PathLanguageUiTest.php in Drupal 9
File
core/modules/path/tests/src/Functional/PathLanguageUiTest.php
View source
<?php
namespace Drupal\Tests\path\Functional;
use Drupal\Core\Language\LanguageInterface;
class PathLanguageUiTest extends PathTestBase {
protected static $modules = [
'path',
'locale',
'locale_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$web_user = $this
->drupalCreateUser([
'edit any page content',
'create page content',
'administer url aliases',
'create url aliases',
'administer languages',
'access administration pages',
]);
$this
->drupalLogin($web_user);
$edit = [];
$edit['predefined_langcode'] = 'fr';
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add language');
$edit = [
'language_interface[enabled][language-url]' => 1,
];
$this
->drupalGet('admin/config/regional/language/detection');
$this
->submitForm($edit, 'Save settings');
}
public function testLanguageNeutralUrl() {
$name = $this
->randomMachineName(8);
$edit = [];
$edit['path[0][value]'] = '/admin/config/search/path';
$edit['alias[0][value]'] = '/' . $name;
$this
->drupalGet('admin/config/search/path/add');
$this
->submitForm($edit, 'Save');
$this
->drupalGet($name);
$this
->assertSession()
->pageTextContains('Filter aliases');
}
public function testDefaultLanguageUrl() {
$name = $this
->randomMachineName(8);
$edit = [];
$edit['path[0][value]'] = '/admin/config/search/path';
$edit['alias[0][value]'] = '/' . $name;
$edit['langcode[0][value]'] = 'en';
$this
->drupalGet('admin/config/search/path/add');
$this
->submitForm($edit, 'Save');
$this
->drupalGet($name);
$this
->assertSession()
->pageTextContains('Filter aliases');
}
public function testNonDefaultUrl() {
$name = $this
->randomMachineName(8);
$edit = [];
$edit['path[0][value]'] = '/admin/config/search/path';
$edit['alias[0][value]'] = '/' . $name;
$edit['langcode[0][value]'] = 'fr';
$this
->drupalGet('admin/config/search/path/add');
$this
->submitForm($edit, 'Save');
$this
->drupalGet('fr/' . $name);
$this
->assertSession()
->pageTextContains('Filter aliases');
}
public function testNotSpecifiedNode() {
$node = $this
->drupalCreateNode();
$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');
$node = $this
->drupalCreateNode();
$this
->drupalget($node
->toUrl('edit-form'));
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextNotContains('The alias is already in use.');
}
}