You are here

public function BlockLanguageTest::testLanguageBlockVisibilityLanguageDelete in Drupal 9

Same name and namespace in other branches
  1. 8 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 93

Class

BlockLanguageTest
Tests if a block can be configured to be only visible on a particular language.

Namespace

Drupal\Tests\block\Functional

Code

public function testLanguageBlockVisibilityLanguageDelete() {

  // 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
    ->assertTrue(empty($visibility['language']['langcodes']['fr']), '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');
  $elements = $this
    ->xpath('//details[@id="edit-visibility-language"]');
  $this
    ->assertTrue(empty($elements));
}