FixedToContentMappingTest.php in Fixed Block Content 8
File
tests/src/Kernel/FixedToContentMappingTest.php
View source
<?php
namespace Drupal\Tests\fixed_block_content\Kernel;
class FixedToContentMappingTest extends FixedBlockContentKernelTestBase {
protected $mappingHandler;
protected $blockContent;
protected function setUp() {
parent::setUp();
$this->mappingHandler = $this->entityTypeManager
->getHandler('fixed_block_content', 'mapping_handler');
$this->blockContent = $this->entityTypeManager
->getStorage('block_content')
->create([
'type' => 'basic',
'info' => 'Basic block',
]);
}
public function testSetBlockContent() {
$this->mappingHandler
->setBlockContent($this->fixedBlock, $this->blockContent);
$this
->assertEquals($this->blockContent
->id(), $this->fixedBlock
->getBlockContent(FALSE)
->id());
$this->mappingHandler
->setBlockContent($this->fixedBlock, $this->blockContent);
}
public function testSetBlockContentInProtected() {
$this->fixedBlock
->setProtected();
$block_content_id = $this->fixedBlock
->getBlockContent()
->id();
$this->mappingHandler
->setBlockContent($this->fixedBlock, $this->blockContent);
$this
->assertEmpty($this->entityTypeManager
->getStorage('block_content')
->load($block_content_id));
}
public function testGetBlockContentOnUnlinked() {
$block_content = $this->mappingHandler
->getBlockContent($this->fixedBlock
->id());
$this
->assertNull($block_content);
$block_content = $this->fixedBlock
->getBlockContent(FALSE);
$this
->assertNull($block_content);
}
public function testGetDeletedBlockContent() {
$block_content = $this->fixedBlock
->getBlockContent();
$original_id = $block_content
->id();
$block_content
->delete();
$block_content = $this->fixedBlock
->getBlockContent();
$this
->assertNotEquals($block_content
->id(), $original_id);
}
public function testReleaseBlockContent() {
$this->mappingHandler
->releaseBlockContent($this->fixedBlock);
$block_id = $this->fixedBlock
->getBlockContent()
->id();
$this->mappingHandler
->releaseBlockContent($this->fixedBlock);
$this
->assertNotNull($this->entityTypeManager
->getStorage('block_content')
->load($block_id));
$this
->assertEmpty($this->fixedBlock
->getBlockContent(FALSE));
$this->fixedBlock
->setProtected();
$block_id = $this->fixedBlock
->getBlockContent()
->id();
$this->mappingHandler
->releaseBlockContent($this->fixedBlock);
$this
->assertNull($this->entityTypeManager
->getStorage('block_content')
->load($block_id));
$this
->assertEmpty($this->fixedBlock
->getBlockContent(FALSE));
}
public function testGetFixedBlock() {
$this
->assertEmpty($this->mappingHandler
->getFixedBlock($this->blockContent));
$this->blockContent
->save();
$this
->assertEmpty($this->mappingHandler
->getFixedBlock($this->blockContent));
$linked_block_content = $this->fixedBlock
->getBlockContent();
$this
->assertEquals($this->mappingHandler
->getFixedBlock($linked_block_content)
->id(), $this->fixedBlock
->id());
}
}