function PathNodeFormTest::testAliasDuplicationPrevention

Tests that duplicate path aliases don't get created.

File

core/modules/path/tests/src/Functional/PathNodeFormTest.php, line 68

Class

PathNodeFormTest
Tests the Path Node form UI.

Namespace

Drupal\Tests\path\Functional

Code

public function testAliasDuplicationPrevention() : void {
  $this->drupalGet('node/add/page');
  $edit['title[0][value]'] = 'path duplication test';
  $edit['path[0][alias]'] = '/my-alias';
  $this->submitForm($edit, 'Save');
  // Test that PathItem::postSave detects if a path alias exists
  // before creating one.
  $aliases = \Drupal::entityTypeManager()->getStorage('path_alias')
    ->loadMultiple();
  static::assertCount(1, $aliases);
  $node = Node::load(1);
  static::assertInstanceOf(NodeInterface::class, $node);
  // This updated title gets set in PathTestMiscHooks::nodePresave. This
  // is a way of ensuring that bit of test code runs.
  static::assertEquals('path duplication test ran', $node->getTitle());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.