You are here

public function PathContentModerationTest::testNodePathAlias in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/path/tests/src/Functional/PathContentModerationTest.php \Drupal\Tests\path\Functional\PathContentModerationTest::testNodePathAlias()

Tests node path aliases on a moderated content type.

File

core/modules/path/tests/src/Functional/PathContentModerationTest.php, line 78

Class

PathContentModerationTest
Tests path aliases with Content Moderation.

Namespace

Drupal\Tests\path\Functional

Code

public function testNodePathAlias() {

  // Create some moderated content with a path alias.
  $this
    ->drupalGet('node/add/moderated');
  $this
    ->assertSession()
    ->fieldValueEquals('path[0][alias]', '');
  $this
    ->submitForm([
    'title[0][value]' => 'moderated content',
    'path[0][alias]' => '/moderated-content',
    'moderation_state[0][state]' => 'published',
  ], 'Save');
  $node = $this
    ->getNodeByTitle('moderated content');

  // Add a pending revision with the same alias.
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->assertSession()
    ->fieldValueEquals('path[0][alias]', '/moderated-content');
  $this
    ->submitForm([
    'title[0][value]' => 'pending revision',
    'path[0][alias]' => '/moderated-content',
    'moderation_state[0][state]' => 'draft',
  ], 'Save');
  $this
    ->assertSession()
    ->pageTextNotContains('You can only change the URL alias for the published version of this content.');

  // Create some moderated content with no path alias.
  $this
    ->drupalGet('node/add/moderated');
  $this
    ->assertSession()
    ->fieldValueEquals('path[0][alias]', '');
  $this
    ->submitForm([
    'title[0][value]' => 'moderated content 2',
    'path[0][alias]' => '',
    'moderation_state[0][state]' => 'published',
  ], 'Save');
  $node = $this
    ->getNodeByTitle('moderated content 2');

  // Add a pending revision with a new alias.
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->assertSession()
    ->fieldValueEquals('path[0][alias]', '');
  $this
    ->submitForm([
    'title[0][value]' => 'pending revision',
    'path[0][alias]' => '/pending-revision',
    'moderation_state[0][state]' => 'draft',
  ], 'Save');
  $this
    ->assertSession()
    ->pageTextContains('You can only change the URL alias for the published version of this content.');

  // Create some moderated content with no path alias.
  $this
    ->drupalGet('node/add/moderated');
  $this
    ->assertSession()
    ->fieldValueEquals('path[0][alias]', '');
  $this
    ->submitForm([
    'title[0][value]' => 'moderated content 3',
    'path[0][alias]' => '',
    'moderation_state[0][state]' => 'published',
  ], 'Save');
  $node = $this
    ->getNodeByTitle('moderated content 3');

  // Add a pending revision with no path alias.
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->assertSession()
    ->fieldValueEquals('path[0][alias]', '');
  $this
    ->submitForm([
    'title[0][value]' => 'pending revision',
    'path[0][alias]' => '',
    'moderation_state[0][state]' => 'draft',
  ], 'Save');
  $this
    ->assertSession()
    ->pageTextNotContains('You can only change the URL alias for the published version of this content.');
}