You are here

public function AutoExportTest::testAutoExportOnNonEmpty in Fixed Block Content 8

Tests the automatic block content creation on non empty.

File

tests/src/Kernel/AutoExportTest.php, line 72

Class

AutoExportTest
Tests the auto-create option of fixed blocks.

Namespace

Drupal\Tests\fixed_block_content\Kernel

Code

public function testAutoExportOnNonEmpty() {

  // Check that there is no block content for the fixed block with
  // the auto-export option disabled.

  /** @var \Drupal\fixed_block_content\FixedBlockContentInterface[] $fixed_blocks */
  $fixed_blocks = [];

  /** @var \Drupal\block_content\BlockContentInterface[] $block_contents */
  $block_contents = [];
  $entity_storage = $this->entityTypeManager
    ->getStorage('fixed_block_content');
  foreach ($this->testBlocksId as $block_id) {
    $fixed_blocks[$block_id] = $entity_storage
      ->load($block_id);

    // Creates an empty block content for each test block.
    $block_contents[$block_id] = $fixed_blocks[$block_id]
      ->getBlockContent();
  }

  // Do config import.
  $this
    ->configImporter()
    ->import();

  // Check that there is no changes in the block content linked to the test
  // fixed block with the auto-export option disabled.
  $this
    ->assertEqual($fixed_blocks['test_auto_export_disabled']
    ->getBlockContent(FALSE), $block_contents['test_auto_export_disabled']);

  // Check that the fixed block with the auto-export on empty option
  // has no changes.
  $this
    ->assertEqual($fixed_blocks['auto_export_on_empty']
    ->getBlockContent(FALSE), $block_contents['auto_export_on_empty']);

  // Check that the fixed block with the auto-export always option
  // has a block content linked.
  $this
    ->assertNotEqual($fixed_blocks['auto_export_always']
    ->getBlockContent(FALSE), $block_contents['auto_export_always']);
}