You are here

public function XMLSitemapUnitTest::testGetChunkCount in XML sitemap 7.2

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

Tests for xmlsitemap_get_chunk_count().

File

./xmlsitemap.test, line 501
Unit tests for the xmlsitemap.

Class

XMLSitemapUnitTest
XML Sitemap UnitTest.

Code

public 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_query("SELECT COUNT(id) FROM {xmlsitemap}")
    ->fetchField();
  for ($i = $count; $i < 4; $i++) {
    $this
      ->addSitemapLink();
    $this
      ->assertEqual(xmlsitemap_get_chunk_count(TRUE), 1);
  }
  $this
    ->assertEqual(db_query("SELECT COUNT(id) FROM {xmlsitemap}")
    ->fetchField(), 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_delete('xmlsitemap')
    ->execute();
  $this
    ->assertEqual(db_query("SELECT COUNT(id) FROM {xmlsitemap}")
    ->fetchField(), 0);
  $this
    ->assertEqual(xmlsitemap_get_chunk_count(TRUE), 1);
}