3 namespace Drupal\Tests\comment\Functional;
5 use Drupal\comment\CommentInterface;
6 use Drupal\comment\Tests\CommentTestTrait;
7 use Drupal\node\Entity\Node;
8 use Drupal\Tests\BrowserTestBase;
9 use Drupal\comment\Entity\Comment;
12 * Tests visibility of comments on book pages.
16 class CommentBookTest extends BrowserTestBase {
25 public static $modules = ['book', 'comment'];
27 protected function setUp() {
30 // Create comment field on book.
31 $this->addDefaultCommentField('node', 'book');
35 * Tests comments in book export.
37 public function testBookCommentPrint() {
38 $book_node = Node::create([
40 'title' => 'Book title',
41 'body' => 'Book body',
43 $book_node->book['bid'] = 'new';
46 $comment_subject = $this->randomMachineName(8);
47 $comment_body = $this->randomMachineName(8);
48 $comment = Comment::create([
49 'subject' => $comment_subject,
50 'comment_body' => $comment_body,
51 'entity_id' => $book_node->id(),
52 'entity_type' => 'node',
53 'field_name' => 'comment',
54 'status' => CommentInterface::PUBLISHED,
58 $commenting_user = $this->drupalCreateUser(['access printer-friendly version', 'access comments', 'post comments']);
59 $this->drupalLogin($commenting_user);
61 $this->drupalGet('node/' . $book_node->id());
63 $this->assertText($comment_subject, 'Comment subject found');
64 $this->assertText($comment_body, 'Comment body found');
65 $this->assertText(t('Add new comment'), 'Comment form found');
66 $this->assertField('subject[0][value]', 'Comment form subject found');
68 $this->drupalGet('book/export/html/' . $book_node->id());
70 $this->assertText(t('Comments'), 'Comment thread found');
71 $this->assertText($comment_subject, 'Comment subject found');
72 $this->assertText($comment_body, 'Comment body found');
74 $this->assertNoText(t('Add new comment'), 'Comment form not found');
75 $this->assertNoField('subject[0][value]', 'Comment form subject not found');