3 namespace Drupal\Tests\node\Functional;
5 use Drupal\Core\Session\AccountInterface;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\user\Entity\Role;
10 * Tests the node entity preview functionality for anonymous user.
14 class NodePreviewAnonymousTest extends BrowserTestBase {
17 * Enable node module to test on the preview.
21 public static $modules = ['node'];
26 protected function setUp() {
28 // Create Basic page node type.
29 $this->drupalCreateContentType([
31 'name' => 'Basic page',
32 'display_submitted' => FALSE,
35 // Grant create and editing permissions to anonymous user:
36 $anonymous_role = Role::load(AccountInterface::ANONYMOUS_ROLE);
37 $anonymous_role->grantPermission('create page content');
38 $anonymous_role->save();
42 * Checks the node preview functionality for anonymous users.
44 public function testAnonymousPagePreview() {
46 $title_key = 'title[0][value]';
47 $body_key = 'body[0][value]';
49 // Fill in node creation form and preview node.
51 $title_key => $this->randomMachineName(),
52 $body_key => $this->randomMachineName(),
54 $this->drupalPostForm('node/add/page', $edit, t('Preview'));
56 // Check that the preview is displaying the title, body and term.
57 $this->assertSession()->linkExists(t('Back to content editing'));
58 $this->assertSession()->responseContains($edit[$body_key]);
59 $this->assertSession()->titleEquals($edit[$title_key] . ' | Drupal');