3 namespace Drupal\Tests\block\Functional;
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\Tests\BrowserTestBase;
10 * Tests display of menu blocks with multiple languages.
14 class BlockLanguageCacheTest extends BrowserTestBase {
21 public static $modules = ['block', 'language', 'menu_ui'];
28 protected $langcodes = [];
30 protected function setUp() {
33 // Create test languages.
34 $this->langcodes = [ConfigurableLanguage::load('en')];
35 for ($i = 1; $i < 3; ++$i) {
36 $language = ConfigurableLanguage::create([
38 'label' => $this->randomString(),
41 $this->langcodes[$i] = $language;
46 * Creates a block in a language, check blocks page in all languages.
48 public function testBlockLinks() {
49 // Create admin user to be able to access block admin.
50 $admin_user = $this->drupalCreateUser([
52 'access administration pages',
55 $this->drupalLogin($admin_user);
57 // Create the block cache for all languages.
58 foreach ($this->langcodes as $langcode) {
59 $this->drupalGet('admin/structure/block', ['language' => $langcode]);
60 $this->clickLink('Place block');
63 // Create a menu in the default language.
64 $edit['label'] = $this->randomMachineName();
65 $edit['id'] = Unicode::strtolower($edit['label']);
66 $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
67 $this->assertText(t('Menu @label has been added.', ['@label' => $edit['label']]));
69 // Check that the block is listed for all languages.
70 foreach ($this->langcodes as $langcode) {
71 $this->drupalGet('admin/structure/block', ['language' => $langcode]);
72 $this->clickLink('Place block');
73 $this->assertText($edit['label']);