annotate core/modules/comment/tests/src/Functional/CommentBookTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\comment\Functional;
Chris@0 4
Chris@0 5 use Drupal\comment\CommentInterface;
Chris@0 6 use Drupal\comment\Tests\CommentTestTrait;
Chris@0 7 use Drupal\node\Entity\Node;
Chris@0 8 use Drupal\Tests\BrowserTestBase;
Chris@0 9 use Drupal\comment\Entity\Comment;
Chris@0 10
Chris@0 11 /**
Chris@0 12 * Tests visibility of comments on book pages.
Chris@0 13 *
Chris@0 14 * @group comment
Chris@0 15 */
Chris@0 16 class CommentBookTest extends BrowserTestBase {
Chris@0 17
Chris@0 18 use CommentTestTrait;
Chris@0 19
Chris@0 20 /**
Chris@0 21 * Modules to install.
Chris@0 22 *
Chris@0 23 * @var array
Chris@0 24 */
Chris@0 25 public static $modules = ['book', 'comment'];
Chris@0 26
Chris@0 27 protected function setUp() {
Chris@0 28 parent::setUp();
Chris@0 29
Chris@0 30 // Create comment field on book.
Chris@0 31 $this->addDefaultCommentField('node', 'book');
Chris@0 32 }
Chris@0 33
Chris@0 34 /**
Chris@0 35 * Tests comments in book export.
Chris@0 36 */
Chris@0 37 public function testBookCommentPrint() {
Chris@0 38 $book_node = Node::create([
Chris@0 39 'type' => 'book',
Chris@0 40 'title' => 'Book title',
Chris@0 41 'body' => 'Book body',
Chris@0 42 ]);
Chris@0 43 $book_node->book['bid'] = 'new';
Chris@0 44 $book_node->save();
Chris@0 45
Chris@0 46 $comment_subject = $this->randomMachineName(8);
Chris@0 47 $comment_body = $this->randomMachineName(8);
Chris@0 48 $comment = Comment::create([
Chris@0 49 'subject' => $comment_subject,
Chris@0 50 'comment_body' => $comment_body,
Chris@0 51 'entity_id' => $book_node->id(),
Chris@0 52 'entity_type' => 'node',
Chris@0 53 'field_name' => 'comment',
Chris@0 54 'status' => CommentInterface::PUBLISHED,
Chris@0 55 ]);
Chris@0 56 $comment->save();
Chris@0 57
Chris@0 58 $commenting_user = $this->drupalCreateUser(['access printer-friendly version', 'access comments', 'post comments']);
Chris@0 59 $this->drupalLogin($commenting_user);
Chris@0 60
Chris@0 61 $this->drupalGet('node/' . $book_node->id());
Chris@0 62
Chris@0 63 $this->assertText($comment_subject, 'Comment subject found');
Chris@0 64 $this->assertText($comment_body, 'Comment body found');
Chris@0 65 $this->assertText(t('Add new comment'), 'Comment form found');
Chris@0 66 $this->assertField('subject[0][value]', 'Comment form subject found');
Chris@0 67
Chris@0 68 $this->drupalGet('book/export/html/' . $book_node->id());
Chris@0 69
Chris@0 70 $this->assertText(t('Comments'), 'Comment thread found');
Chris@0 71 $this->assertText($comment_subject, 'Comment subject found');
Chris@0 72 $this->assertText($comment_body, 'Comment body found');
Chris@0 73
Chris@0 74 $this->assertNoText(t('Add new comment'), 'Comment form not found');
Chris@0 75 $this->assertNoField('subject[0][value]', 'Comment form subject not found');
Chris@0 76 }
Chris@0 77
Chris@0 78 }