public function TrackerTest::testTrackerCronIndexing in Drupal 10
Same name and namespace in other branches
- 8 core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerCronIndexing()
- 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 368
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
->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());
}
}