View source
<?php
namespace Drupal\Tests\redirect\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
class RedirectUILanguageTest extends RedirectUITest {
public static $modules = [
'redirect',
'node',
'path',
'dblog',
'views',
'taxonomy',
'language',
'content_translation',
];
protected function setUp() {
parent::setUp();
$language = ConfigurableLanguage::createFromLangcode('de');
$language
->save();
$language = ConfigurableLanguage::createFromLangcode('es');
$language
->save();
}
public function testLanguageSpecificRedirects() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/search/redirect/add');
$this
->assertOption('edit-language-0-value', 'en');
$this
->assertOption('edit-language-0-value', 'de');
$this
->assertOption('edit-language-0-value', 'es');
$this
->assertOption('edit-language-0-value', 'und');
$this
->assertNoOption('edit-language-0-value', 'zxx');
$this
->assertOptionByText('edit-language-0-value', 'English');
$this
->assertOptionByText('edit-language-0-value', 'German');
$this
->assertOptionByText('edit-language-0-value', 'Spanish');
$this
->assertOptionByText('edit-language-0-value', '- All languages -');
$this
->drupalPostForm('admin/config/search/redirect/add', [
'redirect_source[0][path]' => 'langpath',
'redirect_redirect[0][uri]' => '/user',
'language[0][value]' => 'en',
], t('Save'));
$this
->drupalPostForm('admin/config/search/redirect/add', [
'redirect_source[0][path]' => 'langpath',
'redirect_redirect[0][uri]' => '<front>',
'language[0][value]' => 'de',
], t('Save'));
$this
->assertRedirect('langpath', '/user', 301);
$this
->assertRedirect('de/langpath', '/de', 301);
$this
->assertRedirect('es/langpath', NULL, 404);
}
public function testUndefinedLangugageRedirects() {
$this
->drupalLogin($this->adminUser);
$this
->drupalPostForm('admin/config/search/redirect/add', [
'redirect_source[0][path]' => 'langpath',
'redirect_redirect[0][uri]' => '/user',
'language[0][value]' => 'und',
], t('Save'));
$this
->assertRedirect('langpath', '/user', 301);
$this
->assertRedirect('es/langpath', '/es/user', 301);
}
public function testEditRedirectLanguage() {
$this
->drupalLogin($this->adminUser);
$this
->drupalPostForm('admin/config/search/redirect/add', [
'redirect_source[0][path]' => 'langpath',
'redirect_redirect[0][uri]' => '/user',
'language[0][value]' => 'en',
], t('Save'));
$this
->assertRedirect('langpath', '/user', 301);
$this
->assertRedirect('de/langpath', NULL, 404);
$this
->drupalGet('admin/config/search/redirect');
$this
->clickLink('Edit');
$this
->drupalPostForm(NULL, [
'language[0][value]' => 'de',
], t('Save'));
$this
->assertRedirect('langpath', NULL, 404);
$this
->assertRedirect('de/langpath', '/de/user', 301);
}
}