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