7dac15667fbdd5627371837e3fe17c25a26e6bb2
[yaffs-website] / web / core / modules / content_moderation / tests / src / Functional / ModerationRevisionRevertTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Functional;
4
5 use Drupal\simpletest\ContentTypeCreationTrait;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\workflows\Entity\Workflow;
8
9 /**
10  * Test revision revert.
11  *
12  * @group content_moderation
13  */
14 class ModerationRevisionRevertTest extends BrowserTestBase {
15
16   use ContentTypeCreationTrait;
17
18   /**
19    * Modules to enable.
20    *
21    * @var array
22    */
23   public static $modules = [
24     'content_moderation',
25     'node',
26   ];
27
28   /**
29    * {@inheritdoc}
30    */
31   public function setUp() {
32     parent::setUp();
33
34     $moderated_bundle = $this->createContentType(['type' => 'moderated_bundle']);
35     $moderated_bundle->save();
36
37     $workflow = Workflow::load('editorial');
38     $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated_bundle');
39     $workflow->save();
40
41     $admin = $this->drupalCreateUser([
42       'access content overview',
43       'administer nodes',
44       'bypass node access',
45       'view all revisions',
46       'view content moderation',
47       'use editorial transition create_new_draft',
48       'use editorial transition publish',
49     ]);
50     $this->drupalLogin($admin);
51   }
52
53   /**
54    * Test that reverting a revision works.
55    */
56   public function testEditingAfterRevertRevision() {
57     // Create a draft.
58     $this->drupalPostForm('node/add/moderated_bundle', ['title[0][value]' => 'First draft node'], t('Save and Create New Draft'));
59
60     // Now make it published.
61     $this->drupalPostForm('node/1/edit', ['title[0][value]' => 'Published node'], t('Save and Publish'));
62
63     // Check the editing form that show the published title.
64     $this->drupalGet('node/1/edit');
65     $this->assertSession()
66       ->pageTextContains('Published node');
67
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');
73
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');
80
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.');
84
85     // Check the node has been saved.
86     $this->assertSession()
87       ->pageTextContains('moderated_bundle First draft node has been updated');
88   }
89
90 }