3 namespace Drupal\Tests\path\Functional;
5 use Drupal\Core\Language\LanguageInterface;
8 * Confirm that the Path module user interface works with languages.
12 class PathLanguageUiTest extends PathTestBase {
19 public static $modules = ['path', 'locale', 'locale_test'];
21 protected function setUp() {
24 // Create and log in user.
25 $web_user = $this->drupalCreateUser(['edit any page content', 'create page content', 'administer url aliases', 'create url aliases', 'administer languages', 'access administration pages']);
26 $this->drupalLogin($web_user);
28 // Enable French language.
30 $edit['predefined_langcode'] = 'fr';
32 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
34 // Enable URL language detection and selection.
35 $edit = ['language_interface[enabled][language-url]' => 1];
36 $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
40 * Tests that a language-neutral URL alias works.
42 public function testLanguageNeutralUrl() {
43 $name = $this->randomMachineName(8);
45 $edit['source'] = '/admin/config/search/path';
46 $edit['alias'] = '/' . $name;
47 $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
49 $this->drupalGet($name);
50 $this->assertText(t('Filter aliases'), 'Language-neutral URL alias works');
54 * Tests that a default language URL alias works.
56 public function testDefaultLanguageUrl() {
57 $name = $this->randomMachineName(8);
59 $edit['source'] = '/admin/config/search/path';
60 $edit['alias'] = '/' . $name;
61 $edit['langcode'] = 'en';
62 $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
64 $this->drupalGet($name);
65 $this->assertText(t('Filter aliases'), 'English URL alias works');
69 * Tests that a non-default language URL alias works.
71 public function testNonDefaultUrl() {
72 $name = $this->randomMachineName(8);
74 $edit['source'] = '/admin/config/search/path';
75 $edit['alias'] = '/' . $name;
76 $edit['langcode'] = 'fr';
77 $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
79 $this->drupalGet('fr/' . $name);
80 $this->assertText(t('Filter aliases'), 'Foreign URL alias works');
84 * Test that language unspecific aliases are shown and saved in the node form.
86 public function testNotSpecifiedNode() {
88 $node = $this->drupalCreateNode();
90 // Create a language-unspecific alias in the admin UI, ensure that is
91 // displayed and the langcode is not changed when saving.
93 'source' => '/node/' . $node->id(),
94 'alias' => '/' . $this->getRandomGenerator()->word(8),
95 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
97 $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
99 $this->drupalGet($node->toUrl('edit-form'));
100 $this->assertSession()->fieldValueEquals('path[0][alias]', $edit['alias']);
101 $this->drupalPostForm(NULL, [], t('Save'));
103 $this->drupalGet('admin/config/search/path');
104 $this->assertSession()->pageTextContains('None');
105 $this->assertSession()->pageTextNotContains('English');
107 // Create another node, with no alias, to ensure non-language specific
108 // aliases are loaded correctly.
109 $node = $this->drupalCreateNode();
110 $this->drupalget($node->toUrl('edit-form'));
111 $this->drupalPostForm(NULL, [], t('Save'));
112 $this->assertSession()->pageTextNotContains(t('The alias is already in use.'));