You are here

public function BlockLanguageTest::testLanguageBlockVisibilityLanguageDelete in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/block/src/Tests/BlockLanguageTest.php \Drupal\block\Tests\BlockLanguageTest::testLanguageBlockVisibilityLanguageDelete()

Tests if the visibility settings are removed if the language is deleted.

File

core/modules/block/src/Tests/BlockLanguageTest.php, line 85
Contains \Drupal\block\Tests\BlockLanguageTest.

Class

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

Namespace

Drupal\block\Tests

Code

public function testLanguageBlockVisibilityLanguageDelete() {

  // Enable a standard block and set the visibility setting for one language.
  $edit = array(
    'visibility' => array(
      'language' => array(
        'langcodes' => array(
          '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
    ->assertEqual('fr', $visibility['language']['langcodes']['fr'], 'Language is set in the block configuration.');

  // Delete the language.
  $this
    ->drupalPostForm('admin/config/regional/language/delete/fr', array(), t('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));
}