function TrackerTest::testTrackerCronIndexing

Same name in other branches
  1. 9 core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerCronIndexing()
  2. 8.9.x core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerCronIndexing()
  3. 10 core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerCronIndexing()
  4. 11.x core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerCronIndexing()

Tests that existing nodes are indexed by cron.

File

modules/tracker/tracker.test, line 253

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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.