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