Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / redirect / src / Tests / RedirectUILanguageTest.php
1 <?php
2
3 namespace Drupal\redirect\Tests;
4 use Drupal\language\Entity\ConfigurableLanguage;
5
6 /**
7  * UI tests for redirect module with language and content translation modules.
8  *
9  * This runs the exact same tests as RedirectUITest, but with both the language
10  * and content translation modules enabled.
11  *
12  * @group redirect
13  */
14 class RedirectUILanguageTest extends RedirectUITest {
15
16   /**
17    * {@inheritdoc}
18    */
19   public static $modules = ['redirect', 'node', 'path', 'dblog', 'views', 'taxonomy', 'language', 'content_translation'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26
27     $language = ConfigurableLanguage::createFromLangcode('de');
28     $language->save();
29     $language = ConfigurableLanguage::createFromLangcode('es');
30     $language->save();
31   }
32
33   /**
34    * Test multilingual scenarios.
35    */
36   public function testLanguageSpecificRedirects() {
37     $this->drupalLogin($this->adminUser);
38
39     $this->drupalGet('admin/config/search/redirect/add');
40     $this->assertOption('edit-language-0-value', 'en');
41     $this->assertOption('edit-language-0-value', 'de');
42     $this->assertOption('edit-language-0-value', 'es');
43     $this->assertOption('edit-language-0-value', 'und');
44     $this->assertNoOption('edit-language-0-value', 'zxx');
45     $this->assertOptionByText('edit-language-0-value', 'English');
46     $this->assertOptionByText('edit-language-0-value', 'German');
47     $this->assertOptionByText('edit-language-0-value', 'Spanish');
48     $this->assertOptionByText('edit-language-0-value', '- All languages -');
49
50     // Add a redirect for english.
51     $this->drupalPostForm('admin/config/search/redirect/add', array(
52       'redirect_source[0][path]' => 'langpath',
53       'redirect_redirect[0][uri]' => '/user',
54       'language[0][value]' => 'en',
55     ), t('Save'));
56
57     // Add a redirect for germany.
58     $this->drupalPostForm('admin/config/search/redirect/add', array(
59       'redirect_source[0][path]' => 'langpath',
60       'redirect_redirect[0][uri]' => '<front>',
61       'language[0][value]' => 'de',
62     ), t('Save'));
63
64     // Check redirect for english.
65     $this->assertRedirect('langpath', '/user', 'HTTP/1.1 301 Moved Permanently');
66
67     // Check redirect for germany.
68     $this->assertRedirect('de/langpath', '/de', 'HTTP/1.1 301 Moved Permanently');
69
70     // Check no redirect for spanish.
71     $this->assertRedirect('es/langpath', NULL, 'HTTP/1.1 404 Not Found');
72   }
73
74   /**
75    * Test non-language specific redirect.
76    */
77   public function testUndefinedLangugageRedirects() {
78     $this->drupalLogin($this->adminUser);
79
80     // Add a redirect for english.
81     $this->drupalPostForm('admin/config/search/redirect/add', array(
82       'redirect_source[0][path]' => 'langpath',
83       'redirect_redirect[0][uri]' => '/user',
84       'language[0][value]' => 'und',
85     ), t('Save'));
86
87     // Check redirect for english.
88     $this->assertRedirect('langpath', '/user', 'HTTP/1.1 301 Moved Permanently');
89
90     // Check redirect for spanish.
91     $this->assertRedirect('es/langpath', '/es/user', 'HTTP/1.1 301 Moved Permanently');
92   }
93
94   /**
95    * Test editing the redirect language.
96    */
97   public function testEditRedirectLanguage() {
98     $this->drupalLogin($this->adminUser);
99
100     // Add a redirect for english.
101     $this->drupalPostForm('admin/config/search/redirect/add', array(
102       'redirect_source[0][path]' => 'langpath',
103       'redirect_redirect[0][uri]' => '/user',
104       'language[0][value]' => 'en',
105     ), t('Save'));
106
107     // Check redirect for english.
108     $this->assertRedirect('langpath', '/user', 'HTTP/1.1 301 Moved Permanently');
109
110     // Check that redirect for Germany is not working.
111     $this->assertRedirect('de/langpath', NULL, 'HTTP/1.1 404 Not Found');
112
113     // Edit the redirect and change the language.
114     $this->drupalGet('admin/config/search/redirect');
115     $this->clickLink('Edit');
116     $this->drupalPostForm(NULL, ['language[0][value]' => 'de'], t('Save'));
117
118     // Check redirect for english is NOT working now.
119     $this->assertRedirect('langpath', NULL, 'HTTP/1.1 404 Not Found');
120
121     // Check that redirect for Germany is now working.
122     $this->assertRedirect('de/langpath', '/de/user', 'HTTP/1.1 301 Moved Permanently');
123   }
124
125 }