Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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\Tests\content_moderation\Traits\ContentModerationTestTrait;
8
9 /**
10  * Test revision revert.
11  *
12  * @group content_moderation
13  */
14 class ModerationRevisionRevertTest extends BrowserTestBase {
15
16   use ContentTypeCreationTrait;
17   use ContentModerationTestTrait;
18
19   /**
20    * Modules to enable.
21    *
22    * @var array
23    */
24   public static $modules = [
25     'content_moderation',
26     'node',
27   ];
28
29   /**
30    * {@inheritdoc}
31    */
32   public function setUp() {
33     parent::setUp();
34
35     $moderated_bundle = $this->createContentType(['type' => 'moderated_bundle']);
36     $moderated_bundle->save();
37
38     $workflow = $this->createEditorialWorkflow();
39     $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated_bundle');
40     $workflow->save();
41
42     /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
43     $router_builder = $this->container->get('router.builder');
44     $router_builder->rebuildIfNeeded();
45
46     $admin = $this->drupalCreateUser([
47       'access content overview',
48       'administer nodes',
49       'bypass node access',
50       'view all revisions',
51       'use editorial transition create_new_draft',
52       'use editorial transition publish',
53     ]);
54     $this->drupalLogin($admin);
55   }
56
57   /**
58    * Test that reverting a revision works.
59    */
60   public function testEditingAfterRevertRevision() {
61     // Create a draft.
62     $this->drupalPostForm('node/add/moderated_bundle', [
63       'title[0][value]' => 'First draft node',
64       'moderation_state[0][state]' => 'draft',
65     ], t('Save'));
66
67     // Now make it published.
68     $this->drupalPostForm('node/1/edit', [
69       'title[0][value]' => 'Published node',
70       'moderation_state[0][state]' => 'published',
71     ], t('Save'));
72
73     // Check the editing form that show the published title.
74     $this->drupalGet('node/1/edit');
75     $this->assertSession()
76       ->pageTextContains('Published node');
77
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');
83
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',
91     ], t('Save'));
92
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.');
96
97     // Check the node has been saved.
98     $this->assertSession()
99       ->pageTextContains('moderated_bundle First draft node has been updated');
100   }
101
102 }