ConfigLanguageOverrideWebTest.php in Drupal 8
File
core/modules/config/tests/src/Functional/ConfigLanguageOverrideWebTest.php
View source
<?php
namespace Drupal\Tests\config\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
class ConfigLanguageOverrideWebTest extends BrowserTestBase {
public static $modules = [
'block',
'language',
'system',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
}
public function testSiteNameTranslation() {
$adminUser = $this
->drupalCreateUser([
'administer site configuration',
'administer languages',
]);
$this
->drupalLogin($adminUser);
$langcode = 'xx';
$name = $this
->randomMachineName(16);
$edit = [
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
];
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
\Drupal::languageManager()
->getLanguageConfigOverride($langcode, 'system.site')
->set('name', 'XX site name')
->save();
$this
->drupalPlaceBlock('system_branding_block', [
'region' => 'header',
]);
$this
->drupalLogout();
$this
->drupalGet('');
$this
->assertNoText('XX site name');
$this
->drupalGet('xx');
$this
->assertText('XX site name');
$language_manager = \Drupal::languageManager()
->reset();
$this
->assertTrue($language_manager
->isMultilingual(), 'The test site is multilingual.');
$this
->config('system.site')
->set('default_langcode', 'xx')
->save();
ConfigurableLanguage::load('en')
->delete();
$this
->assertFalse($language_manager
->isMultilingual(), 'The test site is monolingual.');
$this
->drupalGet('xx');
$this
->assertText('XX site name');
}
}