You are here

function XMLSitemapUnitTest::testGetChunkCount in XML sitemap 6.2

Same name and namespace in other branches
  1. 7.2 xmlsitemap.test \XMLSitemapUnitTest::testGetChunkCount()

Tests for xmlsitemap_get_chunk_count().

File

./xmlsitemap.test, line 407
Unit tests for the xmlsitemap module.

Class

XMLSitemapUnitTest

Code

function testGetChunkCount() {

  // Set a low chunk size for testing.
  variable_set('xmlsitemap_chunk_size', 4);

  // Make the total number of links just equal to the chunk size.
  $count = db_result(db_query("SELECT COUNT(id) FROM {xmlsitemap}"));
  for ($i = $count; $i < 4; $i++) {
    $this
      ->addSitemapLink();
    $this
      ->assertEqual(xmlsitemap_get_chunk_count(TRUE), 1);
  }
  $this
    ->assertEqual(db_result(db_query("SELECT COUNT(id) FROM {xmlsitemap}")), 4);

  // Add a disabled link, should not change the chunk count.
  $this
    ->addSitemapLink(array(
    'status' => FALSE,
  ));
  $this
    ->assertEqual(xmlsitemap_get_chunk_count(TRUE), 1);

  // Add a visible link, should finally bump up the chunk count.
  $this
    ->addSitemapLink();
  $this
    ->assertEqual(xmlsitemap_get_chunk_count(TRUE), 2);

  // Change all links to disabled. The chunk count should be 1 not 0.
  db_query("UPDATE {xmlsitemap} SET status = 0");
  $this
    ->assertEqual(xmlsitemap_get_chunk_count(TRUE), 1);
  $this
    ->assertEqual(xmlsitemap_get_link_count(), 0);

  // Delete all links. The chunk count should be 1 not 0.
  db_query("DELETE FROM {xmlsitemap}");
  $this
    ->assertEqual(db_result(db_query("SELECT COUNT(id) FROM {xmlsitemap}")), 0);
  $this
    ->assertEqual(xmlsitemap_get_chunk_count(TRUE), 1);
}