function TrackerTest::testTrackerCronIndexing

Same name and namespace in other branches
  1. 7.x modules/tracker/tracker.test \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

core/modules/tracker/tests/src/Functional/TrackerTest.php, line 371

Class

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

Namespace

Drupal\Tests\tracker\Functional

Code

public function testTrackerCronIndexing() {
    $this->drupalLogin($this->user);
    // Create 3 nodes.
    $edits = [];
    $nodes = [];
    for ($i = 1; $i <= 3; $i++) {
        $edits[$i] = [
            'title' => $this->randomMachineName(),
        ];
        $nodes[$i] = $this->drupalCreateNode($edits[$i]);
    }
    // Add a comment to the last node as other user.
    $this->drupalLogin($this->otherUser);
    $comment = [
        'subject[0][value]' => $this->randomMachineName(),
        'comment_body[0][value]' => $this->randomMachineName(20),
    ];
    $this->drupalGet('comment/reply/node/' . $nodes[3]->id() . '/comment');
    $this->submitForm($comment, 'Save');
    // Create an unpublished node.
    $unpublished = $this->drupalCreateNode([
        'title' => $this->randomMachineName(8),
        'status' => 0,
    ]);
    $this->drupalGet('activity');
    $this->assertSession()
        ->responseNotContains($unpublished->label());
    // Start indexing backwards from node 4.
    \Drupal::state()->set('tracker.index_nid', 4);
    // Clear the current tracker tables and rebuild them.
    $connection = Database::getConnection();
    $connection->delete('tracker_node')
        ->execute();
    $connection->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->assertSession()
            ->pageTextContains($node->label());
    }
    // Fetch the site-wide tracker.
    $this->drupalGet('activity');
    // Assert that all node titles are displayed.
    foreach ($nodes as $i => $node) {
        $this->assertSession()
            ->pageTextContains($node->label());
    }
}

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