3 namespace Drupal\Tests\content_moderation\Functional;
5 use Drupal\simpletest\ContentTypeCreationTrait;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\workflows\Entity\Workflow;
10 * Test revision revert.
12 * @group content_moderation
14 class ModerationRevisionRevertTest extends BrowserTestBase {
16 use ContentTypeCreationTrait;
23 public static $modules = [
31 public function setUp() {
34 $moderated_bundle = $this->createContentType(['type' => 'moderated_bundle']);
35 $moderated_bundle->save();
37 $workflow = Workflow::load('editorial');
38 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated_bundle');
41 $admin = $this->drupalCreateUser([
42 'access content overview',
46 'view content moderation',
47 'use editorial transition create_new_draft',
48 'use editorial transition publish',
50 $this->drupalLogin($admin);
54 * Test that reverting a revision works.
56 public function testEditingAfterRevertRevision() {
58 $this->drupalPostForm('node/add/moderated_bundle', ['title[0][value]' => 'First draft node'], t('Save and Create New Draft'));
60 // Now make it published.
61 $this->drupalPostForm('node/1/edit', ['title[0][value]' => 'Published node'], t('Save and Publish'));
63 // Check the editing form that show the published title.
64 $this->drupalGet('node/1/edit');
65 $this->assertSession()
66 ->pageTextContains('Published node');
68 // Revert the first revision.
69 $revision_url = 'node/1/revisions/1/revert';
70 $this->drupalGet($revision_url);
71 $this->assertSession()->elementExists('css', '.form-submit');
72 $this->click('.form-submit');
74 // Check that it reverted.
75 $this->drupalGet('node/1/edit');
76 $this->assertSession()
77 ->pageTextContains('First draft node');
78 // Try to save the node.
79 $this->click('.moderation-state-draft > input');
81 // Check if the submission passed the EntityChangedConstraintValidator.
82 $this->assertSession()
83 ->pageTextNotContains('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.');
85 // Check the node has been saved.
86 $this->assertSession()
87 ->pageTextContains('moderated_bundle First draft node has been updated');