View source
<?php
namespace Drupal\Tests\pdb_vue\Unit\Plugin\Derivative;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\pdb_vue\Plugin\Derivative\VueBlockDeriver;
use Drupal\pdb\ComponentDiscoveryInterface;
class VueBlockDeriverTest extends UnitTestCase {
protected $componentDiscovery;
protected $configFactory;
protected $deriver;
protected function setUp() {
parent::setUp();
$this->configFactory = $this
->getConfigFactoryStub([
'pdb_vue.settings' => [
'development_mode' => 0,
],
]);
$this->componentDiscovery = $this
->prophesize(ComponentDiscoveryInterface::CLASS);
$this->componentDiscovery
->getComponents()
->willReturn([
'block_1' => (object) [
'type' => 'pdb',
'info' => [
'name' => 'Block 1',
'machine_name' => 'block_1',
'presentation' => 'vue',
],
],
'vue_example_1' => (object) [
'type' => 'pdb',
'info' => [
'name' => 'Vue Example 1',
'type' => 'vue-example-1',
'presentation' => 'vue',
],
],
]);
$this->deriver = new VueBlockDeriver($this->componentDiscovery
->reveal(), $this->configFactory);
}
public function testCreate() {
$base_plugin_id = 'pdb_vue';
$container = $this
->prophesize(ContainerInterface::CLASS);
$container
->get('pdb.component_discovery')
->willReturn($this->componentDiscovery);
$container
->get('config.factory')
->willReturn($this->configFactory);
$instance = VueBlockDeriver::create($container
->reveal(), $base_plugin_id);
$this
->assertInstanceOf('Drupal\\pdb_vue\\Plugin\\Derivative\\VueBlockDeriver', $instance);
}
public function testGetDerivativeDefinitions() {
$base_plugin_definition = [
'provider' => 'pdb_vue',
];
$expected = [
'block_1' => [
'info' => [
'name' => 'Block 1',
'machine_name' => 'block_1',
'presentation' => 'vue',
],
'provider' => 'pdb_vue',
'admin_label' => 'Block 1',
'cache' => [
'max-age' => 0,
],
],
];
$return = $this->deriver
->getDerivativeDefinitions($base_plugin_definition);
$this
->assertArrayEquals($expected, $return);
}
}