BlockManager example

parent::setUp();

    $container = new ContainerBuilder();
    $current_user = $this->prophesize(AccountInterface::class);
    $container->set('current_user', $current_user->reveal());
    $container->set('string_translation', $this->getStringTranslationStub());
    \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' => $this->t('Broken/Missing'),
        'category' => $this->t('Block'),
        'class' => Broken::class,
        'provider' => 'core',
      ],
Home | Imprint | This part of the site doesn't use cookies.