You are here

public function XMLSitemapNodeFunctionalTest::testCron in XML sitemap 7.2

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

Test the import of old nodes via cron.

File

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

Class

XMLSitemapNodeFunctionalTest
Node Functional Test.

Code

public 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_delete('xmlsitemap')
    ->condition('type', 'node')
    ->execute();

  // Run cron to import old nodes.
  xmlsitemap_node_cron();
  for ($i = 1; $i <= $limit + 1; $i++) {
    $node = array_shift($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,
      ));
    }
  }
}