You are here

public function TrackerTest::testTrackerHistoryMetadata in Drupal 8

Same name and namespace in other branches
  1. 9 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 245

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
    ->drupalPostForm('comment/reply/node/' . $node
    ->id() . '/comment', $comment, t('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(), $node
    ->get('comment')->last_comment_timestamp);
  $this
    ->drupalGet('activity/' . $this->user
    ->id());
  $this
    ->assertHistoryMetadata($node
    ->id(), $node
    ->getChangedTime(), $node
    ->get('comment')->last_comment_timestamp);
  $this
    ->drupalGet('user/' . $this->user
    ->id() . '/activity');
  $this
    ->assertHistoryMetadata($node
    ->id(), $node
    ->getChangedTime(), $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(), $node
    ->get('comment')->last_comment_timestamp, FALSE);
  $this
    ->drupalGet('user/' . $this->user
    ->id() . '/activity');
  $this
    ->assertHistoryMetadata($node
    ->id(), $node
    ->getChangedTime(), $node
    ->get('comment')->last_comment_timestamp, FALSE);
}