function TrackerTest::testTrackerNewComments

Tests for comment counters on the tracker listing.

File

drupal/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php, line 162
Definition of Drupal\tracker\Tests\TrackerTest.

Class

TrackerTest
Defines a base class for testing tracker.module.

Namespace

Drupal\tracker\Tests

Code

function testTrackerNewComments() {
  $this
    ->drupalLogin($this->user);
  $node = $this
    ->drupalCreateNode(array(
    'comment' => 2,
    'title' => array(
      LANGUAGE_NOT_SPECIFIED => array(
        array(
          'value' => $this
            ->randomName(8),
        ),
      ),
    ),
  ));

  // Add a comment to the page.
  $comment = array(
    'subject' => $this
      ->randomName(),
    'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this
      ->randomName(20),
  );

  // The new comment is automatically viewed by the current user.
  $this
    ->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));
  $this
    ->drupalLogin($this->other_user);
  $this
    ->drupalGet('tracker');
  $this
    ->assertText('1 new', 'New comments are counted on the tracker listing pages.');
  $this
    ->drupalGet('node/' . $node->nid);

  // Add another comment as other_user.
  $comment = array(
    'subject' => $this
      ->randomName(),
    'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this
      ->randomName(20),
  );

  // 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);
  $this
    ->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet('tracker');
  $this
    ->assertText('1 new', 'New comments are counted on the tracker listing pages.');
}