comparison core/modules/comment/tests/src/Functional/CommentBookTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\Tests\comment\Functional;
4
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;
10
11 /**
12 * Tests visibility of comments on book pages.
13 *
14 * @group comment
15 */
16 class CommentBookTest extends BrowserTestBase {
17
18 use CommentTestTrait;
19
20 /**
21 * Modules to install.
22 *
23 * @var array
24 */
25 public static $modules = ['book', 'comment'];
26
27 protected function setUp() {
28 parent::setUp();
29
30 // Create comment field on book.
31 $this->addDefaultCommentField('node', 'book');
32 }
33
34 /**
35 * Tests comments in book export.
36 */
37 public function testBookCommentPrint() {
38 $book_node = Node::create([
39 'type' => 'book',
40 'title' => 'Book title',
41 'body' => 'Book body',
42 ]);
43 $book_node->book['bid'] = 'new';
44 $book_node->save();
45
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,
55 ]);
56 $comment->save();
57
58 $commenting_user = $this->drupalCreateUser(['access printer-friendly version', 'access comments', 'post comments']);
59 $this->drupalLogin($commenting_user);
60
61 $this->drupalGet('node/' . $book_node->id());
62
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');
67
68 $this->drupalGet('book/export/html/' . $book_node->id());
69
70 $this->assertText(t('Comments'), 'Comment thread found');
71 $this->assertText($comment_subject, 'Comment subject found');
72 $this->assertText($comment_body, 'Comment body found');
73
74 $this->assertNoText(t('Add new comment'), 'Comment form not found');
75 $this->assertNoField('subject[0][value]', 'Comment form subject not found');
76 }
77
78 }