You are here

function TrackerTest::testTrackerCronIndexing in Drupal 7

Tests that existing nodes are indexed by cron.

File

modules/tracker/tracker.test, line 253
Tests for tracker.module.

Class

TrackerTest
Defines a base class for testing tracker.module.

Code

function testTrackerCronIndexing() {
  $this
    ->drupalLogin($this->user);

  // Create 3 nodes.
  $edits = array();
  $nodes = array();
  for ($i = 1; $i <= 3; $i++) {
    $edits[$i] = array(
      'comment' => 2,
      'title' => $this
        ->randomName(),
    );
    $nodes[$i] = $this
      ->drupalCreateNode($edits[$i]);
  }

  // Add a comment to the last node as other user.
  $this
    ->drupalLogin($this->other_user);
  $comment = array(
    'subject' => $this
      ->randomName(),
    'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this
      ->randomName(20),
  );
  $this
    ->drupalPost('comment/reply/' . $nodes[3]->nid, $comment, t('Save'));

  // Start indexing backwards from node 3.
  variable_set('tracker_index_nid', 3);

  // Clear the current tracker tables and rebuild them.
  db_delete('tracker_node')
    ->execute();
  db_delete('tracker_user')
    ->execute();
  tracker_cron();
  $this
    ->drupalLogin($this->user);

  // Fetch the user's tracker.
  $this
    ->drupalGet('tracker/' . $this->user->uid);

  // Assert that all node titles are displayed.
  foreach ($nodes as $i => $node) {
    $this
      ->assertText($node->title, format_string('Node @i is displayed on the tracker listing pages.', array(
      '@i' => $i,
    )));
  }
  $this
    ->assertText('1 new', 'New comment is counted on the tracker listing pages.');
  $this
    ->assertText('updated', 'Node is listed as updated');

  // Fetch the site-wide tracker.
  $this
    ->drupalGet('tracker');

  // Assert that all node titles are displayed.
  foreach ($nodes as $i => $node) {
    $this
      ->assertText($node->title, format_string('Node @i is displayed on the tracker listing pages.', array(
      '@i' => $i,
    )));
  }
  $this
    ->assertText('1 new', 'New comment is counted on the tracker listing pages.');
}