195718a6fe286ebc7298343085622eb2069cd2bd
[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     $types[] = $this->createContentType();
40     $types[] = $this->createContentType();
41     $types[] = $this->createContentType();
42
43     $entity_bundle_info = \Drupal::service('entity_type.bundle.info');
44
45     $this->drupalPostForm('admin/config/workflow/workflows/add', [
46       'label' => 'Test',
47       'id' => 'test',
48       'workflow_type' => 'content_moderation',
49     ], 'Save');
50
51     $session = $this->assertSession();
52     // Make sure the test workflow includes the default states and transitions.
53     $session->pageTextContains('Draft');
54     $session->pageTextContains('Published');
55     $session->pageTextContains('Create New Draft');
56     $session->pageTextContains('Publish');
57
58     $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/draft/delete');
59     $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/published/delete');
60
61     // Ensure after a workflow is created, the bundle information can be
62     // refreshed.
63     $entity_bundle_info->clearCachedBundles();
64     $this->assertNotEmpty($entity_bundle_info->getAllBundleInfo());
65
66     $this->clickLink('Add a new state');
67     $this->submitForm([
68       'label' => 'Test State',
69       'id' => 'test_state',
70       'type_settings[published]' => TRUE,
71       'type_settings[default_revision]' => FALSE,
72     ], 'Save');
73     $session->pageTextContains('Created Test State state.');
74     $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/state/test_state/delete');
75
76     // Check there is a link to delete a default transition.
77     $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
78     // Delete the transition.
79     $this->drupalGet('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
80     $this->submitForm([], 'Delete');
81     // The link to delete the transition should now be gone.
82     $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
83
84     // Ensure that the published settings cannot be changed.
85     $this->drupalGet('admin/config/workflow/workflows/manage/test/state/published');
86     $session->fieldDisabled('type_settings[published]');
87     $session->fieldDisabled('type_settings[default_revision]');
88
89     // Ensure that the draft settings cannot be changed.
90     $this->drupalGet('admin/config/workflow/workflows/manage/test/state/draft');
91     $session->fieldDisabled('type_settings[published]');
92     $session->fieldDisabled('type_settings[default_revision]');
93
94     $this->drupalGet('admin/config/workflow/workflows/manage/test/type/node');
95     $session->pageTextContains('Select the content type entities for the Test workflow');
96     foreach ($types as $type) {
97       $session->pageTextContains($type->label());
98     }
99   }
100
101 }