You are here

class ToolbarAlterEventTest in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 modules/toolbar_event_dispatcher/tests/src/Unit/Toolbar/ToolbarAlterEventTest.php \Drupal\Tests\toolbar_event_dispatcher\Unit\Toolbar\ToolbarAlterEventTest

Class ToolbarAlterEventTest.

@group toolbar_event_dispatcher

Hierarchy

  • class \Drupal\Tests\toolbar_event_dispatcher\Unit\Toolbar\ToolbarAlterEventTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of ToolbarAlterEventTest

File

modules/toolbar_event_dispatcher/tests/src/Unit/Toolbar/ToolbarAlterEventTest.php, line 18

Namespace

Drupal\Tests\toolbar_event_dispatcher\Unit\Toolbar
View source
class ToolbarAlterEventTest extends TestCase {

  /**
   * The manager.
   *
   * @var \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy
   */
  private $manager;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    $builder = new ContainerBuilder();
    $this->manager = new HookEventDispatcherManagerSpy();
    $builder
      ->set('hook_event_dispatcher.manager', $this->manager);
    $builder
      ->compile();
    Drupal::setContainer($builder);
  }

  /**
   * Test the ToolbarAlterEvent.
   */
  public function testToolbarAlterEvent() : void {
    $newItem = [
      'test' => 'item',
    ];
    $this->manager
      ->setEventCallbacks([
      HookEventDispatcherInterface::TOOLBAR_ALTER => static function (ToolbarAlterEvent $event) use ($newItem) {
        $items =& $event
          ->getItems();
        $items += $newItem;
      },
    ]);
    $items = [
      'user' => [],
      'manage' => [],
    ];
    $expectedItems = $items + $newItem;
    toolbar_event_dispatcher_toolbar_alter($items);

    /** @var \Drupal\toolbar_event_dispatcher\Event\Toolbar\ToolbarAlterEvent $event */
    $event = $this->manager
      ->getRegisteredEvent(HookEventDispatcherInterface::TOOLBAR_ALTER);
    self::assertSame($expectedItems, $items);
    self::assertSame($expectedItems, $event
      ->getItems());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ToolbarAlterEventTest::$manager private property The manager.
ToolbarAlterEventTest::setUp public function
ToolbarAlterEventTest::testToolbarAlterEvent public function Test the ToolbarAlterEvent.