RouteCachingNonPathLanguageNegotiationTest.php in Drupal 8
File
core/tests/Drupal/FunctionalTests/Routing/RouteCachingNonPathLanguageNegotiationTest.php
View source
<?php
namespace Drupal\FunctionalTests\Routing;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\Traits\Core\PathAliasTestTrait;
class RouteCachingNonPathLanguageNegotiationTest extends BrowserTestBase {
use PathAliasTestTrait;
public static $modules = [
'language',
'block',
];
protected $defaultTheme = 'stark';
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer blocks',
'administer languages',
'access administration pages',
]);
$this
->drupalLogin($this->adminUser);
ConfigurableLanguage::createFromLangcode('fr')
->save();
$edit = [
'language_interface[enabled][language-url]' => FALSE,
'language_interface[enabled][language-session]' => TRUE,
];
$this
->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
$this
->config('language.types')
->set('negotiation.language_url.enabled', [
'language-session' => 0,
])
->save();
$this
->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [
'id' => 'test_language_block',
]);
}
public function testAliases() {
$this
->drupalGet('');
$this
->createPathAlias('/user/' . $this->adminUser
->id(), '/user-page', 'en');
$this
->clickLink('French');
$this
->drupalGet('user-page');
$this
->assertSession()
->statusCodeEquals(404);
$this
->clickLink('English');
$this
->drupalGet('user-page');
$this
->assertSession()
->statusCodeEquals(200);
$this
->resetAll();
$this
->drupalGet('user-page');
$this
->assertSession()
->statusCodeEquals(200);
$this
->clickLink('French');
$this
->drupalGet('user-page');
$this
->assertSession()
->statusCodeEquals(404);
}
}