class ConfigLanguageOverrideWebTest
Same name and namespace in other branches
- 11.x core/modules/config/tests/src/Functional/ConfigLanguageOverrideWebTest.php \Drupal\Tests\config\Functional\ConfigLanguageOverrideWebTest
- 10 core/modules/config/tests/src/Functional/ConfigLanguageOverrideWebTest.php \Drupal\Tests\config\Functional\ConfigLanguageOverrideWebTest
- 8.9.x core/modules/config/tests/src/Functional/ConfigLanguageOverrideWebTest.php \Drupal\Tests\config\Functional\ConfigLanguageOverrideWebTest
Tests language overrides applied through the website.
@group config
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\config\Functional\ConfigLanguageOverrideWebTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ConfigLanguageOverrideWebTest
File
-
core/
modules/ config/ tests/ src/ Functional/ ConfigLanguageOverrideWebTest.php, line 14
Namespace
Drupal\Tests\config\FunctionalView source
class ConfigLanguageOverrideWebTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'block',
'language',
'system',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
}
/**
* Tests translating the site name.
*/
public function testSiteNameTranslation() {
$adminUser = $this->drupalCreateUser([
'administer site configuration',
'administer languages',
]);
$this->drupalLogin($adminUser);
// Add a custom language.
$langcode = 'xx';
$name = $this->randomMachineName(16);
$edit = [
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
];
$this->drupalGet('admin/config/regional/language/add');
$this->submitForm($edit, 'Add custom language');
\Drupal::languageManager()->getLanguageConfigOverride($langcode, 'system.site')
->set('name', 'XX site name')
->save();
// Place branding block with site name into header region.
$this->drupalPlaceBlock('system_branding_block', [
'region' => 'header',
]);
$this->drupalLogout();
// The home page in English should not have the override.
$this->drupalGet('');
$this->assertSession()
->pageTextNotContains('XX site name');
// During path resolution the system.site configuration object is used to
// determine the front page. This occurs before language negotiation causing
// the configuration factory to cache an object without the correct
// overrides. We are testing that the configuration factory is
// re-initialized after language negotiation. Ensure that it applies when
// we access the XX front page.
// @see \Drupal\Core\PathProcessor::processInbound()
$this->drupalGet('xx');
$this->assertSession()
->pageTextContains('XX site name');
// Set the xx language to be the default language and delete the English
// language so the site is no longer multilingual and confirm configuration
// overrides still work.
$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->assertSession()
->pageTextContains('XX site name');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.