You are here

function PathAliasTest::testDuplicateNodeAlias in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/path/src/Tests/PathAliasTest.php \Drupal\path\Tests\PathAliasTest::testDuplicateNodeAlias()

Tests that duplicate aliases fail validation.

File

core/modules/path/src/Tests/PathAliasTest.php, line 338
Contains \Drupal\path\Tests\PathAliasTest.

Class

PathAliasTest
Add, edit, delete, and change alias and verify its consistency in the database.

Namespace

Drupal\path\Tests

Code

function testDuplicateNodeAlias() {

  // Create one node with a random alias.
  $node_one = $this
    ->drupalCreateNode();
  $edit = array();
  $edit['path[0][alias]'] = '/' . $this
    ->randomMachineName();
  $this
    ->drupalPostForm('node/' . $node_one
    ->id() . '/edit', $edit, t('Save'));

  // Now create another node and try to set the same alias.
  $node_two = $this
    ->drupalCreateNode();
  $this
    ->drupalPostForm('node/' . $node_two
    ->id() . '/edit', $edit, t('Save'));
  $this
    ->assertText(t('The alias is already in use.'));
  $this
    ->assertFieldByXPath("//input[@name='path[0][alias]' and contains(@class, 'error')]", $edit['path[0][alias]'], 'Textfield exists and has the error class.');
}