You are here

protected function UninstallDefaultContentTest::assertImportedCustomBlock in Drupal 10

Same name and namespace in other branches
  1. 8 core/profiles/demo_umami/modules/demo_umami_content/tests/src/Functional/UninstallDefaultContentTest.php \Drupal\Tests\demo_umami_content\Functional\UninstallDefaultContentTest::assertImportedCustomBlock()
  2. 9 core/profiles/demo_umami/modules/demo_umami_content/tests/src/Functional/UninstallDefaultContentTest.php \Drupal\Tests\demo_umami_content\Functional\UninstallDefaultContentTest::assertImportedCustomBlock()

Assert block content are imported.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $block_storage: Block storage.

1 call to UninstallDefaultContentTest::assertImportedCustomBlock()
UninstallDefaultContentTest::testReinstall in core/profiles/demo_umami/modules/demo_umami_content/tests/src/Functional/UninstallDefaultContentTest.php
Tests uninstalling content removes created entities.

File

core/profiles/demo_umami/modules/demo_umami_content/tests/src/Functional/UninstallDefaultContentTest.php, line 126

Class

UninstallDefaultContentTest
Tests that uninstalling default content removes created content.

Namespace

Drupal\Tests\demo_umami_content\Functional

Code

protected function assertImportedCustomBlock(EntityStorageInterface $block_storage) : void {
  $assert = $this
    ->assertSession();
  foreach ($this
    ->expectedBlocks() as $block_info) {
    $this
      ->drupalGet($block_info['path']);

    // Verify that the block is placed.
    $assert
      ->pageTextContains($block_info['unique_text']);

    // For blocks that have image alt text, also verify the presence of the
    // expected alt text.
    if (isset($block_info['image_alt_text'])) {
      $img_alt_text = $assert
        ->elementExists('css', $block_info['image_css_selector'])
        ->getAttribute('alt');
      $this
        ->assertEquals($block_info['image_alt_text'], $img_alt_text);
    }

    // Verify that the block can be loaded.
    $count = $block_storage
      ->getQuery()
      ->accessCheck(FALSE)
      ->condition('type', $block_info['type'])
      ->count()
      ->execute();
    $this
      ->assertGreaterThan(0, $count);
    $block = $block_storage
      ->loadByProperties([
      'uuid' => $block_info['uuid'],
    ]);
    $this
      ->assertCount(1, $block);
  }
}