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 = [
27 protected function setUp() {
29 $admin = $this->drupalCreateUser([
30 'administer workflows',
32 $this->drupalLogin($admin);
36 * Test creating a new workflow using the content moderation plugin.
38 public function testNewWorkflow() {
39 $types[] = $this->createContentType();
40 $types[] = $this->createContentType();
41 $types[] = $this->createContentType();
43 $entity_bundle_info = \Drupal::service('entity_type.bundle.info');
45 $this->drupalPostForm('admin/config/workflow/workflows/add', [
48 'workflow_type' => 'content_moderation',
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');
58 $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/draft/delete');
59 $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/published/delete');
61 // Ensure after a workflow is created, the bundle information can be
63 $entity_bundle_info->clearCachedBundles();
64 $this->assertNotEmpty($entity_bundle_info->getAllBundleInfo());
66 $this->clickLink('Add a new state');
68 'label' => 'Test State',
70 'type_settings[published]' => TRUE,
71 'type_settings[default_revision]' => FALSE,
73 $session->pageTextContains('Created Test State state.');
74 $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/state/test_state/delete');
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');
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]');
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]');
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());