public function TrackerTest::testTrackerCronIndexing in Drupal 8
Same name and namespace in other branches
- 9 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 364
Class
- TrackerTest
- Create and delete nodes and check for their display in the tracker listings.
Namespace
Drupal\Tests\tracker\FunctionalCode
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
->drupalPostForm('comment/reply/node/' . $nodes[3]
->id() . '/comment', $comment, t('Save'));
// Create an unpublished node.
$unpublished = $this
->drupalCreateNode([
'title' => $this
->randomMachineName(8),
'status' => 0,
]);
// 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
->assertText($node
->label(), new FormattableMarkup('Node @i is displayed on the tracker listing pages.', [
'@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(), new FormattableMarkup('Node @i is displayed on the tracker listing pages.', [
'@i' => $i,
]));
}
}