3 namespace Drupal\Tests\path\Functional;
5 use Drupal\node\Entity\NodeType;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
10 * Tests path aliases with Content Moderation.
12 * @group content_moderation
15 class PathContentModerationTest extends BrowserTestBase {
17 use ContentModerationTestTrait;
24 public static $modules = ['node', 'path', 'content_moderation'];
29 protected function setUp() {
32 // Created a content type.
33 $node_type = NodeType::create(['name' => 'moderated', 'type' => 'moderated']);
36 // Set the content type as moderated.
37 $workflow = $this->createEditorialWorkflow();
38 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated');
41 $this->drupalLogin($this->rootUser);
45 * Tests node path aliases on a moderated content type.
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',
56 $node = $this->getNodeByTitle('moderated content');
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',
66 $this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');
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',
76 $node = $this->getNodeByTitle('moderated content 2');
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',
86 $this->assertSession()->pageTextContains('You can only change the URL alias for the published version of this content.');
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',
96 $node = $this->getNodeByTitle('moderated content 3');
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',
106 $this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');