class CommentBookTest
Same name and namespace in other branches
- 10 core/modules/book/tests/src/Functional/Comment/CommentBookTest.php \Drupal\Tests\book\Functional\Comment\CommentBookTest
- 8.9.x core/modules/comment/tests/src/Functional/CommentBookTest.php \Drupal\Tests\comment\Functional\CommentBookTest
Tests visibility of comments on book pages.
@group comment
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\comment\Functional\CommentBookTest uses \Drupal\comment\Tests\CommentTestTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of CommentBookTest
File
-
core/
modules/ comment/ tests/ src/ Functional/ CommentBookTest.php, line 16
Namespace
Drupal\Tests\comment\FunctionalView source
class CommentBookTest extends BrowserTestBase {
use CommentTestTrait;
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'book',
'comment',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create comment field on book.
$this->addDefaultCommentField('node', 'book');
}
/**
* Tests comments in book export.
*/
public function testBookCommentPrint() {
$book_node = Node::create([
'type' => 'book',
'title' => 'Book title',
'body' => 'Book body',
]);
$book_node->book['bid'] = 'new';
$book_node->save();
$comment_subject = $this->randomMachineName(8);
$comment_body = $this->randomMachineName(8);
$comment = Comment::create([
'subject' => $comment_subject,
'comment_body' => $comment_body,
'entity_id' => $book_node->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'status' => CommentInterface::PUBLISHED,
]);
$comment->save();
$commenting_user = $this->drupalCreateUser([
'access printer-friendly version',
'access comments',
'post comments',
]);
$this->drupalLogin($commenting_user);
$this->drupalGet('node/' . $book_node->id());
$this->assertSession()
->pageTextContains($comment_subject);
$this->assertSession()
->pageTextContains($comment_body);
$this->assertSession()
->pageTextContains('Add new comment');
// Ensure that the comment form subject field exists.
$this->assertSession()
->fieldExists('subject[0][value]');
$this->drupalGet('book/export/html/' . $book_node->id());
$this->assertSession()
->pageTextContains('Comments');
$this->assertSession()
->pageTextContains($comment_subject);
$this->assertSession()
->pageTextContains($comment_body);
$this->assertSession()
->pageTextNotContains('Add new comment');
// Verify that the comment form subject field is not found.
$this->assertSession()
->fieldNotExists('subject[0][value]');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.