<?php
namespace Drupal\comment\Tests;
class CommentBlockTest extends CommentTestBase {
public static $modules = array(
'block',
);
function setUp() {
parent::setUp();
$this->admin_user = $this
->drupalCreateUser(array(
'administer content types',
'administer comments',
'skip comment approval',
'post comments',
'access comments',
'access content',
'administer blocks',
));
}
public static function getInfo() {
return array(
'name' => 'Comment blocks',
'description' => 'Test comment block functionality.',
'group' => 'Comment',
);
}
function testRecentCommentBlock() {
$this
->drupalLogin($this->admin_user);
$block = $this
->drupalPlaceBlock('recent_comments', array(
'block_count' => 2,
));
$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());
$this
->drupalLogout();
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments',
));
cache_invalidate_tags(array(
'content' => TRUE,
));
$this
->drupalGet('');
$label = $block
->label();
$this
->assertNoText($label, 'Block was not found.');
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments',
));
$this
->drupalLogin($this->web_user);
$this
->drupalGet('');
$this
->assertText($label, 'Block was found.');
$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.');
$block
->getPlugin()
->setConfig('block_count', 10);
$block
->save();
$comment4 = $this
->postComment($this->node, $this
->randomName(), $this
->randomName());
$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
->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.');
$this
->assertRaw('<link rel="canonical"', 'Canonical URL was found in the HTML head');
}
}