Mercurial > hg > cmmr2012-drupal-site
comparison core/tests/Drupal/FunctionalTests/Routing/RouteCachingNonPathLanguageNegotiationTest.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\FunctionalTests\Routing; | |
4 | |
5 use Drupal\language\Entity\ConfigurableLanguage; | |
6 use Drupal\Core\Language\LanguageInterface; | |
7 use Drupal\Tests\BrowserTestBase; | |
8 | |
9 /** | |
10 * Tests the route cache when the language is not in the path. | |
11 * | |
12 * @group language | |
13 */ | |
14 class RouteCachingNonPathLanguageNegotiationTest extends BrowserTestBase { | |
15 | |
16 /** | |
17 * Modules to enable. | |
18 * | |
19 * @var array | |
20 */ | |
21 public static $modules = ['language', 'block']; | |
22 | |
23 /** | |
24 * The admin user. | |
25 * | |
26 * @var \Drupal\user\UserInterface | |
27 */ | |
28 protected $adminUser; | |
29 | |
30 protected function setUp() { | |
31 parent::setUp(); | |
32 | |
33 // Create and log in user. | |
34 $this->adminUser = $this->drupalCreateUser(['administer blocks', 'administer languages', 'access administration pages']); | |
35 $this->drupalLogin($this->adminUser); | |
36 | |
37 // Add language. | |
38 ConfigurableLanguage::createFromLangcode('fr')->save(); | |
39 | |
40 // Enable session language detection and selection. | |
41 $edit = [ | |
42 'language_interface[enabled][language-url]' => FALSE, | |
43 'language_interface[enabled][language-session]' => TRUE, | |
44 ]; | |
45 $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); | |
46 | |
47 // A more common scenario is domain-based negotiation but that can not be | |
48 // tested. Session negotiation by default is not considered by the URL | |
49 // language type that is used to resolve the alias. Explicitly enable | |
50 // that to be able to test this scenario. | |
51 // @todo Improve in https://www.drupal.org/project/drupal/issues/1125428. | |
52 $this->config('language.types') | |
53 ->set('negotiation.language_url.enabled', ['language-session' => 0]) | |
54 ->save(); | |
55 | |
56 // Enable the language switching block. | |
57 $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [ | |
58 'id' => 'test_language_block', | |
59 ]); | |
60 | |
61 } | |
62 | |
63 /** | |
64 * Tests aliases when the negotiated language is not in the path. | |
65 */ | |
66 public function testAliases() { | |
67 // Switch to French and try to access the now inaccessible block. | |
68 $this->drupalGet(''); | |
69 | |
70 // Create an alias for user/UID just for en, make sure that this is a 404 | |
71 // on the french page exist in english, no matter which language is | |
72 // checked first. Create the alias after visiting frontpage to make sure | |
73 // there is no existing cache entry for this that affects the tests. | |
74 \Drupal::service('path.alias_storage')->save('/user/' . $this->adminUser->id(), '/user-page', 'en'); | |
75 | |
76 $this->clickLink('French'); | |
77 $this->drupalGet('user-page'); | |
78 $this->assertSession()->statusCodeEquals(404); | |
79 | |
80 // Switch to english, make sure it works now. | |
81 $this->clickLink('English'); | |
82 $this->drupalGet('user-page'); | |
83 $this->assertSession()->statusCodeEquals(200); | |
84 | |
85 // Clear cache and repeat the check, this time with english first. | |
86 $this->resetAll(); | |
87 $this->drupalGet('user-page'); | |
88 $this->assertSession()->statusCodeEquals(200); | |
89 | |
90 $this->clickLink('French'); | |
91 $this->drupalGet('user-page'); | |
92 $this->assertSession()->statusCodeEquals(404); | |
93 } | |
94 | |
95 } |