3 namespace Drupal\Tests\path\Functional;
5 use Drupal\node\Entity\NodeType;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\workflows\Entity\Workflow;
10 * Tests path aliases with Content Moderation.
12 * @group content_moderation
15 class PathContentModerationTest extends BrowserTestBase {
22 public static $modules = ['node', 'path', 'content_moderation'];
27 protected function setUp() {
30 // Created a content type.
31 $node_type = NodeType::create(['name' => 'moderated', 'type' => 'moderated']);
34 // Set the content type as moderated.
35 $workflow = Workflow::load('editorial');
36 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated');
39 $this->drupalLogin($this->rootUser);
43 * Tests node path aliases on a moderated content type.
45 public function testNodePathAlias() {
46 // Create some moderated content with a path alias.
47 $this->drupalGet('node/add/moderated');
48 $this->assertSession()->fieldValueEquals('path[0][alias]', '');
49 $this->drupalPostForm(NULL, [
50 'title[0][value]' => 'moderated content',
51 'path[0][alias]' => '/moderated-content',
52 'moderation_state[0][state]' => 'published',
54 $node = $this->getNodeByTitle('moderated content');
56 // Add a pending revision with the same alias.
57 $this->drupalGet('node/' . $node->id() . '/edit');
58 $this->assertSession()->fieldValueEquals('path[0][alias]', '/moderated-content');
59 $this->drupalPostForm(NULL, [
60 'title[0][value]' => 'pending revision',
61 'path[0][alias]' => '/moderated-content',
62 'moderation_state[0][state]' => 'draft',
64 $this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');
66 // Create some moderated content with no path alias.
67 $this->drupalGet('node/add/moderated');
68 $this->assertSession()->fieldValueEquals('path[0][alias]', '');
69 $this->drupalPostForm(NULL, [
70 'title[0][value]' => 'moderated content 2',
71 'path[0][alias]' => '',
72 'moderation_state[0][state]' => 'published',
74 $node = $this->getNodeByTitle('moderated content 2');
76 // Add a pending revision with a new alias.
77 $this->drupalGet('node/' . $node->id() . '/edit');
78 $this->assertSession()->fieldValueEquals('path[0][alias]', '');
79 $this->drupalPostForm(NULL, [
80 'title[0][value]' => 'pending revision',
81 'path[0][alias]' => '/pending-revision',
82 'moderation_state[0][state]' => 'draft',
84 $this->assertSession()->pageTextContains('You can only change the URL alias for the published version of this content.');
86 // Create some moderated content with no path alias.
87 $this->drupalGet('node/add/moderated');
88 $this->assertSession()->fieldValueEquals('path[0][alias]', '');
89 $this->drupalPostForm(NULL, [
90 'title[0][value]' => 'moderated content 3',
91 'path[0][alias]' => '',
92 'moderation_state[0][state]' => 'published',
94 $node = $this->getNodeByTitle('moderated content 3');
96 // Add a pending revision with no path alias.
97 $this->drupalGet('node/' . $node->id() . '/edit');
98 $this->assertSession()->fieldValueEquals('path[0][alias]', '');
99 $this->drupalPostForm(NULL, [
100 'title[0][value]' => 'pending revision',
101 'path[0][alias]' => '',
102 'moderation_state[0][state]' => 'draft',
104 $this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');