ContentModerationWorkflowTypeTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace Drupal\Tests\content_moderation\Functional;
  3. use Drupal\Tests\BrowserTestBase;
  4. /**
  5. * Test the workflow type plugin in the content_moderation module.
  6. *
  7. * @group content_moderation
  8. */
  9. class ContentModerationWorkflowTypeTest extends BrowserTestBase {
  10. /**
  11. * Modules to install.
  12. *
  13. * @var array
  14. */
  15. public static $modules = [
  16. 'content_moderation',
  17. 'node',
  18. 'entity_test',
  19. ];
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected function setUp() {
  24. parent::setUp();
  25. $admin = $this->drupalCreateUser([
  26. 'administer workflows',
  27. ]);
  28. $this->drupalLogin($admin);
  29. }
  30. /**
  31. * Test creating a new workflow using the content moderation plugin.
  32. */
  33. public function testNewWorkflow() {
  34. $types[] = $this->createContentType();
  35. $types[] = $this->createContentType();
  36. $types[] = $this->createContentType();
  37. $entity_bundle_info = \Drupal::service('entity_type.bundle.info');
  38. $this->drupalPostForm('admin/config/workflow/workflows/add', [
  39. 'label' => 'Test',
  40. 'id' => 'test',
  41. 'workflow_type' => 'content_moderation',
  42. ], 'Save');
  43. $session = $this->assertSession();
  44. // Make sure the test workflow includes the default states and transitions.
  45. $session->pageTextContains('Draft');
  46. $session->pageTextContains('Published');
  47. $session->pageTextContains('Create New Draft');
  48. $session->pageTextContains('Publish');
  49. $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/draft/delete');
  50. $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/published/delete');
  51. // Ensure after a workflow is created, the bundle information can be
  52. // refreshed.
  53. $entity_bundle_info->clearCachedBundles();
  54. $this->assertNotEmpty($entity_bundle_info->getAllBundleInfo());
  55. $this->clickLink('Add a new state');
  56. $this->submitForm([
  57. 'label' => 'Test State',
  58. 'id' => 'test_state',
  59. 'type_settings[published]' => TRUE,
  60. 'type_settings[default_revision]' => FALSE,
  61. ], 'Save');
  62. $session->pageTextContains('Created Test State state.');
  63. $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/state/test_state/delete');
  64. // Check there is a link to delete a default transition.
  65. $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
  66. // Delete the transition.
  67. $this->drupalGet('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
  68. $this->submitForm([], 'Delete');
  69. // The link to delete the transition should now be gone.
  70. $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
  71. // Ensure that the published settings cannot be changed.
  72. $this->drupalGet('admin/config/workflow/workflows/manage/test/state/published');
  73. $session->fieldDisabled('type_settings[published]');
  74. $session->fieldDisabled('type_settings[default_revision]');
  75. // Ensure that the draft settings cannot be changed.
  76. $this->drupalGet('admin/config/workflow/workflows/manage/test/state/draft');
  77. $session->fieldDisabled('type_settings[published]');
  78. $session->fieldDisabled('type_settings[default_revision]');
  79. $this->drupalGet('admin/config/workflow/workflows/manage/test/type/node');
  80. $session->pageTextContains('Select the content types for the Test workflow');
  81. foreach ($types as $type) {
  82. $session->pageTextContains($type->label());
  83. $session->elementContains('css', sprintf('.form-item-bundles-%s label', $type->id()), sprintf('Update %s', $type->label()));
  84. }
  85. // Ensure warning message are displayed for unsupported features.
  86. $this->drupalGet('admin/config/workflow/workflows/manage/test/type/entity_test_rev');
  87. $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.');
  88. }
  89. }