comparison core/modules/config/tests/src/Functional/ConfigLanguageOverrideWebTest.php @ 0:c75dbcec494b

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