class PdbBlockDeriverTest in Decoupled Blocks 8
@coversDefaultClass \Drupal\pdb\Plugin\Derivative\PdbBlockDeriver @group pdb
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\pdb\Unit\Plugin\Derivative\PdbBlockDeriverTest
Expanded class hierarchy of PdbBlockDeriverTest
File
- tests/
src/ Unit/ Plugin/ Derivative/ PdbBlockDeriverTest.php, line 14
Namespace
Drupal\Tests\pdb\Unit\Plugin\DerivativeView source
class PdbBlockDeriverTest extends UnitTestCase {
/**
* Mocked Component Discovery.
*
* @var \Drupal\pdb\ComponentDiscoveryInterface
*/
protected $componentDiscovery;
/**
* Instance of the Block Deriver.
*
* @var \Drupal\pdb\Plugin\Derivative\PdbBlockDeriver
*/
protected $deriver;
/**
* Create the setup for constants.
*/
protected function setUp() {
parent::setUp();
// 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' => 'pdb',
'contexts' => [
'entity' => 'node',
],
],
],
]);
$this->deriver = new PdbBlockDeriver($this->componentDiscovery
->reveal());
}
/**
* Tests the create method.
*
* @see ::create()
*/
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);
}
/**
* Tests the getDerivativeDefinitions() method.
*/
public function testGetDerivativeDefinitions() {
$base_plugin_definition = [
'provider' => 'pdb',
];
// example_1 should not appear due to debug mode being off.
$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']);
// Remove the context to compare the arrays.
unset($return['block_1']['context_definitions']);
$this
->assertEquals($expected, $return);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PdbBlockDeriverTest:: |
protected | property | Mocked Component Discovery. | |
PdbBlockDeriverTest:: |
protected | property | Instance of the Block Deriver. | |
PdbBlockDeriverTest:: |
protected | function |
Create the setup for constants. Overrides UnitTestCase:: |
|
PdbBlockDeriverTest:: |
public | function | Tests the create method. | |
PdbBlockDeriverTest:: |
public | function | Tests the getDerivativeDefinitions() method. | |
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. |