public function SimplesitemapTest::testGenerationResume in Simple XML sitemap 4.x
Same name and namespace in other branches
- 8.3 tests/src/Functional/SimplesitemapTest.php \Drupal\Tests\simple_sitemap\Functional\SimplesitemapTest::testGenerationResume()
@dataProvider generationResumeProvider
Throws
\Drupal\Component\Plugin\Exception\PluginException
File
- tests/
src/ Functional/ SimplesitemapTest.php, line 619
Class
- SimplesitemapTest
- Tests Simple XML Sitemap functional integration.
Namespace
Drupal\Tests\simple_sitemap\FunctionalCode
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
->entityManager()
->setBundleSettings('node', 'blog');
$this->generator
->customLinkManager()
->remove();
$this->generator
->saveSetting('generate_duration', $generate_duration)
->saveSetting('max_links', $max_links)
->saveSetting('skip_untranslated', FALSE);
$this->generator
->rebuildQueue();
$generate_count = 0;
while (\Drupal::service('simple_sitemap.queue_worker')
->generationInProgress()) {
$generate_count++;
$this->generator
->generateSitemap(QueueWorker::GENERATE_TYPE_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
->assertSame($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);
}