1 path.test PathTestCase::testDuplicateNodeAlias()

Tests that tries to create a duplicate alias are caught by validation.

File

core/modules/path/tests/path.test, line 215
Tests for the Path module.

Class

PathTestCase
Provides a base class for testing the Path module.

Code

function testDuplicateNodeAlias() {
  // Create one node with a random alias.
  $node_one = $this->backdropCreateNode();
  $edit = array();
  $edit['path[auto]'] = FALSE;
  $edit['path[alias]'] = $this->randomName();
  $this->backdropPost('node/' . $node_one->nid . '/edit', $edit, t('Save'));

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