function CommentLinksTest::testCommentLinks

Tests comment links.

The output of comment links depends on various environment conditions:

  • Various Comment module configuration settings, user registration settings, and user access permissions.
  • Whether the user is authenticated or not, and whether any comments exist.

To account for all possible cases, this test creates permutations of all possible conditions and tests the expected appearance of comment links in each environment.

File

drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php, line 35
Contains Drupal\comment\Tests\CommentLinksTest.

Class

CommentLinksTest
Tests comment links based on environment configurations.

Namespace

Drupal\comment\Tests

Code

function testCommentLinks() {

  // Bartik theme alters comment links, so use a different theme.
  theme_enable(array(
    'stark',
  ));
  variable_set('theme_default', 'stark');

  // Remove additional user permissions from $this->web_user added by setUp(),
  // since this test is limited to anonymous and authenticated roles only.
  user_role_delete(key($this->web_user->roles));

  // Matrix of possible environmental conditions and configuration settings.
  // See setEnvironment() for details.
  $conditions = array(
    'authenticated' => array(
      FALSE,
      TRUE,
    ),
    'comment count' => array(
      FALSE,
      TRUE,
    ),
    'access comments' => array(
      0,
      1,
    ),
    'post comments' => array(
      0,
      1,
    ),
    'form' => array(
      COMMENT_FORM_BELOW,
      COMMENT_FORM_SEPARATE_PAGE,
    ),
    // USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL is irrelevant for this
    // test; there is only a difference between open and closed registration.
    'user_register' => array(
      USER_REGISTER_VISITORS,
      USER_REGISTER_ADMINISTRATORS_ONLY,
    ),
  );
  $environments = $this
    ->generatePermutations($conditions);
  foreach ($environments as $info) {
    $this
      ->assertCommentLinks($info);
  }
}