Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / path / tests / src / Functional / PathLanguageUiTest.php
1 <?php
2
3 namespace Drupal\Tests\path\Functional;
4
5 use Drupal\Core\Language\LanguageInterface;
6
7 /**
8  * Confirm that the Path module user interface works with languages.
9  *
10  * @group path
11  */
12 class PathLanguageUiTest extends PathTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['path', 'locale', 'locale_test'];
20
21   protected function setUp() {
22     parent::setUp();
23
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);
27
28     // Enable French language.
29     $edit = [];
30     $edit['predefined_langcode'] = 'fr';
31
32     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
33
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'));
37   }
38
39   /**
40    * Tests that a language-neutral URL alias works.
41    */
42   public function testLanguageNeutralUrl() {
43     $name = $this->randomMachineName(8);
44     $edit = [];
45     $edit['source'] = '/admin/config/search/path';
46     $edit['alias'] = '/' . $name;
47     $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
48
49     $this->drupalGet($name);
50     $this->assertText(t('Filter aliases'), 'Language-neutral URL alias works');
51   }
52
53   /**
54    * Tests that a default language URL alias works.
55    */
56   public function testDefaultLanguageUrl() {
57     $name = $this->randomMachineName(8);
58     $edit = [];
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'));
63
64     $this->drupalGet($name);
65     $this->assertText(t('Filter aliases'), 'English URL alias works');
66   }
67
68   /**
69    * Tests that a non-default language URL alias works.
70    */
71   public function testNonDefaultUrl() {
72     $name = $this->randomMachineName(8);
73     $edit = [];
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'));
78
79     $this->drupalGet('fr/' . $name);
80     $this->assertText(t('Filter aliases'), 'Foreign URL alias works');
81   }
82
83   /**
84    * Test that language unspecific aliases are shown and saved in the node form.
85    */
86   public function testNotSpecifiedNode() {
87     // Create test node.
88     $node = $this->drupalCreateNode();
89
90     // Create a language-unspecific alias in the admin UI, ensure that is
91     // displayed and the langcode is not changed when saving.
92     $edit = [
93       'source' => '/node/' . $node->id(),
94       'alias' => '/' . $this->getRandomGenerator()->word(8),
95       'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
96     ];
97     $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
98
99     $this->drupalGet($node->toUrl('edit-form'));
100     $this->assertSession()->fieldValueEquals('path[0][alias]', $edit['alias']);
101     $this->drupalPostForm(NULL, [], t('Save'));
102
103     $this->drupalGet('admin/config/search/path');
104     $this->assertSession()->pageTextContains('None');
105     $this->assertSession()->pageTextNotContains('English');
106
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.'));
113   }
114
115 }