3 namespace Drupal\Tests\content_moderation\Functional;
6 * Tests moderation state node type integration.
8 * @group content_moderation
10 class ModerationStateNodeTypeTest extends ModerationStateTestBase {
13 * A node type without moderation state disabled.
15 * @covers \Drupal\content_moderation\EntityTypeInfo::formAlter
16 * @covers \Drupal\content_moderation\Entity\Handler\NodeModerationHandler::enforceRevisionsBundleFormAlter
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',
28 $this->assertText('Not moderated Test has been created.');
32 * Tests enabling moderation on an existing node-type, with content.
34 * @covers \Drupal\content_moderation\EntityTypeInfo::formAlter
35 * @covers \Drupal\content_moderation\Entity\Handler\NodeModerationHandler::enforceRevisionsBundleFormAlter
37 public function testEnablingOnExistingContent() {
38 $editor_permissions = [
39 'administer workflows',
40 'access administration pages',
41 'administer content types',
43 'view latest version',
44 'view any unpublished content',
45 'access content overview',
46 'use editorial transition create_new_draft',
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);
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');
59 $this->drupalGet('node/add/not_moderated');
60 $this->drupalPostForm(NULL, [
61 'title[0][value]' => 'Test',
63 $this->assertText('Not moderated Test has been created.');
65 // Now enable moderation state.
66 $this->enableModerationThroughUi('not_moderated');
68 // And make sure it works.
69 $nodes = \Drupal::entityTypeManager()->getStorage('node')
70 ->loadByProperties(['title' => 'Test']);
72 $this->fail('Could not load node with title Test');
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');
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');