function BlockDisplayVariantTest::testBlockDisplayVariantEvents

Same name and namespace in other branches
  1. 8.x-3.x tests/src/Kernel/BlockDisplayVariantTest.php \Drupal\Tests\ctools\Kernel\BlockDisplayVariantTest::testBlockDisplayVariantEvents()

Tests that events are fired when manipulating a block variant.

File

tests/src/Kernel/BlockDisplayVariantTest.php, line 28

Class

BlockDisplayVariantTest
@coversDefaultClass <a href="/api/ctools/src%21Plugin%21DisplayVariant%21BlockDisplayVariant.php/class/BlockDisplayVariant/4.0.x" title="Provides a base class for a display variant that simply contains blocks." class="local">\Drupal\ctools\Plugin\DisplayVariant\BlockDisplayVariant</a> @group CTools

Namespace

Drupal\Tests\ctools\Kernel

Code

public function testBlockDisplayVariantEvents() {
    
    /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
    $event_dispatcher = $this->prophesize(EventDispatcherInterface::class);
    // Swap in a mock event dispatcher so we can spy on method calls.
    $this->container
        ->set('event_dispatcher', $event_dispatcher->reveal());
    $variant = BlockDisplayVariant::create($this->container, [], 'foobar', []);
    // Set up the expected calls to the event dispatcher.
    $event = Argument::type(BlockVariantEvent::class);
    $event_dispatcher->dispatch($event, BlockVariantEvents::ADD_BLOCK)
        ->shouldBeCalled();
    $event_dispatcher->dispatch($event, BlockVariantEvents::UPDATE_BLOCK)
        ->shouldBeCalled();
    $event_dispatcher->dispatch($event, BlockVariantEvents::DELETE_BLOCK)
        ->shouldBeCalled();
    $block_id = $variant->addBlock([
        'id' => 'system_powered_by_block',
    ]);
    $variant->updateBlock($block_id, []);
    $variant->removeBlock($block_id);
}