Version 1
[yaffs-website] / web / core / modules / content_moderation / tests / src / Functional / ContentModerationWorkflowTypeTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Test the workflow type plugin in the content_moderation module.
9  *
10  * @group content_moderation
11  */
12 class ContentModerationWorkflowTypeTest extends BrowserTestBase {
13
14   /**
15    * Modules to install.
16    *
17    * @var array
18    */
19   public static $modules = [
20     'content_moderation',
21     'node',
22   ];
23
24   /**
25    * {@inheritdoc}
26    */
27   protected function setUp() {
28     parent::setUp();
29     $admin = $this->drupalCreateUser([
30       'administer workflows',
31     ]);
32     $this->drupalLogin($admin);
33   }
34
35   /**
36    * Test creating a new workflow using the content moderation plugin.
37    */
38   public function testNewWorkflow() {
39     $entity_bundle_info = \Drupal::service('entity_type.bundle.info');
40
41     $this->drupalPostForm('admin/config/workflow/workflows/add', [
42       'label' => 'Test Workflow',
43       'id' => 'test_workflow',
44       'workflow_type' => 'content_moderation',
45     ], 'Save');
46
47     // Make sure the test workflow includes the default states and transitions.
48     $this->assertSession()->pageTextContains('Draft');
49     $this->assertSession()->pageTextContains('Published');
50     $this->assertSession()->pageTextContains('Create New Draft');
51     $this->assertSession()->pageTextContains('Publish');
52
53     // Ensure after a workflow is created, the bundle information can be
54     // refreshed.
55     $entity_bundle_info->clearCachedBundles();
56     $this->assertNotEmpty($entity_bundle_info->getAllBundleInfo());
57
58     $this->clickLink('Add a new state');
59     $this->submitForm([
60       'label' => 'Test State',
61       'id' => 'test_state',
62       'type_settings[content_moderation][published]' => TRUE,
63       'type_settings[content_moderation][default_revision]' => FALSE,
64     ], 'Save');
65     $this->assertSession()->pageTextContains('Created Test State state.');
66
67     // Ensure that the published settings cannot be changed.
68     $this->drupalGet('admin/config/workflow/workflows/manage/test_workflow/state/published');
69     $this->assertSession()->fieldDisabled('type_settings[content_moderation][published]');
70     $this->assertSession()->fieldDisabled('type_settings[content_moderation][default_revision]');
71
72     // Ensure that the draft settings cannot be changed.
73     $this->drupalGet('admin/config/workflow/workflows/manage/test_workflow/state/draft');
74     $this->assertSession()->fieldDisabled('type_settings[content_moderation][published]');
75     $this->assertSession()->fieldDisabled('type_settings[content_moderation][default_revision]');
76   }
77
78 }