You are here

public function RedirectUILanguageTest::testLanguageSpecificRedirects in Redirect 8

Test multilingual scenarios.

File

tests/src/Functional/RedirectUILanguageTest.php, line 37

Class

RedirectUILanguageTest
UI tests for redirect module with language and content translation modules.

Namespace

Drupal\Tests\redirect\Functional

Code

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 -');

  // Add a redirect for english.
  $this
    ->drupalPostForm('admin/config/search/redirect/add', [
    'redirect_source[0][path]' => 'langpath',
    'redirect_redirect[0][uri]' => '/user',
    'language[0][value]' => 'en',
  ], t('Save'));

  // Add a redirect for germany.
  $this
    ->drupalPostForm('admin/config/search/redirect/add', [
    'redirect_source[0][path]' => 'langpath',
    'redirect_redirect[0][uri]' => '<front>',
    'language[0][value]' => 'de',
  ], t('Save'));

  // Check redirect for english.
  $this
    ->assertRedirect('langpath', '/user', 301);

  // Check redirect for germany.
  $this
    ->assertRedirect('de/langpath', '/de', 301);

  // Check no redirect for spanish.
  $this
    ->assertRedirect('es/langpath', NULL, 404);
}