You are here

public function BlockLanguageTest::testLanguageBlockVisibility 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::testLanguageBlockVisibility()

Tests the visibility settings for the blocks based on language.

File

core/modules/block/src/Tests/BlockLanguageTest.php, line 51
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 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 = array(
    '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 = array(
    '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.');
}