Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\block\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
6 use Drupal\block\Entity\Block;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Tests that an active block assigned to a non-existing region triggers the
|
Chris@0
|
10 * warning message and is disabled.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @group block
|
Chris@0
|
13 */
|
Chris@0
|
14 class BlockInvalidRegionTest extends BrowserTestBase {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * Modules to install.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @var array
|
Chris@0
|
20 */
|
Chris@0
|
21 public static $modules = ['block', 'block_test'];
|
Chris@0
|
22
|
Chris@0
|
23 protected function setUp() {
|
Chris@0
|
24 parent::setUp();
|
Chris@0
|
25 // Create an admin user.
|
Chris@0
|
26 $admin_user = $this->drupalCreateUser([
|
Chris@0
|
27 'administer site configuration',
|
Chris@0
|
28 'access administration pages',
|
Chris@0
|
29 'administer blocks',
|
Chris@0
|
30 ]);
|
Chris@0
|
31 $this->drupalLogin($admin_user);
|
Chris@0
|
32 }
|
Chris@0
|
33
|
Chris@0
|
34 /**
|
Chris@0
|
35 * Tests that blocks assigned to invalid regions work correctly.
|
Chris@0
|
36 */
|
Chris@0
|
37 public function testBlockInInvalidRegion() {
|
Chris@0
|
38 // Enable a test block and place it in an invalid region.
|
Chris@0
|
39 $block = $this->drupalPlaceBlock('test_html');
|
Chris@0
|
40 \Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save();
|
Chris@0
|
41 $block = Block::load($block->id());
|
Chris@0
|
42
|
Chris@0
|
43 $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block->id(), '%region' => 'invalid_region']);
|
Chris@0
|
44
|
Chris@0
|
45 // Clearing the cache should disable the test block placed in the invalid region.
|
Chris@0
|
46 $this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
|
Chris@0
|
47 $this->assertRaw($warning_message, 'Enabled block was in the invalid region and has been disabled.');
|
Chris@0
|
48
|
Chris@0
|
49 // Clear the cache to check if the warning message is not triggered.
|
Chris@0
|
50 $this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
|
Chris@0
|
51 $this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
|
Chris@0
|
52
|
Chris@0
|
53 // Place disabled test block in the invalid region of the default theme.
|
Chris@0
|
54 \Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save();
|
Chris@0
|
55 $block = Block::load($block->id());
|
Chris@0
|
56
|
Chris@0
|
57 // Clear the cache to check if the warning message is not triggered.
|
Chris@0
|
58 $this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
|
Chris@0
|
59 $this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 }
|