3 namespace Drupal\Tests\block\Functional;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests display of menu blocks with multiple languages.
13 class BlockLanguageCacheTest extends BrowserTestBase {
20 public static $modules = ['block', 'language', 'menu_ui'];
27 protected $langcodes = [];
29 protected function setUp() {
32 // Create test languages.
33 $this->langcodes = [ConfigurableLanguage::load('en')];
34 for ($i = 1; $i < 3; ++$i) {
35 $language = ConfigurableLanguage::create([
37 'label' => $this->randomString(),
40 $this->langcodes[$i] = $language;
45 * Creates a block in a language, check blocks page in all languages.
47 public function testBlockLinks() {
48 // Create admin user to be able to access block admin.
49 $admin_user = $this->drupalCreateUser([
51 'access administration pages',
54 $this->drupalLogin($admin_user);
56 // Create the block cache for all languages.
57 foreach ($this->langcodes as $langcode) {
58 $this->drupalGet('admin/structure/block', ['language' => $langcode]);
59 $this->clickLink('Place block');
62 // Create a menu in the default language.
63 $edit['label'] = $this->randomMachineName();
64 $edit['id'] = mb_strtolower($edit['label']);
65 $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
66 $this->assertText(t('Menu @label has been added.', ['@label' => $edit['label']]));
68 // Check that the block is listed for all languages.
69 foreach ($this->langcodes as $langcode) {
70 $this->drupalGet('admin/structure/block', ['language' => $langcode]);
71 $this->clickLink('Place block');
72 $this->assertText($edit['label']);