Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / content_moderation / tests / src / Functional / ModerationStateNodeTypeTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Functional;
4
5 /**
6  * Tests moderation state node type integration.
7  *
8  * @group content_moderation
9  */
10 class ModerationStateNodeTypeTest extends ModerationStateTestBase {
11
12   /**
13    * A node type without moderation state disabled.
14    */
15   public function testNotModerated() {
16     $this->drupalLogin($this->adminUser);
17     $this->createContentTypeFromUi('Not moderated', 'not_moderated');
18     $this->assertText('The content type Not moderated has been added.');
19     $this->grantUserPermissionToCreateContentOfType($this->adminUser, 'not_moderated');
20     $this->drupalGet('node/add/not_moderated');
21     $this->assertRaw('Save as unpublished');
22     $this->drupalPostForm(NULL, [
23       'title[0][value]' => 'Test',
24     ], t('Save and publish'));
25     $this->assertText('Not moderated Test has been created.');
26   }
27
28   /**
29    * Tests enabling moderation on an existing node-type, with content.
30    */
31   public function testEnablingOnExistingContent() {
32     $editor_permissions = [
33       'administer content moderation',
34       'access administration pages',
35       'administer content types',
36       'administer nodes',
37       'view latest version',
38       'view any unpublished content',
39       'access content overview',
40       'use editorial transition create_new_draft',
41     ];
42     $publish_permissions = array_merge($editor_permissions, ['use editorial transition publish']);
43     $editor = $this->drupalCreateUser($editor_permissions);
44     $editor_with_publish = $this->drupalCreateUser($publish_permissions);
45
46     // Create a node type that is not moderated.
47     $this->drupalLogin($editor);
48     $this->createContentTypeFromUi('Not moderated', 'not_moderated');
49     $this->grantUserPermissionToCreateContentOfType($editor, 'not_moderated');
50     $this->grantUserPermissionToCreateContentOfType($editor_with_publish, 'not_moderated');
51
52     // Create content.
53     $this->drupalGet('node/add/not_moderated');
54     $this->drupalPostForm(NULL, [
55       'title[0][value]' => 'Test',
56     ], t('Save and publish'));
57     $this->assertText('Not moderated Test has been created.');
58
59     // Now enable moderation state, ensuring all the expected links and tabs are
60     // present.
61     $this->drupalGet('admin/structure/types');
62     $this->assertLinkByHref('admin/structure/types/manage/not_moderated/moderation');
63     $this->drupalGet('admin/structure/types/manage/not_moderated');
64     $this->assertLinkByHref('admin/structure/types/manage/not_moderated/moderation');
65     $this->drupalGet('admin/structure/types/manage/not_moderated/moderation');
66     $this->assertOptionSelected('edit-workflow', '');
67     $this->assertNoLink('Delete');
68     $edit['workflow'] = 'editorial';
69     $this->drupalPostForm(NULL, $edit, t('Save'));
70
71     // And make sure it works.
72     $nodes = \Drupal::entityTypeManager()->getStorage('node')
73       ->loadByProperties(['title' => 'Test']);
74     if (empty($nodes)) {
75       $this->fail('Could not load node with title Test');
76       return;
77     }
78     $node = reset($nodes);
79     $this->drupalGet('node/' . $node->id());
80     $this->assertResponse(200);
81     $this->assertLinkByHref('node/' . $node->id() . '/edit');
82     $this->drupalGet('node/' . $node->id() . '/edit');
83     $this->assertResponse(200);
84     $this->assertRaw('Save and Create New Draft');
85     $this->assertNoRaw('Save and Publish');
86
87     $this->drupalLogin($editor_with_publish);
88     $this->drupalGet('node/' . $node->id() . '/edit');
89     $this->assertResponse(200);
90     $this->assertRaw('Save and Create New Draft');
91     $this->assertRaw('Save and Publish');
92   }
93
94 }