function TrackerTest::testTrackerHistoryMetadata

Same name in other branches
  1. 9 core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerHistoryMetadata()
  2. 8.9.x core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerHistoryMetadata()
  3. 10 core/modules/tracker/tests/src/Functional/TrackerTest.php \Drupal\Tests\tracker\Functional\TrackerTest::testTrackerHistoryMetadata()

Tests the metadata for the "new"/"updated" indicators.

File

core/modules/tracker/tests/src/Functional/TrackerTest.php, line 240

Class

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

Namespace

Drupal\Tests\tracker\Functional

Code

public function testTrackerHistoryMetadata() {
    $this->drupalLogin($this->user);
    // Create a page node.
    $edit = [
        'title' => $this->randomMachineName(8),
    ];
    $node = $this->drupalCreateNode($edit);
    // Verify that the history metadata is present.
    $this->drupalGet('activity');
    $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->getChangedTime());
    $this->drupalGet('activity/' . $this->user
        ->id());
    $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->getChangedTime());
    $this->drupalGet('user/' . $this->user
        ->id() . '/activity');
    $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->getChangedTime());
    // Add a comment to the page, make sure it is created after the node by
    // sleeping for one second, to ensure the last comment timestamp is
    // different from before.
    $comment = [
        'subject[0][value]' => $this->randomMachineName(),
        'comment_body[0][value]' => $this->randomMachineName(20),
    ];
    sleep(1);
    $this->drupalGet('comment/reply/node/' . $node->id() . '/comment');
    $this->submitForm($comment, 'Save');
    // Reload the node so that comment.module's hook_node_load()
    // implementation can set $node->last_comment_timestamp for the freshly
    // posted comment.
    $node = Node::load($node->id());
    // Verify that the history metadata is updated.
    $this->drupalGet('activity');
    $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), (int) $node->get('comment')->last_comment_timestamp);
    $this->drupalGet('activity/' . $this->user
        ->id());
    $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), (int) $node->get('comment')->last_comment_timestamp);
    $this->drupalGet('user/' . $this->user
        ->id() . '/activity');
    $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), (int) $node->get('comment')->last_comment_timestamp);
    // Log out, now verify that the metadata is still there, but the library is
    // not.
    $this->drupalLogout();
    $this->drupalGet('activity');
    $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), (int) $node->get('comment')->last_comment_timestamp, FALSE);
    $this->drupalGet('user/' . $this->user
        ->id() . '/activity');
    $this->assertHistoryMetadata($node->id(), $node->getChangedTime(), (int) $node->get('comment')->last_comment_timestamp, FALSE);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.