Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.920
diff -u -p -r1.920 comment.module
--- modules/comment/comment.module	23 Nov 2010 06:02:06 -0000	1.920
+++ modules/comment/comment.module	27 Nov 2010 14:22:38 -0000
@@ -651,6 +651,19 @@ function comment_node_view($node, $view_
       }
     }
     elseif ($view_mode != 'search_index') {
+      if (user_access('access comments')) {
+        if (!empty($node->comment_count)) {
+          // Display and link to the number of comments that have been posted.
+          $links['comment-comments'] = array(
+            'title' => format_plural($node->comment_count, '1 comment', '@count comments'),
+            'href' => "node/$node->nid",
+            'attributes' => array('title' => t('Jump to the first comment of this posting.')),
+            'fragment' => 'comments',
+            'html' => TRUE,
+          );
+        }
+      }
+
       // Node in other view modes: add a "post comment" link if the user is
       // allowed to post comments and if this node is allowing new comments.
       // But we don't want this link if we're building the node for search
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 14:22:39 -0000
@@ -249,6 +249,236 @@ class CommentHelperCase extends DrupalWe
   }
 }
 
+/**
+ * Check that appropriate links are added to nodes.
+ *
+ * Each node page should provide links for:
+ *
+ * - Add comment                              links['comment-add']
+ * - View comments (including comment-count)  links['comment']
+ *
+ * Each link may be non-existant, in-page or to another page, depending on the
+ * users permissions and the site configuration.  Links to new comments are not
+ * shown, because once the user has visited the node page, the comments are no
+ * longer new.
+ *
+ * Dependencies:
+ *   SETTING            LINK KEY              URL                                    OPTIONS
+ * - Cannot comment     comment_forbidden     -                                      Checks against user_access('post comments').
+ * - Add comment        comment-add           node/$node->nid#comment-form           see COMMENT_FORM_BELOW
+ * - Add comment        comment-add           comment/reply/$node->nid#comment-form  see COMMENT_FORM_SEPARATE_PAGE
+ * - View comments      comment-comments      node/$node->nid#comments               Only if comments are enabled and exist.
+ */
+class CommentLinksTest extends CommentHelperCase {
+
+  public $node = NULL;
+  public $comments = array();
+  public $admin_user = NULL;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Comment links',
+      'description' => 'Test the links added by comment.',
+      'group' => 'Comment',
+    );
+  }
+
+  /**
+   * Each test expects a pre-existing node, and one or more comments.
+   */
+  function setUp() {
+    parent::setUp();
+
+    // Create an admin user.
+    $permissions = module_invoke_all('permission');
+    $this->admin_user = $this->drupalCreateUser(array_keys($permissions));
+    $this->drupalLogin($this->admin_user);
+
+    // Create a node with comments.
+    $node = array(
+      'type' => 'page',
+    );
+    $this->node_with_comments = $this->drupalCreateNode($node);
+
+    // Create a node without comments.
+    $node = array(
+      'type' => 'page',
+    );
+    $this->node_without_comments = $this->drupalCreateNode($node);
+
+    // Add first comment
+    $comment_text = $this->randomName();
+    $comment = $this->postComment($this->node_with_comments, $comment_text);
+
+    // Add second comment
+    $this->comments[] = $comment_text = $this->randomName();
+    $this->comments[] = $comment = $this->postComment($this->node_with_comments, $comment_text);
+
+  }
+
+
+  /**
+   * Check the comment interface under the Stark theme.
+   */
+  function testCommentStark() {
+    // Switch the theme to Stark.
+    theme_enable(array('stark'));
+    variable_set('theme_default', 'stark');
+
+    // Login and fetch the node page.
+    $this->drupalLogin($this->admin_user);
+    $node = $this->node_with_comments;
+    $this->drupalGet("node/{$node->nid}");
+
+    // Look for link to ALL comments at node/1#comments
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comments",
+    ));
+    $this->assertTrue(count($elements), "Link to comments section found using Stark.");
+
+    // Look for link to ADD-COMMENT-FORM at node/1#comment-form when configured
+    // using COMMENT_FORM_BELOW.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comment-form",
+    ));
+    $this->assertTrue(count($elements), "Link to comment-form found using Stark.");
+  }
+
+  /**
+   * Check the comment interface under the Stark theme, when comments are
+   * displayed on a separate page.
+   */
+  function testCommentStarkCOMMENT_FORM_SEPARATE_PAGE() {
+    // Switch the theme to Stark.
+    theme_enable(array('stark'));
+    variable_set('theme_default', 'stark');
+
+    // Switch the comment-location setting to COMMENT_FORM_SEPARATE_PAGE.
+    variable_set('comment_form_location_page', COMMENT_FORM_SEPARATE_PAGE);
+
+    // Login and fetch the node page.
+    $this->drupalLogin($this->admin_user);
+    $node = $this->node_with_comments;
+    $this->drupalGet("node/{$node->nid}");
+
+    // Look for ALL comments at node/1#comments.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comments",
+    ));
+    $this->assertTrue(count($elements), "Link to comments section found using Stark.");
+
+    // There should be no ADD-COMMENT-FORM at node/1#comment-form when using
+    // COMMENT_FORM_SEPARATE_PAGE.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comment-form",
+    ));
+    $this->assertFALSE(count($elements), "Link to on-page comment-form is not present using Stark.");
+
+    // There should be an ADD-COMMENT-FORM at comment/reply/1#comment-form when
+    // using COMMENT_FORM_SEPARATE_PAGE.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "comment/reply/{$node->nid}#comment-form",
+    ));
+    $this->assertTRUE(count($elements), "Link to separate-page comment-form is not present using Stark.");
+  }
+
+
+  /**
+   * Check the comment interface under the Bartik theme.
+   */
+  function testCommentBartik() {
+    // No need to switch theme: the default is Bartik.
+
+    // Login and fetch the node page.
+    $this->drupalLogin($this->admin_user);
+    $node = $this->node_with_comments;
+    $this->drupalGet("node/{$node->nid}");
+
+    // Look for ALL comments at node/1#comments
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comments",
+    ));
+    $this->assertTrue(count($elements), "Link to comments section found using Bartik.");
+
+    // Look for ADD-COMMENT-FORM at node/1#comment-form for COMMENT_FORM_BELOW.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comment-form",
+    ));
+    $this->assertTrue(count($elements), "Link to comment-form found using Bartik.");
+
+
+    // Fetch the node which has no comments.
+    $node = $this->node_without_comments;
+    $this->drupalGet("node/{$node->nid}");
+
+    // Check that there is no link to the comments section.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comments",
+    ));
+    $this->assertFalse(count($elements), "No link to comments section found when there are no comments using Bartik.");
+
+    // Check that there is no link to the ADD-COMMENT-FORM ().
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comment-form",
+    ));
+    $this->assertFalse(count($elements), "No link to comment-form found when there are no comments using Bartik.");
+  }
+
+  /**
+   * Check the comment interface under the Bartik theme, when comments are
+   * displayed on a separate page.
+   */
+  function testCommentBartikCOMMENT_FORM_SEPARATE_PAGE() {
+    // No need to switch theme: the default is Bartik.
+
+    // Switch the comment-location setting to COMMENT_FORM_SEPARATE_PAGE.
+    variable_set('comment_form_location_page', COMMENT_FORM_SEPARATE_PAGE);
+
+    // Login and fetch the node page.
+    $this->drupalLogin($this->admin_user);
+    $node = $this->node_with_comments;
+    $this->drupalGet("node/{$node->nid}");
+
+    // Look for ALL comments at node/1#comments.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comments",
+    ));
+    $this->assertTrue(count($elements), "Link to comments section found using Bartik.");
+
+    // There should be no ADD-COMMENT-FORM at node/1#comment-form when using
+    // COMMENT_FORM_SEPARATE_PAGE.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comment-form",
+    ));
+    $this->assertFALSE(count($elements), "Link to on-page comment-form is not present using Bartik.");
+
+    // There should be an ADD-COMMENT-FORM at comment/reply/1#comment-form when
+    // using COMMENT_FORM_SEPARATE_PAGE.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "comment/reply/{$node->nid}#comment-form",
+    ));
+    $this->assertTRUE(count($elements), "Link to separate-page comment-form is present using Bartik.");
+
+
+    // Fetch the node which has no comments.
+    $node = $this->node_without_comments;
+    $this->drupalGet("node/{$node->nid}");
+
+    // Check that there is no link to the comments section.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "node/{$node->nid}#comments",
+    ));
+    $this->assertFalse(count($elements), "No link to comments section found when there are no comments using Bartik.");
+
+    // There should be an ADD-COMMENT-FORM at comment/reply/1#comment-form when
+    // using COMMENT_FORM_SEPARATE_PAGE.
+    $elements = $this->xpath('//a[contains(@href, :filename)]', array(
+      ':filename' => "comment/reply/{$node->nid}#comment-form",
+    ));
+    $this->assertTRUE(count($elements), "Link to separate-page comment-form is present using Bartik.");
+  }
+}
+
 class CommentInterfaceTest extends CommentHelperCase {
   public static function getInfo() {
     return array(
Index: themes/bartik/templates/node.tpl.php
===================================================================
RCS file: /cvs/drupal/drupal/themes/bartik/templates/node.tpl.php,v
retrieving revision 1.1
diff -u -p -r1.1 node.tpl.php
--- themes/bartik/templates/node.tpl.php	6 Jul 2010 05:25:51 -0000	1.1
+++ themes/bartik/templates/node.tpl.php	27 Nov 2010 14:22:39 -0000
@@ -107,9 +107,10 @@
   </div>
 
   <?php
-    // Remove the "Add new comment" link on the teaser page or if the comment
-    // form is being displayed on the same page.
-    if ($teaser || !empty($content['comments']['comment_form'])) {
+    // Remove the "Add new comment" link on the teaser page, or where there are
+    // no comments and the comment form displays on the same page (because the
+    // "Add new comment" form is directly below).
+    if ($teaser || (isset($comment_count) && $comment_count == 0 && !empty($content['comments']['comment_form']))) {
       unset($content['links']['comment']['#links']['comment-add']);
     }
     // Only display the wrapper div if there are links.
