cbe5807a5fbed274d7892e26630f5fdfecb86cff
[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     'entity_test',
23   ];
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function setUp() {
29     parent::setUp();
30     $admin = $this->drupalCreateUser([
31       'administer workflows',
32     ]);
33     $this->drupalLogin($admin);
34   }
35
36   /**
37    * Test creating a new workflow using the content moderation plugin.
38    */
39   public function testNewWorkflow() {
40     $types[] = $this->createContentType();
41     $types[] = $this->createContentType();
42     $types[] = $this->createContentType();
43
44     $entity_bundle_info = \Drupal::service('entity_type.bundle.info');
45
46     $this->drupalPostForm('admin/config/workflow/workflows/add', [
47       'label' => 'Test',
48       'id' => 'test',
49       'workflow_type' => 'content_moderation',
50     ], 'Save');
51
52     $session = $this->assertSession();
53     // Make sure the test workflow includes the default states and transitions.
54     $session->pageTextContains('Draft');
55     $session->pageTextContains('Published');
56     $session->pageTextContains('Create New Draft');
57     $session->pageTextContains('Publish');
58
59     $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/draft/delete');
60     $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/published/delete');
61
62     // Ensure after a workflow is created, the bundle information can be
63     // refreshed.
64     $entity_bundle_info->clearCachedBundles();
65     $this->assertNotEmpty($entity_bundle_info->getAllBundleInfo());
66
67     $this->clickLink('Add a new state');
68     $this->submitForm([
69       'label' => 'Test State',
70       'id' => 'test_state',
71       'type_settings[published]' => TRUE,
72       'type_settings[default_revision]' => FALSE,
73     ], 'Save');
74     $session->pageTextContains('Created Test State state.');
75     $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/state/test_state/delete');
76
77     // Check there is a link to delete a default transition.
78     $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
79     // Delete the transition.
80     $this->drupalGet('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
81     $this->submitForm([], 'Delete');
82     // The link to delete the transition should now be gone.
83     $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
84
85     // Ensure that the published settings cannot be changed.
86     $this->drupalGet('admin/config/workflow/workflows/manage/test/state/published');
87     $session->fieldDisabled('type_settings[published]');
88     $session->fieldDisabled('type_settings[default_revision]');
89
90     // Ensure that the draft settings cannot be changed.
91     $this->drupalGet('admin/config/workflow/workflows/manage/test/state/draft');
92     $session->fieldDisabled('type_settings[published]');
93     $session->fieldDisabled('type_settings[default_revision]');
94
95     $this->drupalGet('admin/config/workflow/workflows/manage/test/type/node');
96     $session->pageTextContains('Select the content types for the Test workflow');
97     foreach ($types as $type) {
98       $session->pageTextContains($type->label());
99       $session->elementContains('css', sprintf('.form-item-bundles-%s label', $type->id()), sprintf('Update %s', $type->label()));
100     }
101
102     // Ensure warning message are displayed for unsupported features.
103     $this->drupalGet('admin/config/workflow/workflows/manage/test/type/entity_test_rev');
104     $this->assertSession()->pageTextContains('Test entity - revisions entities do not support publishing statuses. For example, even after transitioning from a published workflow state to an unpublished workflow state they will still be visible to site visitors.');
105   }
106
107 }