function TrackerTest::testTrackerAll
Same name in other branches
- 7.x modules/tracker/tracker.test \TrackerTest::testTrackerAll()
- 8.9.x core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerAll()
- 10 core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerAll()
- 11.x core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerAll()
Tests for the presence of nodes on the global tracker listing.
File
-
core/
modules/ tracker/ tests/ src/ Functional/ TrackerTest.php, line 81
Class
- TrackerTest
- Create and delete nodes and check for their display in the tracker listings.
Namespace
Drupal\Tests\tracker\FunctionalCode
public function testTrackerAll() {
$this->drupalLogin($this->user);
$unpublished = $this->drupalCreateNode([
'title' => $this->randomMachineName(8),
'status' => 0,
]);
$published = $this->drupalCreateNode([
'title' => $this->randomMachineName(8),
'status' => 1,
]);
$this->drupalGet('activity');
$this->assertSession()
->pageTextNotContains($unpublished->label());
$this->assertSession()
->pageTextContains($published->label());
$this->assertSession()
->linkExists('My recent content', 0, 'User tab shows up on the global tracker page.');
// Assert cache contexts, specifically the pager and node access contexts.
$this->assertCacheContexts([
'languages:language_interface',
'route',
'theme',
'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT,
'url.query_args.pagers:0',
'user.node_grants:view',
'user',
]);
// Assert cache tags for the action/tabs blocks, visible node, and node list
// cache tag.
$expected_tags = Cache::mergeTags($published->getCacheTags(), $published->getOwner()
->getCacheTags());
// Because the 'user.permissions' cache context is being optimized away.
$role_tags = [];
foreach ($this->user
->getRoles() as $rid) {
$role_tags[] = "config:user.role.{$rid}";
}
$expected_tags = Cache::mergeTags($expected_tags, $role_tags);
$block_tags = [
'block_view',
'local_task',
'config:block.block.page_actions_block',
'config:block.block.page_tabs_block',
'config:block_list',
];
$expected_tags = Cache::mergeTags($expected_tags, $block_tags);
$additional_tags = [
'node_list',
'rendered',
];
$expected_tags = Cache::mergeTags($expected_tags, $additional_tags);
$this->assertCacheTags($expected_tags);
// Delete a node and ensure it no longer appears on the tracker.
$published->delete();
$this->drupalGet('activity');
$this->assertSession()
->pageTextNotContains($published->label());
// Test proper display of time on activity page when comments are disabled.
// Disable comments.
FieldStorageConfig::loadByName('node', 'comment')->delete();
$node = $this->drupalCreateNode([
// This title is required to trigger the custom changed time set in the
// node_test module. This is needed in order to ensure a sufficiently
// large 'time ago' interval that isn't numbered in seconds.
'title' => 'testing_node_presave',
'status' => 1,
]);
$this->drupalGet('activity');
$this->assertSession()
->pageTextContains($node->label());
$this->assertSession()
->pageTextContains(\Drupal::service('date.formatter')->formatTimeDiffSince($node->getChangedTime()));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.