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
1 <?php
2
3 namespace Drupal\Tests\node\Functional;
4
5 use Drupal\Core\Session\AccountInterface;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\user\Entity\Role;
8
9 /**
10  * Tests the node entity preview functionality for anonymous user.
11  *
12  * @group node
13  */
14 class NodePreviewAnonymousTest extends BrowserTestBase {
15
16   /**
17    * Enable node module to test on the preview.
18    *
19    * @var array
20    */
21   public static $modules = ['node'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp() {
27     parent::setUp();
28     // Create Basic page node type.
29     $this->drupalCreateContentType([
30       'type' => 'page',
31       'name' => 'Basic page',
32       'display_submitted' => FALSE,
33     ]);
34
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();
39   }
40
41   /**
42    * Checks the node preview functionality for anonymous users.
43    */
44   public function testAnonymousPagePreview() {
45
46     $title_key = 'title[0][value]';
47     $body_key = 'body[0][value]';
48
49     // Fill in node creation form and preview node.
50     $edit = [
51       $title_key => $this->randomMachineName(),
52       $body_key => $this->randomMachineName(),
53     ];
54     $this->drupalPostForm('node/add/page', $edit, t('Preview'));
55
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');
60   }
61
62 }