Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\config\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Language\LanguageInterface;
|
Chris@0
|
6 use Drupal\language\Entity\ConfigurableLanguage;
|
Chris@0
|
7 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Tests language overrides applied through the website.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @group config
|
Chris@0
|
13 */
|
Chris@0
|
14 class ConfigLanguageOverrideWebTest extends BrowserTestBase {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * Modules to install.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @var array
|
Chris@0
|
20 */
|
Chris@0
|
21 public static $modules = [
|
Chris@0
|
22 'block',
|
Chris@0
|
23 'language',
|
Chris@17
|
24 'system',
|
Chris@0
|
25 ];
|
Chris@0
|
26
|
Chris@0
|
27 /**
|
Chris@0
|
28 * {@inheritdoc}
|
Chris@0
|
29 */
|
Chris@0
|
30 protected function setUp() {
|
Chris@0
|
31 parent::setUp();
|
Chris@0
|
32 }
|
Chris@0
|
33
|
Chris@0
|
34 /**
|
Chris@0
|
35 * Tests translating the site name.
|
Chris@0
|
36 */
|
Chris@0
|
37 public function testSiteNameTranslation() {
|
Chris@0
|
38 $adminUser = $this->drupalCreateUser(['administer site configuration', 'administer languages']);
|
Chris@0
|
39 $this->drupalLogin($adminUser);
|
Chris@0
|
40
|
Chris@0
|
41 // Add a custom language.
|
Chris@0
|
42 $langcode = 'xx';
|
Chris@0
|
43 $name = $this->randomMachineName(16);
|
Chris@0
|
44 $edit = [
|
Chris@0
|
45 'predefined_langcode' => 'custom',
|
Chris@0
|
46 'langcode' => $langcode,
|
Chris@0
|
47 'label' => $name,
|
Chris@0
|
48 'direction' => LanguageInterface::DIRECTION_LTR,
|
Chris@0
|
49 ];
|
Chris@0
|
50 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
Chris@0
|
51 \Drupal::languageManager()
|
Chris@0
|
52 ->getLanguageConfigOverride($langcode, 'system.site')
|
Chris@0
|
53 ->set('name', 'XX site name')
|
Chris@0
|
54 ->save();
|
Chris@0
|
55
|
Chris@0
|
56 // Place branding block with site name into header region.
|
Chris@0
|
57 $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
|
Chris@0
|
58
|
Chris@0
|
59 $this->drupalLogout();
|
Chris@0
|
60
|
Chris@0
|
61 // The home page in English should not have the override.
|
Chris@0
|
62 $this->drupalGet('');
|
Chris@0
|
63 $this->assertNoText('XX site name');
|
Chris@0
|
64
|
Chris@0
|
65 // During path resolution the system.site configuration object is used to
|
Chris@0
|
66 // determine the front page. This occurs before language negotiation causing
|
Chris@0
|
67 // the configuration factory to cache an object without the correct
|
Chris@0
|
68 // overrides. We are testing that the configuration factory is
|
Chris@0
|
69 // re-initialised after language negotiation. Ensure that it applies when
|
Chris@0
|
70 // we access the XX front page.
|
Chris@0
|
71 // @see \Drupal\Core\PathProcessor::processInbound()
|
Chris@0
|
72 $this->drupalGet('xx');
|
Chris@0
|
73 $this->assertText('XX site name');
|
Chris@0
|
74
|
Chris@0
|
75 // Set the xx language to be the default language and delete the English
|
Chris@0
|
76 // language so the site is no longer multilingual and confirm configuration
|
Chris@0
|
77 // overrides still work.
|
Chris@0
|
78 $language_manager = \Drupal::languageManager()->reset();
|
Chris@0
|
79 $this->assertTrue($language_manager->isMultilingual(), 'The test site is multilingual.');
|
Chris@0
|
80 $this->config('system.site')->set('default_langcode', 'xx')->save();
|
Chris@0
|
81
|
Chris@0
|
82 ConfigurableLanguage::load('en')->delete();
|
Chris@0
|
83 $this->assertFalse($language_manager->isMultilingual(), 'The test site is monolingual.');
|
Chris@0
|
84
|
Chris@0
|
85 $this->drupalGet('xx');
|
Chris@0
|
86 $this->assertText('XX site name');
|
Chris@0
|
87
|
Chris@0
|
88 }
|
Chris@0
|
89
|
Chris@0
|
90 }
|