X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=inline;f=web%2Fcore%2Fmodules%2Fblock%2Ftests%2Fsrc%2FKernel%2FBlockRebuildTest.php;fp=web%2Fcore%2Fmodules%2Fblock%2Ftests%2Fsrc%2FKernel%2FBlockRebuildTest.php;h=33de12ce87d8d69dda68e1284a56df6381d12122;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/block/tests/src/Kernel/BlockRebuildTest.php b/web/core/modules/block/tests/src/Kernel/BlockRebuildTest.php new file mode 100644 index 000000000..33de12ce8 --- /dev/null +++ b/web/core/modules/block/tests/src/Kernel/BlockRebuildTest.php @@ -0,0 +1,103 @@ +container->get('theme_installer')->install(['stable', 'classy']); + $this->container->get('config.factory')->getEditable('system.theme')->set('default', 'classy')->save(); + } + + /** + * {@inheritdoc} + */ + public static function setUpBeforeClass() { + parent::setUpBeforeClass(); + + // @todo Once block_rebuild() is refactored to auto-loadable code, remove + // this require statement. + require_once static::getDrupalRoot() . '/core/modules/block/block.module'; + } + + /** + * @covers ::block_rebuild + */ + public function testRebuildNoBlocks() { + block_rebuild(); + $messages = drupal_get_messages(); + $this->assertEquals([], $messages); + } + + /** + * @covers ::block_rebuild + */ + public function testRebuildNoInvalidBlocks() { + $this->placeBlock('system_powered_by_block', ['region' => 'content']); + + block_rebuild(); + $messages = drupal_get_messages(); + $this->assertEquals([], $messages); + } + + /** + * @covers ::block_rebuild + */ + public function testRebuildInvalidBlocks() { + $this->placeBlock('system_powered_by_block', ['region' => 'content']); + $block1 = $this->placeBlock('system_powered_by_block'); + $block2 = $this->placeBlock('system_powered_by_block'); + $block2->disable()->save(); + // Use the config API directly to bypass Block::preSave(). + \Drupal::configFactory()->getEditable('block.block.' . $block1->id())->set('region', 'INVALID')->save(); + \Drupal::configFactory()->getEditable('block.block.' . $block2->id())->set('region', 'INVALID')->save(); + + // Reload block entities. + $block1 = Block::load($block1->id()); + $block2 = Block::load($block2->id()); + + $this->assertSame('INVALID', $block1->getRegion()); + $this->assertTrue($block1->status()); + $this->assertSame('INVALID', $block2->getRegion()); + $this->assertFalse($block2->status()); + + block_rebuild(); + + // Reload block entities. + $block1 = Block::load($block1->id()); + $block2 = Block::load($block2->id()); + + $messages = drupal_get_messages(); + $expected = ['warning' => [new TranslatableMarkup('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block1->id(), '%region' => 'INVALID'])]]; + $this->assertEquals($expected, $messages); + + $default_region = system_default_region('classy'); + $this->assertSame($default_region, $block1->getRegion()); + $this->assertFalse($block1->status()); + $this->assertSame($default_region, $block2->getRegion()); + $this->assertFalse($block2->status()); + } + +}