You are here

function TrackerTest::testTrackerCronIndexing in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/tracker/src/Tests/TrackerTest.php \Drupal\tracker\Tests\TrackerTest::testTrackerCronIndexing()

Tests that existing nodes are indexed by cron.

File

core/modules/tracker/src/Tests/TrackerTest.php, line 348
Contains \Drupal\tracker\Tests\TrackerTest.

Class

TrackerTest
Create and delete nodes and check for their display in the tracker listings.

Namespace

Drupal\tracker\Tests

Code

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

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

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

  // Start indexing backwards from node 3.
  \Drupal::state()
    ->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('activity/' . $this->user
    ->id());

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

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

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