9ca2b718636de7c648065caedccb9e3e6c1825eb
[yaffs-website] / web / core / modules / block / tests / src / Functional / BlockLanguageCacheTest.php
1 <?php
2
3 namespace Drupal\Tests\block\Functional;
4
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests display of menu blocks with multiple languages.
10  *
11  * @group block
12  */
13 class BlockLanguageCacheTest extends BrowserTestBase {
14
15   /**
16    * Modules to install.
17    *
18    * @var array
19    */
20   public static $modules = ['block', 'language', 'menu_ui'];
21
22   /**
23    * List of langcodes.
24    *
25    * @var array
26    */
27   protected $langcodes = [];
28
29   protected function setUp() {
30     parent::setUp();
31
32     // Create test languages.
33     $this->langcodes = [ConfigurableLanguage::load('en')];
34     for ($i = 1; $i < 3; ++$i) {
35       $language = ConfigurableLanguage::create([
36         'id' => 'l' . $i,
37         'label' => $this->randomString(),
38       ]);
39       $language->save();
40       $this->langcodes[$i] = $language;
41     }
42   }
43
44   /**
45    * Creates a block in a language, check blocks page in all languages.
46    */
47   public function testBlockLinks() {
48     // Create admin user to be able to access block admin.
49     $admin_user = $this->drupalCreateUser([
50       'administer blocks',
51       'access administration pages',
52       'administer menu',
53     ]);
54     $this->drupalLogin($admin_user);
55
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');
60     }
61
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']]));
67
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']);
73     }
74   }
75
76 }