function TrackerTest::testTrackerAll in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/tracker/src/Tests/TrackerTest.php \Drupal\tracker\Tests\TrackerTest::testTrackerAll()
Tests for the presence of nodes on the global tracker listing.
File
- core/
modules/ tracker/ src/ Tests/ TrackerTest.php, line 71 - Contains \Drupal\tracker\Tests\TrackerTest.
Class
- TrackerTest
- Create and delete nodes and check for their display in the tracker listings.
Namespace
Drupal\tracker\TestsCode
function testTrackerAll() {
$this
->drupalLogin($this->user);
$unpublished = $this
->drupalCreateNode(array(
'title' => $this
->randomMachineName(8),
'status' => 0,
));
$published = $this
->drupalCreateNode(array(
'title' => $this
->randomMachineName(8),
'status' => 1,
));
$this
->drupalGet('activity');
$this
->assertNoText($unpublished
->label(), 'Unpublished node does not show up in the tracker listing.');
$this
->assertText($published
->label(), 'Published node shows up in the tracker listing.');
$this
->assertLink(t('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',
'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
->assertNoText($published
->label(), 'Deleted node does not show up in the tracker listing.');
// 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
->assertText($node
->label(), 'Published node shows up in the tracker listing.');
$this
->assertText(\Drupal::service('date.formatter')
->formatTimeDiffSince($node
->getChangedTime()), 'The changed time was displayed on the tracker listing.');
}