953f1116bafdf208afc85a9c9eef46d5b4c6b703
[yaffs-website] / web / core / modules / path / tests / src / Functional / PathContentModerationTest.php
1 <?php
2
3 namespace Drupal\Tests\path\Functional;
4
5 use Drupal\node\Entity\NodeType;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
8
9 /**
10  * Tests path aliases with Content Moderation.
11  *
12  * @group content_moderation
13  * @group path
14  */
15 class PathContentModerationTest extends BrowserTestBase {
16
17   use ContentModerationTestTrait;
18
19   /**
20    * Modules to install.
21    *
22    * @var array
23    */
24   public static $modules = ['node', 'path', 'content_moderation'];
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function setUp() {
30     parent::setUp();
31
32     // Created a content type.
33     $node_type = NodeType::create(['name' => 'moderated', 'type' => 'moderated']);
34     $node_type->save();
35
36     // Set the content type as moderated.
37     $workflow = $this->createEditorialWorkflow();
38     $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated');
39     $workflow->save();
40
41     $this->drupalLogin($this->rootUser);
42   }
43
44   /**
45    * Tests node path aliases on a moderated content type.
46    */
47   public function testNodePathAlias() {
48     // Create some moderated content with a path alias.
49     $this->drupalGet('node/add/moderated');
50     $this->assertSession()->fieldValueEquals('path[0][alias]', '');
51     $this->drupalPostForm(NULL, [
52       'title[0][value]' => 'moderated content',
53       'path[0][alias]' => '/moderated-content',
54       'moderation_state[0][state]' => 'published',
55     ], t('Save'));
56     $node = $this->getNodeByTitle('moderated content');
57
58     // Add a pending revision with the same alias.
59     $this->drupalGet('node/' . $node->id() . '/edit');
60     $this->assertSession()->fieldValueEquals('path[0][alias]', '/moderated-content');
61     $this->drupalPostForm(NULL, [
62       'title[0][value]' => 'pending revision',
63       'path[0][alias]' => '/moderated-content',
64       'moderation_state[0][state]' => 'draft',
65     ], t('Save'));
66     $this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');
67
68     // Create some moderated content with no path alias.
69     $this->drupalGet('node/add/moderated');
70     $this->assertSession()->fieldValueEquals('path[0][alias]', '');
71     $this->drupalPostForm(NULL, [
72       'title[0][value]' => 'moderated content 2',
73       'path[0][alias]' => '',
74       'moderation_state[0][state]' => 'published',
75     ], t('Save'));
76     $node = $this->getNodeByTitle('moderated content 2');
77
78     // Add a pending revision with a new alias.
79     $this->drupalGet('node/' . $node->id() . '/edit');
80     $this->assertSession()->fieldValueEquals('path[0][alias]', '');
81     $this->drupalPostForm(NULL, [
82       'title[0][value]' => 'pending revision',
83       'path[0][alias]' => '/pending-revision',
84       'moderation_state[0][state]' => 'draft',
85     ], t('Save'));
86     $this->assertSession()->pageTextContains('You can only change the URL alias for the published version of this content.');
87
88     // Create some moderated content with no path alias.
89     $this->drupalGet('node/add/moderated');
90     $this->assertSession()->fieldValueEquals('path[0][alias]', '');
91     $this->drupalPostForm(NULL, [
92       'title[0][value]' => 'moderated content 3',
93       'path[0][alias]' => '',
94       'moderation_state[0][state]' => 'published',
95     ], t('Save'));
96     $node = $this->getNodeByTitle('moderated content 3');
97
98     // Add a pending revision with no path alias.
99     $this->drupalGet('node/' . $node->id() . '/edit');
100     $this->assertSession()->fieldValueEquals('path[0][alias]', '');
101     $this->drupalPostForm(NULL, [
102       'title[0][value]' => 'pending revision',
103       'path[0][alias]' => '',
104       'moderation_state[0][state]' => 'draft',
105     ], t('Save'));
106     $this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');
107   }
108
109 }