db backup prior to drupal security update
[yaffs-website] / web / core / modules / comment / src / Tests / CommentBookTest.php
1 <?php
2
3 namespace Drupal\comment\Tests;
4
5 use Drupal\comment\CommentInterface;
6 use Drupal\node\Entity\Node;
7 use Drupal\simpletest\WebTestBase;
8 use Drupal\comment\Entity\Comment;
9
10 /**
11  * Tests visibility of comments on book pages.
12  *
13  * @group comment
14  */
15 class CommentBookTest extends WebTestBase {
16
17   use CommentTestTrait;
18
19   /**
20    * Modules to install.
21    *
22    * @var array
23    */
24   public static $modules = ['book', 'comment'];
25
26   protected function setUp() {
27     parent::setUp();
28
29     // Create comment field on book.
30     $this->addDefaultCommentField('node', 'book');
31   }
32
33   /**
34    * Tests comments in book export.
35    */
36   public function testBookCommentPrint() {
37     $book_node = Node::create([
38       'type' => 'book',
39       'title' => 'Book title',
40       'body' => 'Book body',
41     ]);
42     $book_node->book['bid'] = 'new';
43     $book_node->save();
44
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,
54     ]);
55     $comment->save();
56
57     $commenting_user = $this->drupalCreateUser(['access printer-friendly version', 'access comments', 'post comments']);
58     $this->drupalLogin($commenting_user);
59
60     $this->drupalGet('node/' . $book_node->id());
61
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');
66
67     $this->drupalGet('book/export/html/' . $book_node->id());
68
69     $this->assertText(t('Comments'), 'Comment thread found');
70     $this->assertText($comment_subject, 'Comment subject found');
71     $this->assertText($comment_body, 'Comment body found');
72
73     $this->assertNoText(t('Add new comment'), 'Comment form not found');
74     $this->assertNoField('subject[0][value]', 'Comment form subject not found');
75   }
76
77 }