You are here

function TrackerTest::testTrackerHistoryMetadata in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/tracker/src/Tests/TrackerTest.php \Drupal\tracker\Tests\TrackerTest::testTrackerHistoryMetadata()

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

File

core/modules/tracker/src/Tests/TrackerTest.php, line 231
Contains \Drupal\tracker\Tests\TrackerTest.

Class

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

Namespace

Drupal\tracker\Tests

Code

function testTrackerHistoryMetadata() {
  $this
    ->drupalLogin($this->user);

  // Create a page node.
  $edit = array(
    '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 = array(
    '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);
}