function BlockLanguageCacheTest::testBlockLinks

Same name in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockLanguageCacheTest.php \Drupal\Tests\block\Functional\BlockLanguageCacheTest::testBlockLinks()
  2. 8.9.x core/modules/block/tests/src/Functional/BlockLanguageCacheTest.php \Drupal\Tests\block\Functional\BlockLanguageCacheTest::testBlockLinks()
  3. 10 core/modules/block/tests/src/Functional/BlockLanguageCacheTest.php \Drupal\Tests\block\Functional\BlockLanguageCacheTest::testBlockLinks()

Creates a block in a language, check blocks page in all languages.

File

core/modules/block/tests/src/Functional/BlockLanguageCacheTest.php, line 55

Class

BlockLanguageCacheTest
Tests display of menu blocks with multiple languages.

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockLinks() : void {
    // Create admin user to be able to access block admin.
    $admin_user = $this->drupalCreateUser([
        'administer blocks',
        'access administration pages',
        'administer menu',
    ]);
    $this->drupalLogin($admin_user);
    // Create the block cache for all languages.
    foreach ($this->langcodes as $langcode) {
        $this->drupalGet('admin/structure/block', [
            'language' => $langcode,
        ]);
        $this->clickLink('Place block');
    }
    // Create a menu in the default language.
    $edit['label'] = $this->randomMachineName();
    $edit['id'] = mb_strtolower($edit['label']);
    $this->drupalGet('admin/structure/menu/add');
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->pageTextContains('Menu ' . $edit['label'] . ' has been added.');
    // Check that the block is listed for all languages.
    foreach ($this->langcodes as $langcode) {
        $this->drupalGet('admin/structure/block', [
            'language' => $langcode,
        ]);
        $this->clickLink('Place block');
        $this->assertSession()
            ->pageTextContains($edit['label']);
    }
}

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