You are here

public function ProtectedFixedBlockTest::testProtectedBlockCreation in Fixed Block Content 8

Tests that a protected fixed block creates a non-reusable custom block.

File

tests/src/Kernel/ProtectedFixedBlockTest.php, line 40

Class

ProtectedFixedBlockTest
Tests the protected option of fixed blocks.

Namespace

Drupal\Tests\fixed_block_content\Kernel

Code

public function testProtectedBlockCreation() {

  // Enables the protected option.
  $this->fixedBlock
    ->setProtected();

  // Test that the custom block content from a non protected fixed block is
  // reusable.
  $block_content = $this->fixedBlock
    ->getBlockContent();
  $this
    ->assertEquals(FALSE, $block_content
    ->isReusable());

  // Set the custom block to reusable.
  $block_content
    ->setReusable();

  // Export it to config. The reusable field will be stored in the default
  // content.
  $this->fixedBlock
    ->exportDefaultContent();

  // Delete it.
  $block_content
    ->delete();

  // Import the default reusable block by the protected fixed block.
  $block_content = $this->fixedBlock
    ->getBlockContent();

  // The new block must not be reusable despite the default content was
  // exported as reusable.
  $this
    ->assertEquals(FALSE, $block_content
    ->isReusable());

  // Test if the non-reusable custom block is deleted when the protected
  // fixed block too.
  $this->fixedBlock
    ->delete();

  /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
  $entity_type_manager = $this->container
    ->get('entity_type.manager');
  $block_content = $entity_type_manager
    ->getStorage('block_content')
    ->load($block_content
    ->id());
  $this
    ->assertNull($block_content);
}