NodePreviewAnonymousTest.php in Drupal 9
File
core/modules/node/tests/src/Functional/NodePreviewAnonymousTest.php
View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Session\AccountInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\Role;
class NodePreviewAnonymousTest extends BrowserTestBase {
protected static $modules = [
'node',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
'display_submitted' => FALSE,
]);
$anonymous_role = Role::load(AccountInterface::ANONYMOUS_ROLE);
$anonymous_role
->grantPermission('create page content');
$anonymous_role
->save();
}
public function testAnonymousPagePreview() {
$title_key = 'title[0][value]';
$body_key = 'body[0][value]';
$edit = [
$title_key => $this
->randomMachineName(),
$body_key => $this
->randomMachineName(),
];
$this
->drupalGet('node/add/page');
$this
->submitForm($edit, 'Preview');
$this
->assertSession()
->linkExists('Back to content editing');
$this
->assertSession()
->responseContains($edit[$body_key]);
$this
->assertSession()
->titleEquals($edit[$title_key] . ' | Drupal');
}
}