diff --git a/core/modules/content_moderation/src/Plugin/Action/ModerationStateChange.php b/core/modules/content_moderation/src/Plugin/Action/ModerationStateChange.php index 9f87c9ebb1..50dc96395a 100644 --- a/core/modules/content_moderation/src/Plugin/Action/ModerationStateChange.php +++ b/core/modules/content_moderation/src/Plugin/Action/ModerationStateChange.php @@ -4,7 +4,6 @@ use Drupal\content_moderation\ModerationInformationInterface; use Drupal\Core\Access\AccessResult; -use Drupal\Core\Action\ActionBase; use Drupal\Core\Action\ConfigurableActionBase; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\DependencyTrait; @@ -86,6 +85,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['configuration'] = [ '#type' => 'container', + '#id' => 'edit-configuration', ]; $form['configuration']['workflow'] = [ diff --git a/core/modules/content_moderation/tests/src/Functional/ActionConfigurationTest.php b/core/modules/content_moderation/tests/src/Functional/ActionConfigurationTest.php new file mode 100644 index 0000000000..6427d8d1d4 --- /dev/null +++ b/core/modules/content_moderation/tests/src/Functional/ActionConfigurationTest.php @@ -0,0 +1,113 @@ +createContentType(['type' => 'page']); + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page'); + $workflow->save(); + } + + /** + * Tests configuration of action through administration interface. + */ + public function testActionConfiguration() { + // Create a user with permission to view the actions administration pages. + $user = $this->drupalCreateUser(['administer actions']); + $this->drupalLogin($user); + $assert_session = $this->assertSession(); + + // Make a POST request to admin/config/system/actions. + $edit = []; + $edit['action'] = Crypt::hashBase64('moderation_state_change:node'); + $this->drupalPostForm('admin/config/system/actions', $edit, t('Create')); + $assert_session->statusCodeEquals(200); + + // Make a POST request to the individual action configuration page. + $edit = []; + $action_label = $this->randomMachineName(); + $edit['label'] = $action_label; + $edit['id'] = strtolower($action_label); + $edit['workflow'] = 'editorial'; + $edit['state'] = 'draft'; + $this->drupalPostForm('admin/config/system/actions/add/' . Crypt::hashBase64('moderation_state_change:node'), $edit, t('Save')); + $assert_session->statusCodeEquals(200); + + $action_id = $edit['id']; + + // Make sure that the new complex action was saved properly. + $assert_session->pageTextContains(t('The action has been successfully saved.')); + $assert_session->pageTextContains($action_label); + + // Make another POST request to the action edit page. + $this->clickLink(t('Configure')); + $assert_session->statusCodeEquals(200); + $assert_session->fieldValueEquals('workflow', 'editorial'); + $assert_session->fieldValueEquals('state', 'draft'); + + $edit = []; + $new_action_label = $this->randomMachineName(); + $edit['label'] = $new_action_label; + $edit['workflow'] = 'editorial'; + $edit['state'] = 'published'; + $this->drupalPostForm(NULL, $edit, t('Save')); + $assert_session->statusCodeEquals(200); + + // Make sure that the action updated properly. + $assert_session->pageTextContains(t('The action has been successfully saved.')); + $assert_session->pageTextNotContains($action_label); + $assert_session->pageTextContains($new_action_label); + + $this->clickLink(t('Configure')); + $assert_session->statusCodeEquals(200); + $assert_session->fieldValueEquals('workflow', 'editorial'); + $assert_session->fieldValueEquals('state', 'published'); + + // Make sure that deletions work properly. + $this->drupalGet('admin/config/system/actions'); + $this->clickLink(t('Delete')); + $assert_session->statusCodeEquals(200); + $edit = []; + $this->drupalPostForm(NULL, $edit, t('Delete')); + $assert_session->statusCodeEquals(200); + + // Make sure that the action was actually deleted. + $assert_session->responseContains(t('The action %action has been deleted.', ['%action' => $new_action_label])); + $this->drupalGet('admin/config/system/actions'); + $assert_session->statusCodeEquals(200); + $assert_session->pageTextNotContains($new_action_label); + + $action = Action::load($action_id); + $this->assertFalse($action, 'Make sure the action is gone after being deleted.'); + } + +} diff --git a/core/modules/content_moderation/tests/src/FunctionalJavascript/ActionConfigurationTest.php b/core/modules/content_moderation/tests/src/FunctionalJavascript/ActionConfigurationTest.php new file mode 100644 index 0000000000..0d7bf900ea --- /dev/null +++ b/core/modules/content_moderation/tests/src/FunctionalJavascript/ActionConfigurationTest.php @@ -0,0 +1,87 @@ +createContentType(['type' => 'page']); + $this->createContentType(['type' => 'article']); + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page'); + $workflow->save(); + $workflow = Workflow::create([ + 'id' => 'moderation', + 'label' => 'Moderation', + 'type' => 'content_moderation', + ]); + $workflow->getTypePlugin() + ->addState('moderated', 'Moderated') + ->addEntityTypeAndBundle('node', 'article'); + $workflow->save(); + } + + /** + * Tests configuration of action through administration interface. + */ + public function testActionConfigurationXYZ() { + // Create a user with permission to view the actions administration pages. + $user = $this->drupalCreateUser(['administer actions']); + $this->drupalLogin($user); + $assert_session = $this->assertSession(); + + // Make a POST request to admin/config/system/actions. + $edit = []; + $edit['action'] = Crypt::hashBase64('moderation_state_change:node'); + $this->drupalPostForm('admin/config/system/actions', $edit, t('Create')); + $assert_session->statusCodeEquals(200); + $workflow_select = $assert_session->selectExists('workflow'); + $this->assertNotNull($workflow_select->find('named', ['option', 'editorial'])); + $this->assertNotNull($workflow_select->find('named', ['option', 'moderation'])); + + $state_select = $assert_session->selectExists('state'); + $this->assertNotNull($state_select->find('named', ['option', 'archived'])); + $this->assertNotNull($state_select->find('named', ['option', 'draft'])); + $this->assertNotNull($state_select->find('named', ['option', 'published'])); + // Trigger the AJAX. + $workflow_select->selectOption('moderation'); + $assert_session->assertWaitOnAjaxRequest(); + $state_select = $assert_session->selectExists('state'); + $this->assertNotNull($state_select->find('named', ['option', 'draft'])); + $this->assertNotNull($state_select->find('named', ['option', 'moderated'])); + $this->assertNotNull($state_select->find('named', ['option', 'published'])); + // Trigger the AJAX. + $workflow_select->selectOption('editorial'); + $assert_session->assertWaitOnAjaxRequest(); + $state_select = $assert_session->selectExists('state'); + $this->assertNotNull($state_select->find('named', ['option', 'archived'])); + $this->assertNotNull($state_select->find('named', ['option', 'draft'])); + $this->assertNotNull($state_select->find('named', ['option', 'published'])); + } + +} diff --git a/core/modules/content_moderation/tests/src/Kernel/ActionConfigSchemaTest.php b/core/modules/content_moderation/tests/src/Kernel/ActionConfigSchemaTest.php new file mode 100644 index 0000000000..8263458214 --- /dev/null +++ b/core/modules/content_moderation/tests/src/Kernel/ActionConfigSchemaTest.php @@ -0,0 +1,91 @@ +installEntitySchema('node'); + $this->installSchema('node', 'node_access'); + $this->installEntitySchema('content_moderation_state'); + $this->installConfig('content_moderation'); + + $node_type = NodeType::create([ + 'type' => 'page', + 'label' => 'Page', + ]); + $node_type->save(); + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page'); + $workflow->save(); + + $action = Action::create([ + 'id' => 'change_moderation_state_to_draft', + 'type' => 'node', + 'label' => t('Change moderation state to Draft'), + 'configuration' => [ + 'workflow' => 'editorial', + 'state' => 'draft', + ], + 'plugin' => 'moderation_state_change:node', + ]); + $action->trustData()->save(); + + $action = Action::create([ + 'id' => 'change_moderation_state_to_published', + 'type' => 'node', + 'label' => t('Change moderation state to Published'), + 'configuration' => [ + 'workflow' => 'editorial', + 'state' => 'published', + ], + 'plugin' => 'moderation_state_change:node', + ]); + $action->trustData()->save(); + } + + /** + * Tests whether the change_moderation_state action config schema is valid. + */ + public function testValidActionConfigSchema() { + + // Test change_moderation_state_to_draft configuration. + $config = $this->config('system.action.change_moderation_state_to_draft'); + $this->assertEquals($config->get('id'), 'change_moderation_state_to_draft'); + $this->assertConfigSchema(\Drupal::service('config.typed'), $config->getName(), $config->get()); + + // Test change_moderation_state_to_published configuration. + $config = $this->config('system.action.change_moderation_state_to_published'); + $this->assertEquals($config->get('id'), 'change_moderation_state_to_published'); + $this->assertConfigSchema(\Drupal::service('config.typed'), $config->getName(), $config->get()); + } + +}