function UninstallDefaultContentTest::assertImportedCustomBlock

Same name and namespace in other branches
  1. 9 core/profiles/demo_umami/modules/demo_umami_content/tests/src/Functional/UninstallDefaultContentTest.php \Drupal\Tests\demo_umami_content\Functional\UninstallDefaultContentTest::assertImportedCustomBlock()
  2. 8.9.x core/profiles/demo_umami/modules/demo_umami_content/tests/src/Functional/UninstallDefaultContentTest.php \Drupal\Tests\demo_umami_content\Functional\UninstallDefaultContentTest::assertImportedCustomBlock()
  3. 11.x 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 128

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);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.