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