Commit 85ed5663 authored by gbyte.co's avatar gbyte.co

Add test testGenerationResume()

parent d7c04e66
......@@ -314,14 +314,6 @@ class SimplesitemapTest extends SimplesitemapTestBase {
$this->assertSession()->responseContains('http://base_url_test/sitemap.xml?page=1');
}
/**
* @todo testSkipUntranslatedSetting
*/
/**
* @todo testSkipNonExistentTranslations
*/
/**
* Test overriding of bundle settings for a single entity.
*
......@@ -463,6 +455,10 @@ class SimplesitemapTest extends SimplesitemapTestBase {
$this->assertTrue($this->generator->entityTypeIsEnabled('node'));
}
/**
* @todo testSitemapLanguages
*/
/**
* Test adding and removing sitemap variants.
*
......@@ -500,4 +496,63 @@ class SimplesitemapTest extends SimplesitemapTestBase {
/**
* @todo Test removeSitemap().
*/
/**
* Test cases for ::testGenerationResume.
*/
public function generationResumeProvider() {
return [
[1000, 500, 1],
[1000, 500, 3, ['de']],
[1000, 500, 5, ['de', 'es']],
[10, 10000, 10],
];
}
/**
* @throws \Drupal\Component\Plugin\Exception\PluginException
*
* @dataProvider generationResumeProvider
*/
public function testGenerationResume($element_count, $generate_duration, $max_links, $langcodes = []) {
$this->addLanguages($langcodes);
$expected_sitemap_count = (int) ceil(($element_count * (count($langcodes) + 1)) / $max_links);
$this->drupalCreateContentType(['type' => 'blog']);
for ($i = 1; $i <= $element_count; $i++) {
$this->createNode(['title' => 'node-' . $i, 'type' => 'blog']);
}
$this->generator
->removeCustomLinks()
->saveSetting('generate_duration', $generate_duration)
->saveSetting('max_links', $max_links)
->saveSetting('skip_untranslated', FALSE)
->setBundleSettings('node', 'blog');
$queue = $this->generator->getQueueWorker()->rebuildQueue();
$generate_count = 0;
while ($queue->generationInProgress()) {
$generate_count++;
$this->generator->generateSitemap('backend');
}
// Test if sitemap generation has been resumed when time limit is very low.
$this->assertTrue($generate_duration > $element_count || $generate_count > 1, 'This assertion tests if the sitemap generation is split up into batches due to a low generation time limit setting. The failing of this assertion can mean that the sitemap was wrongfully generated in one go, but it can also mean that the assumed low time setting is still high enough for a one pass generation.');
// Test if correct number of sitemaps have been created.
$chunks = $this->database->query('SELECT id FROM {simple_sitemap} WHERE delta != 0 AND status = 1');
$chunks->allowRowCount = TRUE;
$chunk_count = $chunks->rowCount();
$this->assertTrue($chunk_count === $expected_sitemap_count);
// Test if index has been created when necessary.
$index = $this->database->query('SELECT id FROM {simple_sitemap} WHERE delta = 0 AND status = 1')
->fetchField();
$this->assertTrue($chunk_count > 1 ? (FALSE !== $index) : !$index);
}
}
......@@ -4,6 +4,7 @@ namespace Drupal\Tests\simple_sitemap\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
/**
* Provides the base class for web tests for Simple sitemap.
......@@ -112,4 +113,11 @@ abstract class SimplesitemapTestBase extends BrowserTestBase {
$this->assertGreaterThan(1, $nr_found);
}
protected function addLanguages($langcodes = 'de') {
foreach ((array) $langcodes as $langcode) {
ConfigurableLanguage::createFromLangcode($langcode)
->save();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment