function TrackerTest::testTrackerAll

Same name in other branches
  1. 7.x modules/tracker/tracker.test \TrackerTest::testTrackerAll()
  2. 9 core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerAll()
  3. 8.9.x core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerAll()
  4. 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 84

Class

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

Namespace

Drupal\Tests\tracker\Functional

Code

public function testTrackerAll() : void {
    $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());
    $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.