function PathLanguageUiTest::testNotSpecifiedNode

Same name and namespace in other branches
  1. 9 core/modules/path/tests/src/Functional/PathLanguageUiTest.php \Drupal\Tests\path\Functional\PathLanguageUiTest::testNotSpecifiedNode()
  2. 8.9.x core/modules/path/tests/src/Functional/PathLanguageUiTest.php \Drupal\Tests\path\Functional\PathLanguageUiTest::testNotSpecifiedNode()
  3. 10 core/modules/path/tests/src/Functional/PathLanguageUiTest.php \Drupal\Tests\path\Functional\PathLanguageUiTest::testNotSpecifiedNode()

Tests language unspecific aliases are shown and saved in the node form.

File

core/modules/path/tests/src/Functional/PathLanguageUiTest.php, line 108

Class

PathLanguageUiTest
Confirm that the Path module user interface works with languages.

Namespace

Drupal\Tests\path\Functional

Code

public function testNotSpecifiedNode() : void {
    // Create test node.
    $node = $this->drupalCreateNode();
    // Create a language-unspecific alias in the admin UI, ensure that is
    // displayed and the langcode is not changed when saving.
    $edit = [
        'path[0][value]' => '/node/' . $node->id(),
        'alias[0][value]' => '/' . $this->getRandomGenerator()
            ->word(8),
        'langcode[0][value]' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ];
    $this->drupalGet('admin/config/search/path/add');
    $this->submitForm($edit, 'Save');
    $this->drupalGet($node->toUrl('edit-form'));
    $this->assertSession()
        ->fieldValueEquals('path[0][alias]', $edit['alias[0][value]']);
    $this->submitForm([], 'Save');
    $this->drupalGet('admin/config/search/path');
    $this->assertSession()
        ->pageTextContains('None');
    $this->assertSession()
        ->pageTextNotContains('English');
    // Create another node, with no alias, to ensure non-language specific
    // aliases are loaded correctly.
    $node = $this->drupalCreateNode();
    $this->drupalGet($node->toUrl('edit-form'));
    $this->submitForm([], 'Save');
    $this->assertSession()
        ->pageTextNotContains('The alias is already in use.');
}

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