3 namespace Drupal\redirect\Tests;
4 use Drupal\language\Entity\ConfigurableLanguage;
7 * UI tests for redirect module with language and content translation modules.
9 * This runs the exact same tests as RedirectUITest, but with both the language
10 * and content translation modules enabled.
14 class RedirectUILanguageTest extends RedirectUITest {
19 public static $modules = ['redirect', 'node', 'path', 'dblog', 'views', 'taxonomy', 'language', 'content_translation'];
24 protected function setUp() {
27 $language = ConfigurableLanguage::createFromLangcode('de');
29 $language = ConfigurableLanguage::createFromLangcode('es');
34 * Test multilingual scenarios.
36 public function testLanguageSpecificRedirects() {
37 $this->drupalLogin($this->adminUser);
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 -');
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',
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',
64 // Check redirect for english.
65 $this->assertRedirect('langpath', '/user', 'HTTP/1.1 301 Moved Permanently');
67 // Check redirect for germany.
68 $this->assertRedirect('de/langpath', '/de', 'HTTP/1.1 301 Moved Permanently');
70 // Check no redirect for spanish.
71 $this->assertRedirect('es/langpath', NULL, 'HTTP/1.1 404 Not Found');
75 * Test non-language specific redirect.
77 public function testUndefinedLangugageRedirects() {
78 $this->drupalLogin($this->adminUser);
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',
87 // Check redirect for english.
88 $this->assertRedirect('langpath', '/user', 'HTTP/1.1 301 Moved Permanently');
90 // Check redirect for spanish.
91 $this->assertRedirect('es/langpath', '/es/user', 'HTTP/1.1 301 Moved Permanently');
95 * Test editing the redirect language.
97 public function testEditRedirectLanguage() {
98 $this->drupalLogin($this->adminUser);
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',
107 // Check redirect for english.
108 $this->assertRedirect('langpath', '/user', 'HTTP/1.1 301 Moved Permanently');
110 // Check that redirect for Germany is not working.
111 $this->assertRedirect('de/langpath', NULL, 'HTTP/1.1 404 Not Found');
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'));
118 // Check redirect for english is NOT working now.
119 $this->assertRedirect('langpath', NULL, 'HTTP/1.1 404 Not Found');
121 // Check that redirect for Germany is now working.
122 $this->assertRedirect('de/langpath', '/de/user', 'HTTP/1.1 301 Moved Permanently');