PdbBlockDeriverTest.php in Decoupled Blocks 8
File
tests/src/Unit/Plugin/Derivative/PdbBlockDeriverTest.php
View source
<?php
namespace Drupal\Tests\pdb\Unit\Plugin\Derivative;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\pdb\Plugin\Derivative\PdbBlockDeriver;
use Drupal\pdb\ComponentDiscoveryInterface;
class PdbBlockDeriverTest extends UnitTestCase {
protected $componentDiscovery;
protected $deriver;
protected function setUp() {
parent::setUp();
$this->componentDiscovery = $this
->prophesize(ComponentDiscoveryInterface::CLASS);
$this->componentDiscovery
->getComponents()
->willReturn([
'block_1' => (object) [
'type' => 'pdb',
'info' => [
'name' => 'Block 1',
'machine_name' => 'block_1',
'presentation' => 'pdb',
'contexts' => [
'entity' => 'node',
],
],
],
]);
$this->deriver = new PdbBlockDeriver($this->componentDiscovery
->reveal());
}
public function testCreate() {
$base_plugin_id = 'pdb';
$container = $this
->prophesize(ContainerInterface::CLASS);
$container
->get('pdb.component_discovery')
->willReturn($this->componentDiscovery);
$instance = PdbBlockDeriver::create($container
->reveal(), $base_plugin_id);
$this
->assertInstanceOf('Drupal\\pdb\\Plugin\\Derivative\\PdbBlockDeriver', $instance);
}
public function testGetDerivativeDefinitions() {
$base_plugin_definition = [
'provider' => 'pdb',
];
$expected = [
'block_1' => [
'info' => [
'name' => 'Block 1',
'machine_name' => 'block_1',
'presentation' => 'pdb',
'contexts' => [
'entity' => 'node',
],
],
'provider' => 'pdb',
'admin_label' => 'Block 1',
'cache' => [
'max-age' => 0,
],
],
];
$return = $this->deriver
->getDerivativeDefinitions($base_plugin_definition);
$this
->assertInstanceOf('Drupal\\Core\\Plugin\\Context\\EntityContextDefinition', $return['block_1']['context_definitions']['entity']);
unset($return['block_1']['context_definitions']);
$this
->assertEquals($expected, $return);
}
}