class NodePreviewAnonymousTest
Same name and namespace in other branches
- 11.x core/modules/node/tests/src/Functional/NodePreviewAnonymousTest.php \Drupal\Tests\node\Functional\NodePreviewAnonymousTest
- 10 core/modules/node/tests/src/Functional/NodePreviewAnonymousTest.php \Drupal\Tests\node\Functional\NodePreviewAnonymousTest
- 8.9.x core/modules/node/tests/src/Functional/NodePreviewAnonymousTest.php \Drupal\Tests\node\Functional\NodePreviewAnonymousTest
Tests the node entity preview functionality for anonymous user.
@group node
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\node\Functional\NodePreviewAnonymousTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of NodePreviewAnonymousTest
File
-
core/
modules/ node/ tests/ src/ Functional/ NodePreviewAnonymousTest.php, line 14
Namespace
Drupal\Tests\node\FunctionalView source
class NodePreviewAnonymousTest extends BrowserTestBase {
/**
* Enable node module to test on the preview.
*
* @var array
*/
protected static $modules = [
'node',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create Basic page node type.
$this->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
'display_submitted' => FALSE,
]);
// Grant create and editing permissions to anonymous user:
$anonymous_role = Role::load(AccountInterface::ANONYMOUS_ROLE);
$anonymous_role->grantPermission('create page content');
$anonymous_role->save();
}
/**
* Checks the node preview functionality for anonymous users.
*/
public function testAnonymousPagePreview() {
$title_key = 'title[0][value]';
$body_key = 'body[0][value]';
// Fill in node creation form and preview node.
$edit = [
$title_key => $this->randomMachineName(),
$body_key => $this->randomMachineName(),
];
$this->drupalGet('node/add/page');
$this->submitForm($edit, 'Preview');
// Check that the preview is displaying the title, body and term.
$this->assertSession()
->linkExists('Back to content editing');
$this->assertSession()
->responseContains($edit[$body_key]);
$this->assertSession()
->titleEquals($edit[$title_key] . ' | Drupal');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.