Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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    * @covers \Drupal\content_moderation\EntityTypeInfo::formAlter
16    * @covers \Drupal\content_moderation\Entity\Handler\NodeModerationHandler::enforceRevisionsBundleFormAlter
17    */
18   public function testNotModerated() {
19     $this->drupalLogin($this->adminUser);
20     $this->createContentTypeFromUi('Not moderated', 'not_moderated');
21     $this->assertText('The content type Not moderated has been added.');
22     $this->grantUserPermissionToCreateContentOfType($this->adminUser, 'not_moderated');
23     $this->drupalGet('node/add/not_moderated');
24     $this->assertRaw('Save');
25     $this->drupalPostForm(NULL, [
26       'title[0][value]' => 'Test',
27     ], t('Save'));
28     $this->assertText('Not moderated Test has been created.');
29   }
30
31   /**
32    * Tests enabling moderation on an existing node-type, with content.
33    *
34    * @covers \Drupal\content_moderation\EntityTypeInfo::formAlter
35    * @covers \Drupal\content_moderation\Entity\Handler\NodeModerationHandler::enforceRevisionsBundleFormAlter
36    */
37   public function testEnablingOnExistingContent() {
38     $editor_permissions = [
39       'administer workflows',
40       'access administration pages',
41       'administer content types',
42       'administer nodes',
43       'view latest version',
44       'view any unpublished content',
45       'access content overview',
46       'use editorial transition create_new_draft',
47     ];
48     $publish_permissions = array_merge($editor_permissions, ['use editorial transition publish']);
49     $editor = $this->drupalCreateUser($editor_permissions);
50     $editor_with_publish = $this->drupalCreateUser($publish_permissions);
51
52     // Create a node type that is not moderated.
53     $this->drupalLogin($editor);
54     $this->createContentTypeFromUi('Not moderated', 'not_moderated');
55     $this->grantUserPermissionToCreateContentOfType($editor, 'not_moderated');
56     $this->grantUserPermissionToCreateContentOfType($editor_with_publish, 'not_moderated');
57
58     // Create content.
59     $this->drupalGet('node/add/not_moderated');
60     $this->drupalPostForm(NULL, [
61       'title[0][value]' => 'Test',
62     ], t('Save'));
63     $this->assertText('Not moderated Test has been created.');
64
65     // Now enable moderation state.
66     $this->enableModerationThroughUi('not_moderated');
67
68     // And make sure it works.
69     $nodes = \Drupal::entityTypeManager()->getStorage('node')
70       ->loadByProperties(['title' => 'Test']);
71     if (empty($nodes)) {
72       $this->fail('Could not load node with title Test');
73       return;
74     }
75     $node = reset($nodes);
76     $this->drupalGet('node/' . $node->id());
77     $this->assertResponse(200);
78     $this->assertLinkByHref('node/' . $node->id() . '/edit');
79     $this->drupalGet('node/' . $node->id() . '/edit');
80     $this->assertResponse(200);
81     $this->assertSession()->optionExists('moderation_state[0][state]', 'draft');
82     $this->assertSession()->optionNotExists('moderation_state[0][state]', 'published');
83
84     $this->drupalLogin($editor_with_publish);
85     $this->drupalGet('node/' . $node->id() . '/edit');
86     $this->assertResponse(200);
87     $this->assertSession()->optionExists('moderation_state[0][state]', 'draft');
88     $this->assertSession()->optionExists('moderation_state[0][state]', 'published');
89   }
90
91 }