function TrackerTest::testTrackerOrderingNewComments in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/tracker/src/Tests/TrackerTest.php \Drupal\tracker\Tests\TrackerTest::testTrackerOrderingNewComments()
Tests for ordering on a users tracker listing when comments are posted.
File
- core/
modules/ tracker/ src/ Tests/ TrackerTest.php, line 282 - 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 testTrackerOrderingNewComments() {
$this
->drupalLogin($this->user);
$node_one = $this
->drupalCreateNode(array(
'title' => $this
->randomMachineName(8),
));
$node_two = $this
->drupalCreateNode(array(
'title' => $this
->randomMachineName(8),
));
// Now get otherUser to track these pieces of content.
$this
->drupalLogin($this->otherUser);
// Add a comment to the first page.
$comment = array(
'subject[0][value]' => $this
->randomMachineName(),
'comment_body[0][value]' => $this
->randomMachineName(20),
);
$this
->drupalPostForm('comment/reply/node/' . $node_one
->id() . '/comment', $comment, t('Save'));
// If the comment is posted in the same second as the last one then Drupal
// can't tell the difference, so we wait one second here.
sleep(1);
// Add a comment to the second page.
$comment = array(
'subject[0][value]' => $this
->randomMachineName(),
'comment_body[0][value]' => $this
->randomMachineName(20),
);
$this
->drupalPostForm('comment/reply/node/' . $node_two
->id() . '/comment', $comment, t('Save'));
// We should at this point have in our tracker for otherUser:
// 1. node_two
// 2. node_one
// Because that's the reverse order of the posted comments.
// Now we're going to post a comment to node_one which should jump it to the
// top of the list.
$this
->drupalLogin($this->user);
// If the comment is posted in the same second as the last one then Drupal
// can't tell the difference, so we wait one second here.
sleep(1);
// Add a comment to the second page.
$comment = array(
'subject[0][value]' => $this
->randomMachineName(),
'comment_body[0][value]' => $this
->randomMachineName(20),
);
$this
->drupalPostForm('comment/reply/node/' . $node_one
->id() . '/comment', $comment, t('Save'));
// Switch back to the otherUser and assert that the order has swapped.
$this
->drupalLogin($this->otherUser);
$this
->drupalGet('user/' . $this->otherUser
->id() . '/activity');
// This is a cheeky way of asserting that the nodes are in the right order
// on the tracker page.
// It's almost certainly too brittle.
$pattern = '/' . preg_quote($node_one
->getTitle()) . '.+' . preg_quote($node_two
->getTitle()) . '/s';
$this
->verbose($pattern);
$this
->assertPattern($pattern, 'Most recently commented on node appears at the top of tracker');
}