X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fcomment%2Ftests%2Fsrc%2FFunctional%2FCommentBlockTest.php;fp=web%2Fcore%2Fmodules%2Fcomment%2Ftests%2Fsrc%2FFunctional%2FCommentBlockTest.php;h=db7d1bd82722d8efb8d7d6d19a075110481db9b2;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/comment/tests/src/Functional/CommentBlockTest.php b/web/core/modules/comment/tests/src/Functional/CommentBlockTest.php new file mode 100644 index 000000000..db7d1bd82 --- /dev/null +++ b/web/core/modules/comment/tests/src/Functional/CommentBlockTest.php @@ -0,0 +1,90 @@ +adminUser = $this->drupalCreateUser([ + 'administer content types', + 'administer comments', + 'skip comment approval', + 'post comments', + 'access comments', + 'access content', + 'administer blocks', + ]); + } + + /** + * Tests the recent comments block. + */ + public function testRecentCommentBlock() { + $this->drupalLogin($this->adminUser); + $block = $this->drupalPlaceBlock('views_block:comments_recent-block_1'); + + // 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. + $timestamp = REQUEST_TIME; + for ($i = 0; $i < 11; ++$i) { + $subject = ($i % 2) ? $this->randomMachineName() : ''; + $comments[$i] = $this->postComment($this->node, $this->randomMachineName(), $subject); + $comments[$i]->created->value = $timestamp--; + $comments[$i]->save(); + } + + // Test that a user without the 'access comments' permission cannot see the + // block. + $this->drupalLogout(); + user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']); + $this->drupalGet(''); + $this->assertNoText(t('Recent comments')); + user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']); + + // Test that a user with the 'access comments' permission can see the + // block. + $this->drupalLogin($this->webUser); + $this->drupalGet(''); + $this->assertText(t('Recent comments')); + + // Test the only the 10 latest comments are shown and in the proper order. + $this->assertNoText($comments[10]->getSubject(), 'Comment 11 not found in block.'); + for ($i = 0; $i < 10; $i++) { + $this->assertText($comments[$i]->getSubject(), SafeMarkup::format('Comment @number found in block.', ['@number' => 10 - $i])); + if ($i > 1) { + $previous_position = $position; + $position = strpos($this->getRawContent(), $comments[$i]->getSubject()); + $this->assertTrue($position > $previous_position, SafeMarkup::format('Comment @a appears after comment @b', ['@a' => 10 - $i, '@b' => 11 - $i])); + } + $position = strpos($this->getRawContent(), $comments[$i]->getSubject()); + } + + // Test that links to comments work when comments are across pages. + $this->setCommentsPerPage(1); + + for ($i = 0; $i < 10; $i++) { + $this->clickLink($comments[$i]->getSubject()); + $this->assertText($comments[$i]->getSubject(), 'Comment link goes to correct page.'); + $this->assertRaw('