You are here

public function LayoutBuilderInlineBlockStubCleanupTest::testLayoutBuilderInlineBlockStubCleanup in Acquia Content Hub 8.2

Tests LayoutBuilderInlineBlockStubCleanup event subscriber.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

tests/src/Kernel/EventSubscriber/CleanUpStubs/LayoutBuilderInlineBlockStubCleanupTest.php, line 64

Class

LayoutBuilderInlineBlockStubCleanupTest
Test that LB inline block is handled correctly in CLEANUP_STUBS event.

Namespace

Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\CleanUpStubs

Code

public function testLayoutBuilderInlineBlockStubCleanup() {
  $block_content = $this
    ->createEntity();

  // Create again to have a duplicate.
  $this
    ->createEntity();
  $event = new CleanUpStubsEvent($block_content, new DependencyStack());
  $this->dispatcher
    ->dispatch(AcquiaContentHubEvents::CLEANUP_STUBS, $event);

  // Inline block usage is not set, should not stop propagation.
  $this
    ->assertFalse($event
    ->isPropagationStopped());

  // Just insert a row in the table with fixed values.
  $this
    ->addInlineBlockUsage($block_content
    ->id());
  $event = new CleanUpStubsEvent($block_content, new DependencyStack());
  $this->dispatcher
    ->dispatch(AcquiaContentHubEvents::CLEANUP_STUBS, $event);

  // Inline block usage is there so propagation should be stopped.
  $this
    ->assertTrue($event
    ->isPropagationStopped());
  $blocks = \Drupal::entityTypeManager()
    ->getStorage('block_content')
    ->loadByProperties([
    'info' => $block_content
      ->get('info')->value,
  ]);
  $this
    ->assertEqual(count($blocks), 1, 'Only 1 block should be after subscriber run');
}