ModerationRevisionRevertTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace Drupal\Tests\content_moderation\Functional;
  3. use Drupal\simpletest\ContentTypeCreationTrait;
  4. use Drupal\Tests\BrowserTestBase;
  5. use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
  6. /**
  7. * Test revision revert.
  8. *
  9. * @group content_moderation
  10. */
  11. class ModerationRevisionRevertTest extends BrowserTestBase {
  12. use ContentTypeCreationTrait;
  13. use ContentModerationTestTrait;
  14. /**
  15. * Modules to enable.
  16. *
  17. * @var array
  18. */
  19. public static $modules = [
  20. 'content_moderation',
  21. 'node',
  22. ];
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function setUp() {
  27. parent::setUp();
  28. $moderated_bundle = $this->createContentType(['type' => 'moderated_bundle']);
  29. $moderated_bundle->save();
  30. $workflow = $this->createEditorialWorkflow();
  31. $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated_bundle');
  32. $workflow->save();
  33. /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
  34. $router_builder = $this->container->get('router.builder');
  35. $router_builder->rebuildIfNeeded();
  36. $admin = $this->drupalCreateUser([
  37. 'access content overview',
  38. 'administer nodes',
  39. 'bypass node access',
  40. 'view all revisions',
  41. 'use editorial transition create_new_draft',
  42. 'use editorial transition publish',
  43. ]);
  44. $this->drupalLogin($admin);
  45. }
  46. /**
  47. * Test that reverting a revision works.
  48. */
  49. public function testEditingAfterRevertRevision() {
  50. // Create a draft.
  51. $this->drupalPostForm('node/add/moderated_bundle', [
  52. 'title[0][value]' => 'First draft node',
  53. 'moderation_state[0][state]' => 'draft',
  54. ], t('Save'));
  55. // Now make it published.
  56. $this->drupalPostForm('node/1/edit', [
  57. 'title[0][value]' => 'Published node',
  58. 'moderation_state[0][state]' => 'published',
  59. ], t('Save'));
  60. // Check the editing form that show the published title.
  61. $this->drupalGet('node/1/edit');
  62. $this->assertSession()
  63. ->pageTextContains('Published node');
  64. // Revert the first revision.
  65. $revision_url = 'node/1/revisions/1/revert';
  66. $this->drupalGet($revision_url);
  67. $this->assertSession()->elementExists('css', '.form-submit');
  68. $this->click('.form-submit');
  69. // Check that it reverted.
  70. $this->drupalGet('node/1/edit');
  71. $this->assertSession()
  72. ->pageTextContains('First draft node');
  73. // Try to save the node.
  74. $this->drupalPostForm('node/1/edit', [
  75. 'moderation_state[0][state]' => 'draft',
  76. ], t('Save'));
  77. // Check if the submission passed the EntityChangedConstraintValidator.
  78. $this->assertSession()
  79. ->pageTextNotContains('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.');
  80. // Check the node has been saved.
  81. $this->assertSession()
  82. ->pageTextContains('moderated_bundle First draft node has been updated');
  83. }
  84. }