Commit 31d06a60 authored by gbyte.co's avatar gbyte.co

Add tests

parent b2aee04b
......@@ -63,7 +63,7 @@ class Batch {
case 'form':
// Start batch process.
batch_set($this->batch);
break;
return TRUE;
case 'drush':
// Start drush batch process.
......@@ -75,7 +75,7 @@ class Batch {
drush_log($this->t(self::BATCH_INIT_MESSAGE), 'status');
drush_backend_batch_process();
break;
return TRUE;
case 'backend':
// Start backend batch process.
......@@ -87,7 +87,7 @@ class Batch {
// todo: Does not take advantage of batch API and eventually runs out of memory on very large sites. Use queue API instead?
batch_process();
break;
return TRUE;
case 'nobatch':
// Call each batch operation the way the Drupal batch API would do, but
......@@ -99,8 +99,9 @@ class Batch {
call_user_func_array($operation[0], $operation[1]);
}
$this->finishGeneration(TRUE, !empty($context['results']) ? $context['results'] : [], []);
break;
return TRUE;
}
return FALSE;
}
/**
......
......@@ -236,6 +236,8 @@ class Simplesitemap {
* @param string $from
* Can be 'form', 'backend', 'drush' or 'nobatch'.
* This decides how the batch process is to be run.
*
* @return bool|\Drupal\simple_sitemap\Simplesitemap
*/
public function generateSitemap($from = 'form') {
......@@ -266,7 +268,8 @@ class Simplesitemap {
}
}
$this->batch->start();
$success = $this->batch->start();
return $from === 'nobatch' ? $this : $success;
}
/**
......
......@@ -230,6 +230,57 @@ class SimplesitemapTest extends SimplesitemapTestBase {
$this->assertNoText('node/' . $this->node->id());
}
public function testBatchProcessLimitSetting() {
// Create some nodes.
for ($i = 3; $i <=50; $i++) {
$this->createNode(['title' => "Node{$i}", 'type' => 'page']);
}
// Test batch_process_limit setting.
$sitemap = $this->generator->setBundleSettings('node', 'page')
->generateSitemap('nobatch')
->getSitemap();
$sitemap2 = $this->generator->saveSetting('batch_process_limit', 1)
->generateSitemap('nobatch')
->getSitemap();
$sitemap3 = $this->generator->saveSetting('batch_process_limit', 10)
->generateSitemap('nobatch')
->getSitemap();
$this->assertEqual($sitemap, $sitemap2);
$this->assertEqual($sitemap, $sitemap3);
// Test batch_process_limit setting in combination with max_links setting.
$sitemap_index = $this->generator->setBundleSettings('node', 'page')
->saveSetting('batch_process_limit', 1500)
->saveSetting('max_links', 30)
->generateSitemap('nobatch')
->getSitemap();
$sitemap_chunk = $this->generator->getSitemap(1);
$sitemap_index2 = $this->generator->saveSetting('batch_process_limit', 1)
->generateSitemap('nobatch')
->getSitemap();
$sitemap_chunk2 = $this->generator->getSitemap(1);
$sitemap_index3 = $this->generator->saveSetting('batch_process_limit', 10)
->generateSitemap('nobatch')
->getSitemap();
$sitemap_chunk3 = $this->generator->getSitemap(1);
$this->assertIdentical($sitemap_index, $sitemap_index2);
$this->assertIdentical($sitemap_chunk, $sitemap_chunk2);
$this->assertIdentical($sitemap_index, $sitemap_index3);
$this->assertIdentical($sitemap_chunk, $sitemap_chunk3);
}
/**
* Test setting the base URL.
*/
......@@ -249,6 +300,9 @@ class SimplesitemapTest extends SimplesitemapTestBase {
$this->assertText('http://base_url_test/sitemaps/1/sitemap.xml');
}
/**
* @todo testSkipUntranslatedSetting
*/
/**
* @todo testSkipNonExistentTranslations
......
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