3 namespace Drupal\Tests\content_moderation\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Test the workflow type plugin in the content_moderation module.
10 * @group content_moderation
12 class ContentModerationWorkflowTypeTest extends BrowserTestBase {
19 public static $modules = [
28 protected function setUp() {
30 $admin = $this->drupalCreateUser([
31 'administer workflows',
33 $this->drupalLogin($admin);
37 * Test creating a new workflow using the content moderation plugin.
39 public function testNewWorkflow() {
40 $types[] = $this->createContentType();
41 $types[] = $this->createContentType();
42 $types[] = $this->createContentType();
44 $entity_bundle_info = \Drupal::service('entity_type.bundle.info');
46 $this->drupalPostForm('admin/config/workflow/workflows/add', [
49 'workflow_type' => 'content_moderation',
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');
59 $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/draft/delete');
60 $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/published/delete');
62 // Ensure after a workflow is created, the bundle information can be
64 $entity_bundle_info->clearCachedBundles();
65 $this->assertNotEmpty($entity_bundle_info->getAllBundleInfo());
67 $this->clickLink('Add a new state');
69 'label' => 'Test State',
71 'type_settings[published]' => TRUE,
72 'type_settings[default_revision]' => FALSE,
74 $session->pageTextContains('Created Test State state.');
75 $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/state/test_state/delete');
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');
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]');
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]');
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()));
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.');