class VueBlockDeriverTest in Decoupled Blocks: Vue.js 8
@coversDefaultClass \Drupal\pdb_vue\Plugin\Derivative\VueBlockDeriver @group pdb_vue
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\pdb_vue\Unit\Plugin\Derivative\VueBlockDeriverTest
Expanded class hierarchy of VueBlockDeriverTest
File
- tests/
src/ Unit/ Plugin/ Derivative/ VueBlockDeriverTest.php, line 14
Namespace
Drupal\Tests\pdb_vue\Unit\Plugin\DerivativeView source
class VueBlockDeriverTest extends UnitTestCase {
/**
* Mocked Component Discovery.
*
* @var \Drupal\pdb\ComponentDiscoveryInterface
*/
protected $componentDiscovery;
/**
* The mocked config factory.
*
* @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configFactory;
/**
* Instance of the Block Deriver.
*
* @var \Drupal\pdb_vue\Plugin\Derivative\VueBlockDeriver
*/
protected $deriver;
/**
* Create the setup for constants and configFactory stub.
*/
protected function setUp() {
parent::setUp();
// Stub the Config Factory.
$this->configFactory = $this
->getConfigFactoryStub([
'pdb_vue.settings' => [
'development_mode' => 0,
],
]);
// Mock the UUID service.
$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);
}
/**
* Tests the create method.
*
* @see ::create()
*/
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);
}
/**
* Tests the getDerivativeDefinitions() method.
*/
public function testGetDerivativeDefinitions() {
$base_plugin_definition = [
'provider' => 'pdb_vue',
];
// vue_example_1 should not appear due to debug mode being off.
$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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
VueBlockDeriverTest:: |
protected | property | Mocked Component Discovery. | |
VueBlockDeriverTest:: |
protected | property | The mocked config factory. | |
VueBlockDeriverTest:: |
protected | property | Instance of the Block Deriver. | |
VueBlockDeriverTest:: |
protected | function |
Create the setup for constants and configFactory stub. Overrides UnitTestCase:: |
|
VueBlockDeriverTest:: |
public | function | Tests the create method. | |
VueBlockDeriverTest:: |
public | function | Tests the getDerivativeDefinitions() method. |