You are here

public function PathautoNodeWebTest::testCustomAliasAfterAutomaticAlias in Pathauto 8

Tests that nodes with an automatic alias can get a custom alias.

File

tests/src/Functional/PathautoNodeWebTest.php, line 301

Class

PathautoNodeWebTest
Tests pathauto node UI integration.

Namespace

Drupal\Tests\pathauto\Functional

Code

public function testCustomAliasAfterAutomaticAlias() {

  // Create a pattern.
  $this
    ->createPattern('node', '/content/[node:title]');

  // Create a node with an automatic alias.
  $edit = [
    'title[0][value]' => 'Sample article',
  ];
  $this
    ->drupalPostForm('node/add/article', $edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('article Sample article has been created.');

  // Ensure that the automatic alias got created.
  $this
    ->assertAliasExists([
    'alias' => '/content/sample-article',
  ]);
  $this
    ->drupalGet('/content/sample-article');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Now edit the node, set a custom alias.
  $edit = [
    'path[0][pathauto]' => 0,
    'path[0][alias]' => '/sample-pattern-for-article',
  ];
  $this
    ->drupalPostForm('node/1/edit', $edit, 'Save');

  // Assert that the new alias exists and the old one does not.
  $this
    ->assertAliasExists([
    'alias' => '/sample-pattern-for-article',
  ]);
  $this
    ->assertNoAliasExists([
    'alias' => '/content/sample-article',
  ]);
  $this
    ->drupalGet('sample-pattern-for-article');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}