function BlockLanguageTest::testLanguageBlockVisibility

Same name in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockLanguageTest.php \Drupal\Tests\block\Functional\BlockLanguageTest::testLanguageBlockVisibility()
  2. 8.9.x core/modules/block/tests/src/Functional/BlockLanguageTest.php \Drupal\Tests\block\Functional\BlockLanguageTest::testLanguageBlockVisibility()
  3. 10 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 70

Class

BlockLanguageTest
Tests per-language block configuration.

Namespace

Drupal\Tests\block\Functional

Code

public function testLanguageBlockVisibility() : void {
    // 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);
    // Ensure that the language visibility field is visible without a type
    // setting.
    $this->assertSession()
        ->fieldExists('visibility[language][langcodes][en]');
    $this->assertSession()
        ->fieldNotExists('visibility[language][context_mapping][language]');
    // Enable a standard block and set the visibility setting for one language.
    $edit = [
        'visibility[language][langcodes][en]' => TRUE,
        'id' => $this->randomMachineName(8),
        'region' => 'sidebar_first',
    ];
    $this->drupalGet('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme);
    $this->submitForm($edit, 'Save block');
    // Change the default language.
    $edit = [
        'site_default_language' => 'fr',
    ];
    $this->drupalGet('admin/config/regional/language');
    $this->submitForm($edit, 'Save configuration');
    // Check that a page has a block.
    $this->drupalGet('en');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains('Powered by Drupal');
    // Check that a page doesn't has a block for the current language anymore.
    $this->drupalGet('fr');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextNotContains('Powered by Drupal');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.