You are here

function XMLSitemapNodeFunctionalTest::testCron in XML sitemap 6.2

Same name and namespace in other branches
  1. 7.2 xmlsitemap_node/xmlsitemap_node.test \XMLSitemapNodeFunctionalTest::testCron()

Test the import of old nodes via cron.

File

xmlsitemap_node/xmlsitemap_node.test, line 114
Unit tests for the xmlsitemap_node module.

Class

XMLSitemapNodeFunctionalTest
@file Unit tests for the xmlsitemap_node module.

Code

function testCron() {
  $limit = 5;
  variable_set('xmlsitemap_batch_limit', $limit);
  $nodes = array();
  for ($i = 1; $i <= $limit + 1; $i++) {
    $node = $this
      ->drupalCreateNode();
    array_push($nodes, $node);

    // Need to delay by one second so the nodes don't all have the same
    // timestamp.
    sleep(1);
  }

  // Clear all the node link data so we can emulate 'old' nodes.
  db_query("DELETE FROM {xmlsitemap} WHERE type = 'node'");

  // Run cron to import old nodes.
  xmlsitemap_node_cron();
  for ($i = 1; $i <= $limit + 1; $i++) {
    $node = array_pop($nodes);
    if ($i <= $limit) {

      // The first $limit nodes should be inserted.
      $this
        ->assertSitemapLinkValues('node', $node->nid, array(
        'access' => 1,
        'status' => 1,
        'lastmod' => $node->changed,
      ));
    }
    else {

      // Any beyond $limit should not be in the sitemap.
      $this
        ->assertNoSitemapLink(array(
        'type' => 'node',
        'id' => $node->nid,
      ));
    }
  }
}