function BlockLanguageTest::testLanguageBlockVisibilityLanguageDelete
Same name in other branches
- 9 core/modules/block/tests/src/Functional/BlockLanguageTest.php \Drupal\Tests\block\Functional\BlockLanguageTest::testLanguageBlockVisibilityLanguageDelete()
- 8.9.x core/modules/block/tests/src/Functional/BlockLanguageTest.php \Drupal\Tests\block\Functional\BlockLanguageTest::testLanguageBlockVisibilityLanguageDelete()
- 11.x core/modules/block/tests/src/Functional/BlockLanguageTest.php \Drupal\Tests\block\Functional\BlockLanguageTest::testLanguageBlockVisibilityLanguageDelete()
Tests if the visibility settings are removed if the language is deleted.
File
-
core/
modules/ block/ tests/ src/ Functional/ BlockLanguageTest.php, line 109
Class
- BlockLanguageTest
- Tests per-language block configuration.
Namespace
Drupal\Tests\block\FunctionalCode
public function testLanguageBlockVisibilityLanguageDelete() : void {
// Enable a standard block and set the visibility setting for one language.
$edit = [
'visibility' => [
'language' => [
'langcodes' => [
'fr' => 'fr',
],
'context_mapping' => [
'language' => '@language.current_language_context:language_interface',
],
],
],
];
$block = $this->drupalPlaceBlock('system_powered_by_block', $edit);
// Check that we have the language in config after saving the setting.
$visibility = $block->getVisibility();
$this->assertEquals('fr', $visibility['language']['langcodes']['fr'], 'Language is set in the block configuration.');
// Delete the language.
$this->drupalGet('admin/config/regional/language/delete/fr');
$this->submitForm([], 'Delete');
// Check that the language is no longer stored in the configuration after
// it is deleted.
$block = Block::load($block->id());
$visibility = $block->getVisibility();
$this->assertArrayNotHasKey('language', $visibility, 'Language is no longer not set in the block configuration after deleting the block.');
// Ensure that the block visibility for language is gone from the UI.
$this->drupalGet('admin/structure/block');
$this->clickLink('Configure');
$this->assertSession()
->elementNotExists('xpath', '//details[@id="edit-visibility-language"]');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.