You are here

protected function BlockManagerTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php \Drupal\Tests\Core\Block\BlockManagerTest::setUp()
  2. 9 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 39

Class

BlockManagerTest
@coversDefaultClass \Drupal\Core\Block\BlockManager

Namespace

Drupal\Tests\Core\Block

Code

protected function setUp() : void {
  parent::setUp();
  $container = new ContainerBuilder();
  $current_user = $this
    ->prophesize(AccountInterface::class);
  $container
    ->set('current_user', $current_user
    ->reveal());
  \Drupal::setContainer($container);
  $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());
}