3 namespace Drupal\Tests\content_moderation\Functional;
5 use Drupal\simpletest\ContentTypeCreationTrait;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
10 * Test revision revert.
12 * @group content_moderation
14 class ModerationRevisionRevertTest extends BrowserTestBase {
16 use ContentTypeCreationTrait;
17 use ContentModerationTestTrait;
24 public static $modules = [
32 public function setUp() {
35 $moderated_bundle = $this->createContentType(['type' => 'moderated_bundle']);
36 $moderated_bundle->save();
38 $workflow = $this->createEditorialWorkflow();
39 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated_bundle');
42 /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
43 $router_builder = $this->container->get('router.builder');
44 $router_builder->rebuildIfNeeded();
46 $admin = $this->drupalCreateUser([
47 'access content overview',
51 'use editorial transition create_new_draft',
52 'use editorial transition publish',
54 $this->drupalLogin($admin);
58 * Test that reverting a revision works.
60 public function testEditingAfterRevertRevision() {
62 $this->drupalPostForm('node/add/moderated_bundle', [
63 'title[0][value]' => 'First draft node',
64 'moderation_state[0][state]' => 'draft',
67 // Now make it published.
68 $this->drupalPostForm('node/1/edit', [
69 'title[0][value]' => 'Published node',
70 'moderation_state[0][state]' => 'published',
73 // Check the editing form that show the published title.
74 $this->drupalGet('node/1/edit');
75 $this->assertSession()
76 ->pageTextContains('Published node');
78 // Revert the first revision.
79 $revision_url = 'node/1/revisions/1/revert';
80 $this->drupalGet($revision_url);
81 $this->assertSession()->elementExists('css', '.form-submit');
82 $this->click('.form-submit');
84 // Check that it reverted.
85 $this->drupalGet('node/1/edit');
86 $this->assertSession()
87 ->pageTextContains('First draft node');
88 // Try to save the node.
89 $this->drupalPostForm('node/1/edit', [
90 'moderation_state[0][state]' => 'draft',
93 // Check if the submission passed the EntityChangedConstraintValidator.
94 $this->assertSession()
95 ->pageTextNotContains('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.');
97 // Check the node has been saved.
98 $this->assertSession()
99 ->pageTextContains('moderated_bundle First draft node has been updated');