Interim commit.
[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     // Add a redirect for english.
40     $this->drupalPostForm('admin/config/search/redirect/add', array(
41       'redirect_source[0][path]' => 'langpath',
42       'redirect_redirect[0][uri]' => '/user',
43       'language[0][value]' => 'en',
44     ), t('Save'));
45
46     // Add a redirect for germany.
47     $this->drupalPostForm('admin/config/search/redirect/add', array(
48       'redirect_source[0][path]' => 'langpath',
49       'redirect_redirect[0][uri]' => '<front>',
50       'language[0][value]' => 'de',
51     ), t('Save'));
52
53     // Check redirect for english.
54     $this->assertRedirect('langpath', '/user', 'HTTP/1.1 301 Moved Permanently');
55
56     // Check redirect for germany.
57     $this->assertRedirect('de/langpath', '/de', 'HTTP/1.1 301 Moved Permanently');
58
59     // Check no redirect for spanish.
60     $this->assertRedirect('es/langpath', NULL, 'HTTP/1.1 404 Not Found');
61   }
62
63   /**
64    * Test non-language specific redirect.
65    */
66   public function testUndefinedLangugageRedirects() {
67     $this->drupalLogin($this->adminUser);
68
69     // Add a redirect for english.
70     $this->drupalPostForm('admin/config/search/redirect/add', array(
71       'redirect_source[0][path]' => 'langpath',
72       'redirect_redirect[0][uri]' => '/user',
73       'language[0][value]' => 'und',
74     ), t('Save'));
75
76     // Check redirect for english.
77     $this->assertRedirect('langpath', '/user', 'HTTP/1.1 301 Moved Permanently');
78
79     // Check redirect for spanish.
80     $this->assertRedirect('es/langpath', '/es/user', 'HTTP/1.1 301 Moved Permanently');
81   }
82
83 }