function BlockManagerTest::setUp

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php \Drupal\Tests\Core\Block\BlockManagerTest::setUp()
  2. 10 core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php \Drupal\Tests\Core\Block\BlockManagerTest::setUp()
  3. 11.x core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php \Drupal\Tests\Core\Block\BlockManagerTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php, line 37

Class

BlockManagerTest
@coversDefaultClass \Drupal\Core\Block\BlockManager

Namespace

Drupal\Tests\Core\Block

Code

protected function setUp() {
    parent::setUp();
    $cache_backend = $this->prophesize(CacheBackendInterface::class);
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $this->logger = $this->prophesize(LoggerInterface::class);
    $this->blockManager = new BlockManager(new \ArrayObject(), $cache_backend->reveal(), $module_handler->reveal(), $this->logger
        ->reveal());
    $this->blockManager
        ->setStringTranslation($this->getStringTranslationStub());
    $discovery = $this->prophesize(DiscoveryInterface::class);
    // Specify the 'broken' block, as well as 3 other blocks with admin labels
    // that are purposefully not in alphabetical order.
    $discovery->getDefinitions()
        ->willReturn([
        'broken' => [
            'admin_label' => 'Broken/Missing',
            'category' => 'Block',
            'class' => Broken::class,
            'provider' => 'core',
        ],
        'block1' => [
            'admin_label' => 'Coconut',
            'category' => 'Group 2',
        ],
        'block2' => [
            'admin_label' => 'Apple',
            'category' => 'Group 1',
        ],
        'block3' => [
            'admin_label' => 'Banana',
            'category' => 'Group 2',
        ],
    ]);
    // Force the discovery object onto the block manager.
    $property = new \ReflectionProperty(BlockManager::class, 'discovery');
    $property->setAccessible(TRUE);
    $property->setValue($this->blockManager, $discovery->reveal());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.