3 namespace Drupal\comment\Tests;
5 use Drupal\comment\CommentInterface;
6 use Drupal\node\Entity\Node;
7 use Drupal\simpletest\WebTestBase;
8 use Drupal\comment\Entity\Comment;
11 * Tests visibility of comments on book pages.
15 class CommentBookTest extends WebTestBase {
24 public static $modules = ['book', 'comment'];
26 protected function setUp() {
29 // Create comment field on book.
30 $this->addDefaultCommentField('node', 'book');
34 * Tests comments in book export.
36 public function testBookCommentPrint() {
37 $book_node = Node::create([
39 'title' => 'Book title',
40 'body' => 'Book body',
42 $book_node->book['bid'] = 'new';
45 $comment_subject = $this->randomMachineName(8);
46 $comment_body = $this->randomMachineName(8);
47 $comment = Comment::create([
48 'subject' => $comment_subject,
49 'comment_body' => $comment_body,
50 'entity_id' => $book_node->id(),
51 'entity_type' => 'node',
52 'field_name' => 'comment',
53 'status' => CommentInterface::PUBLISHED,
57 $commenting_user = $this->drupalCreateUser(['access printer-friendly version', 'access comments', 'post comments']);
58 $this->drupalLogin($commenting_user);
60 $this->drupalGet('node/' . $book_node->id());
62 $this->assertText($comment_subject, 'Comment subject found');
63 $this->assertText($comment_body, 'Comment body found');
64 $this->assertText(t('Add new comment'), 'Comment form found');
65 $this->assertField('subject[0][value]', 'Comment form subject found');
67 $this->drupalGet('book/export/html/' . $book_node->id());
69 $this->assertText(t('Comments'), 'Comment thread found');
70 $this->assertText($comment_subject, 'Comment subject found');
71 $this->assertText($comment_body, 'Comment body found');
73 $this->assertNoText(t('Add new comment'), 'Comment form not found');
74 $this->assertNoField('subject[0][value]', 'Comment form subject not found');