class BlockLanguageCacheTest
Same name and namespace in other branches
- 11.x core/modules/block/tests/src/Functional/BlockLanguageCacheTest.php \Drupal\Tests\block\Functional\BlockLanguageCacheTest
- 10 core/modules/block/tests/src/Functional/BlockLanguageCacheTest.php \Drupal\Tests\block\Functional\BlockLanguageCacheTest
- 8.9.x core/modules/block/tests/src/Functional/BlockLanguageCacheTest.php \Drupal\Tests\block\Functional\BlockLanguageCacheTest
Tests display of menu blocks with multiple languages.
@group block
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\block\Functional\BlockLanguageCacheTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of BlockLanguageCacheTest
File
-
core/
modules/ block/ tests/ src/ Functional/ BlockLanguageCacheTest.php, line 13
Namespace
Drupal\Tests\block\FunctionalView source
class BlockLanguageCacheTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'block',
'language',
'menu_ui',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* List of langcodes.
*
* @var array
*/
protected $langcodes = [];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create test languages.
$this->langcodes = [
ConfigurableLanguage::load('en'),
];
for ($i = 1; $i < 3; ++$i) {
$language = ConfigurableLanguage::create([
'id' => 'l' . $i,
'label' => $this->randomString(),
]);
$language->save();
$this->langcodes[$i] = $language;
}
}
/**
* Creates a block in a language, check blocks page in all languages.
*/
public function testBlockLinks() {
// 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.