Index: modules/comment/comment.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v
retrieving revision 1.92
diff -u -p -r1.92 comment.test
--- modules/comment/comment.test	8 Nov 2010 21:36:45 -0000	1.92
+++ modules/comment/comment.test	27 Nov 2010 20:36:22 -0000
@@ -261,7 +261,7 @@ class CommentInterfaceTest extends Comme
   /**
    * Test comment interface.
    */
-  function testCommentInterface() {
+  function xtestCommentInterface() {
     $langcode = LANGUAGE_NONE;
     // Set comments to have subject and preview disabled.
     $this->drupalLogin($this->admin_user);
@@ -394,7 +394,7 @@ class CommentInterfaceTest extends Comme
   /**
    * Tests the node comment statistics.
    */
-  function testCommentNodeCommentStatistics() {
+  function xtestCommentNodeCommentStatistics() {
     $langcode = LANGUAGE_NONE;
     // Set comments to have subject and preview disabled.
     $this->drupalLogin($this->admin_user);
@@ -473,6 +473,178 @@ class CommentInterfaceTest extends Comme
     $this->assertEqual($node->last_comment_uid, 0, t('The value of node last_comment_uid is zero.'));
     $this->assertEqual($node->comment_count, 2, t('The value of node comment_count is 2.'));
   }
+
+  /**
+   * Tests comment links.
+   */
+  function testCommentLinks() {
+    // Bartik theme alters comment links, so use a different.
+    theme_enable(array('garland'));
+    variable_set('theme_default', 'garland');
+
+    // Remove additional user permissions from $this->web_user added by setUp(),
+    // since this test is limited to anonymous and authenticated roles only.
+    // @todo Standard installation profile grants authenticated users
+    //   permissions to view and post comments by default, which should have an
+    //   impact on "log in or register to post" links for anonymous users.
+    user_role_delete(key($this->web_user->roles));
+
+    $tasks = array(
+      'access comments' => array(0, 1, 0, 0, 1, 0, 1),
+      'post comments'   => array(0, 0, 1, 0, 1, 1, 1),
+      'form'            => array(0, 0, 0, 1, 0, 1, 1),
+      // @todo 
+     #$this->comment_count
+      // @todo 0, 1, 2
+     #'comments'        => array(0, 0, 0, 1, 0, 1, 1),
+    );
+
+    // 0 comments, anonymous user.
+    while (current($tasks['access comments']) !== FALSE) {
+      $info = array();
+      foreach ($tasks as $key => $value) {
+        $info[$key] = current($tasks[$key]);
+        next($tasks[$key]);
+      }
+      $this->assertCommentLinks($info);
+    }
+
+    $this->drupalLogin($this->web_user);
+    foreach ($tasks as $key => $value) {
+      reset($tasks[$key]);
+    }
+
+    // 0 comments, authenticated user.
+    while (current($tasks['access comments']) !== FALSE) {
+      $info = array();
+      foreach ($tasks as $key => $value) {
+        $info[$key] = current($tasks[$key]);
+        next($tasks[$key]);
+      }
+      $this->assertCommentLinks($info);
+    }
+  }
+
+  /**
+   * Re-configures comment settings and user permissions.
+   *
+   * @param $info
+   *   An associative array describing the environment to setup:
+   *   - form: COMMENT_FORM_BELOW or COMMENT_FORM_SEPARATE_PAGE.
+   *   - contact: COMMENT_ANONYMOUS_MAY_CONTACT,
+   *     COMMENT_ANONYMOUS_MAYNOT_CONTACT, or COMMENT_ANONYMOUS_MUST_CONTACT.
+   *   - comments: COMMENT_NODE_OPEN, COMMENT_NODE_CLOSED, or
+   *     COMMENT_NODE_HIDDEN.
+   *   - view comments: TRUE or FALSE. Grants or revokes access for the
+   *     currently logged in user.
+   *   - post comments: TRUE or FALSE. Grants or revokes access for the
+   *     currently logged in user.
+   *   - skip comment approval: TRUE or FALSE. Grants or revokes access for the
+   *     currently logged in user.
+   *   - edit own comments: TRUE or FALSE. Grants or revokes access for the
+   *     currently logged in user.
+   */
+  function setEnvironment(array $info) {
+    static $current;
+
+    // Apply defaults to initial environment.
+    if (!isset($current)) {
+      $current = array(
+        'access comments' => 0,
+        'post comments' => 0,
+        'form' => COMMENT_FORM_BELOW,
+        'contact' => COMMENT_ANONYMOUS_MAY_CONTACT,
+        'comments' => COMMENT_NODE_OPEN,
+        'skip comment approval' => 0,
+        'edit own comments' => 0,
+      );
+    }
+    // Complete new environment with current environment.
+    $info = array_merge($current, $info);
+
+    // Change the environment.
+    variable_set('comment_form_location_' . $this->node->type, $info['form']);
+    variable_set('comment_anonymous_' . $this->node->type, $info['contact']);
+    if ($this->node->comment != $info['comments']) {
+      $this->node->comment = $info['comments'];
+      node_save($this->node);
+    }
+    $rid = ($this->loggedInUser ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID);
+    $perms = array_intersect_key($info, array('access comments' => 1, 'post comments' => 1, 'skip comment approval' => 1, 'edit own comments' => 1));
+    user_role_change_permissions($rid, $perms);
+
+    // Output verbose debugging information.
+    // @see DrupalTestCase::error()
+    $t_form = array(
+      COMMENT_FORM_BELOW => 'below',
+      COMMENT_FORM_SEPARATE_PAGE => 'separate page',
+    );
+    $t_contact = array(
+      COMMENT_ANONYMOUS_MAY_CONTACT => 'optional',
+      COMMENT_ANONYMOUS_MAYNOT_CONTACT => 'disabled',
+      COMMENT_ANONYMOUS_MUST_CONTACT => 'required',
+    );
+    $t_comments = array(
+      COMMENT_NODE_OPEN => 'open',
+      COMMENT_NODE_CLOSED => 'closed',
+      COMMENT_NODE_HIDDEN => 'hidden',
+    );
+    $verbose = $info;
+    $verbose['form'] = $t_form[$info['form']];
+    $verbose['contact'] = $t_contact[$info['contact']];
+    $verbose['comments'] = $t_comments[$info['comments']];
+    $message = t('Changed environment for role @rid:<pre>@verbose</pre>', array(
+      '@rid' => $rid,
+      '@verbose' => var_export($verbose, TRUE),
+    ));
+    $this->assert('debug', $message, 'Debug');
+
+    // Update current environment.
+    $current = $info;
+
+    return $info;
+  }
+
+  /**
+   * Asserts that comment links appear according to the passed environment setup.
+   *
+   * @param $info
+   *   An associative array describing the environment to pass to
+   *   setEnvironment().
+   */
+  function assertCommentLinks(array $info) {
+    $info = $this->setEnvironment($info);
+
+    $nid = $this->node->nid;
+
+    foreach (array('', "node/$nid") as $path) {
+      $this->drupalGet($path);
+
+      // Posting comments is not allowed.
+      if (!$info['post comments']) {
+        $this->assertNoLink('Add new comment');
+        // Anonymous users should see a note to log in or register in case
+        // authenticated users are allowed to post comments.
+        if (!$this->loggedInUser) {
+          if (user_access('post comments', $this->web_user)) {
+            $this->assertText('Log in or register to post comments');
+          }
+          else {
+            $this->assertNoText('Log in or register to post comments');
+          }
+        }
+      }
+      // Posting comments is allowed.
+      else {
+        $this->assertLink('Add new comment');
+        $this->assertNoText('Log in or register to post comments');
+        if ($path == "node/$nid" && $info['form'] == COMMENT_FORM_BELOW) {
+          $elements = $this->xpath('//form[@id=:id]', array(':id' => 'comment-form'));
+          $this->assertTrue(count($elements), t('Comment form found.'));
+        }
+      }
+    }
+  }
 }
 
 /**
