public function BlockLanguageTest::testLanguageBlockVisibility in Drupal 8
Same name and namespace in other branches
- 9 core/modules/block/tests/src/Functional/BlockLanguageTest.php \Drupal\Tests\block\Functional\BlockLanguageTest::testLanguageBlockVisibility()
Tests the visibility settings for the blocks based on language.
File
- core/
modules/ block/ tests/ src/ Functional/ BlockLanguageTest.php, line 53
Class
- BlockLanguageTest
- Tests if a block can be configured to be only visible on a particular language.
Namespace
Drupal\Tests\block\FunctionalCode
public function testLanguageBlockVisibility() {
// Check if the visibility setting is available.
$default_theme = $this
->config('system.theme')
->get('default');
$this
->drupalGet('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme);
$this
->assertField('visibility[language][langcodes][en]', 'Language visibility field is visible.');
$this
->assertNoField('visibility[language][context_mapping][language]', 'Language type field is not visible.');
// Enable a standard block and set the visibility setting for one language.
$edit = [
'visibility[language][langcodes][en]' => TRUE,
'id' => strtolower($this
->randomMachineName(8)),
'region' => 'sidebar_first',
];
$this
->drupalPostForm('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block'));
// Change the default language.
$edit = [
'site_default_language' => 'fr',
];
$this
->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
// Check that a page has a block.
$this
->drupalGet('en');
$this
->assertText('Powered by Drupal', 'The body of the custom block appears on the page.');
// Check that a page doesn't has a block for the current language anymore.
$this
->drupalGet('fr');
$this
->assertNoText('Powered by Drupal', 'The body of the custom block does not appear on the page.');
}