function TopBarItemManagerTest::setUp

Same name and namespace in other branches
  1. 11.x core/modules/navigation/tests/src/Unit/TopBarItemManagerTest.php \Drupal\Tests\navigation\Unit\TopBarItemManagerTest::setUp()

Overrides UnitTestCase::setUp

File

core/modules/navigation/tests/src/Unit/TopBarItemManagerTest.php, line 38

Class

TopBarItemManagerTest
Tests Drupal\navigation\TopBarItemManager.

Namespace

Drupal\Tests\navigation\Unit

Code

protected function setUp() : void {
  parent::setUp();
  $container = new ContainerBuilder();
  $container->set('string_translation', $this->getStringTranslationStub());
  \Drupal::setContainer($container);
  $cache_backend = $this->prophesize(CacheBackendInterface::class);
  $module_handler = $this->prophesize(ModuleHandlerInterface::class);
  $this->manager = new TopBarItemManager(new \ArrayObject(), $cache_backend->reveal(), $module_handler->reveal());
  $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([
    'tools' => [
      'label' => 'Tools',
      'region' => TopBarRegion::Tools,
    ],
    'context' => [
      'admin_label' => 'Context',
      'region' => TopBarRegion::Context,
    ],
    'actions' => [
      'label' => 'Actions',
      'region' => TopBarRegion::Actions,
    ],
    'more_actions' => [
      'label' => 'More Actions',
      'region' => TopBarRegion::Actions,
    ],
  ]);
  // Force the discovery object onto the block manager.
  $property = new \ReflectionProperty(TopBarItemManager::class, 'discovery');
  $property->setValue($this->manager, $discovery->reveal());
}

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