diff --git a/core/modules/comment/config/views.view.comments_recent.yml b/core/modules/comment/config/views.view.comments_recent.yml index 576649f..e2b3aff 100755 --- a/core/modules/comment/config/views.view.comments_recent.yml +++ b/core/modules/comment/config/views.view.comments_recent.yml @@ -26,7 +26,9 @@ display: title: 'Recent comments' use_more: '0' access: - type: none + type: perm + options: + perm: 'access comments' cache: type: none exposed_form: diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php index 901d325..70e6c54 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php @@ -17,7 +17,7 @@ class CommentBlockTest extends CommentTestBase { * * @var array */ - public static $modules = array('block'); + public static $modules = array('block', 'views'); function setUp() { parent::setUp(); @@ -46,12 +46,15 @@ public static function getInfo() { */ function testRecentCommentBlock() { $this->drupalLogin($this->admin_user); - $block = $this->drupalPlaceBlock('recent_comments', array(), array('block_count' => 2)); + $block = $this->drupalPlaceBlock('views_block:comment_recent-block_1'); - // Add some test comments, one without a subject. - $comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName()); - $comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName()); - $comment3 = $this->postComment($this->node, $this->randomName()); + // Add some test comments, with and without subjects. Because the 10 newest + // comments should be shown by the block, we create 11 to test that behavior + // below. + for ($i = 0; $i < 11; ++$i) { + $subject = ($i % 2) ? $this->randomName() : ''; + $comments[$i] = $this->postComment($this->node, $this->randomName(), $subject); + } // Test that a user without the 'access comments' permission cannot see the // block. @@ -62,47 +65,36 @@ function testRecentCommentBlock() { cache_invalidate_tags(array('content' => TRUE)); $this->drupalGet(''); $label = $block->label(); - $this->assertNoText($label, 'Block was not found.'); + $this->assertNoText(t('Recent comments')); user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments')); // Test that a user with the 'access comments' permission can see the // block. $this->drupalLogin($this->web_user); $this->drupalGet(''); - $this->assertText($label, 'Block was found.'); - - // Test the only the 2 latest comments are shown and in the proper order. - $this->assertNoText($comment1->subject->value, 'Comment not found in block.'); - $this->assertText($comment2->subject->value, 'Comment found in block.'); - $this->assertText($comment3->comment_body->value, 'Comment found in block.'); - $this->assertTrue(strpos($this->drupalGetContent(), $comment3->comment_body->value) < strpos($this->drupalGetContent(), $comment2->subject->value), 'Comments were ordered correctly in block.'); - - // Set the number of recent comments to show to 10. - $block->set('settings', array('block_count' => 10)); - $block->save(); - - // Post an additional comment. - $comment4 = $this->postComment($this->node, $this->randomName(), $this->randomName()); - - // Test that all four comments are shown. - $this->assertText($comment1->subject->value, 'Comment found in block.'); - $this->assertText($comment2->subject->value, 'Comment found in block.'); - $this->assertText($comment3->comment_body->value, 'Comment found in block.'); - $this->assertText($comment4->subject->value, 'Comment found in block.'); + $this->assertText(t('Recent comments')); + + // Test the only the 10 latest comments are shown and in the proper order. +debug($comments[0]->subject->value); + $this->assertNoText($comments[0]->subject->value, 'Comment 11 not found in block.'); + for ($i = 1; $i < 11; $i++) { + $this->assertText($comments[$i]->subject->value, format_string('Comment @number found in block.', array('@number' => 11 - $i))); + if ($i > 1) { + $previous_position = $position; + $position = strpos($this->drupalGetContent(), $comments[$i]->subject->value); + $this->assertTrue($position < $previous_position, format_string('Comment @a appears before comment @b', array('@a' => 11 - $i, '@b' => 12 - $i))); + } + $position = strpos($this->drupalGetContent(), $comments[$i]->subject->value); + } // Test that links to comments work when comments are across pages. $this->setCommentsPerPage(1); - $this->drupalGet(''); - $this->clickLink($comment1->subject->value); - $this->assertText($comment1->subject->value, 'Comment link goes to correct page.'); - $this->drupalGet(''); - $this->clickLink($comment2->subject->value); - $this->assertText($comment2->subject->value, 'Comment link goes to correct page.'); - $this->clickLink($comment4->subject->value); - $this->assertText($comment4->subject->value, 'Comment link goes to correct page.'); - // Check that when viewing a comment page from a link to the comment, that - // rel="canonical" is added to the head of the document. - $this->assertRaw('clickLink($comments[$i]->subject->value); + $this->assertText($comments[$i]->subject->value, 'Comment link goes to correct page.'); + $this->assertRaw('