Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / node / tests / src / Functional / NodePreviewAnonymousTest.php
diff --git a/web/core/modules/node/tests/src/Functional/NodePreviewAnonymousTest.php b/web/core/modules/node/tests/src/Functional/NodePreviewAnonymousTest.php
new file mode 100644 (file)
index 0000000..f10d8b7
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+
+namespace Drupal\Tests\node\Functional;
+
+use Drupal\Core\Session\AccountInterface;
+use Drupal\Tests\BrowserTestBase;
+use Drupal\user\Entity\Role;
+
+/**
+ * Tests the node entity preview functionality for anonymous user.
+ *
+ * @group node
+ */
+class NodePreviewAnonymousTest extends BrowserTestBase {
+
+  /**
+   * Enable node module to test on the preview.
+   *
+   * @var array
+   */
+  public static $modules = ['node'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    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->drupalPostForm('node/add/page', $edit, t('Preview'));
+
+    // Check that the preview is displaying the title, body and term.
+    $this->assertSession()->linkExists(t('Back to content editing'));
+    $this->assertSession()->responseContains($edit[$body_key]);
+    $this->assertSession()->titleEquals($edit[$title_key] . ' | Drupal');
+  }
+
+}