You are here

public function DefaultContentTest::testDefaultContentExport in Fixed Block Content 8

Tests the default content export.

That is, copy contents from fixed block content configuration to its regular block content.

@covers ::exportDefaultContent

File

tests/src/Kernel/DefaultContentTest.php, line 21

Class

DefaultContentTest
Tests the fixed block default content management.

Namespace

Drupal\Tests\fixed_block_content\Kernel

Code

public function testDefaultContentExport() {

  // Test the block content creation on default content export. It must end
  // with the creation of a new (empty) block content even if trying to
  // update a non-existing linked block content.
  $this->fixedBlock
    ->exportDefaultContent(TRUE);
  $block_content = $this->fixedBlock
    ->getBlockContent(FALSE);
  $this
    ->assertNotNull($block_content);

  // Test that it is a new block content.
  $this
    ->assertEqual($block_content
    ->id(), 1);

  // Tests that the default content export updates existing block content.
  $block_content
    ->get('body')
    ->setValue('To be overridden.');
  $block_content
    ->save();
  $this->fixedBlock
    ->exportDefaultContent(TRUE);
  $block_content = $this->fixedBlock
    ->getBlockContent(FALSE);

  // Must be the same block content.
  $this
    ->assertEqual($block_content
    ->id(), 1);

  // The body must be empty, as it is in the default content.
  $this
    ->assertTrue($block_content
    ->get('body')
    ->isEmpty());

  // Tests that the default content is stored persistent.
  $test_content = 'To be restored.';
  $block_content
    ->get('body')
    ->setValue($test_content);
  $this->fixedBlock
    ->importDefaultContent();
  $this->fixedBlock
    ->exportDefaultContent();
  $block_content = $this->fixedBlock
    ->getBlockContent(FALSE);

  // It must be a new block content.
  $this
    ->assertEqual($block_content
    ->id(), 2);

  // Tests that the default content was correctly exported.
  $this
    ->assertEqual($block_content
    ->get('body')
    ->getString(), $test_content);
}