class PluginTypeConverterTest in Plugin 8.2
Same name in this branch
- 8.2 tests/src/Functional/ParamConverter/PluginTypeConverterTest.php \Drupal\Tests\plugin\Functional\ParamConverter\PluginTypeConverterTest
- 8.2 tests/src/Unit/ParamConverter/PluginTypeConverterTest.php \Drupal\Tests\plugin\Unit\ParamConverter\PluginTypeConverterTest
@coversDefaultClass \Drupal\plugin\ParamConverter\PluginTypeConverter
@group Plugin
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\plugin\Unit\ParamConverter\PluginTypeConverterTest
Expanded class hierarchy of PluginTypeConverterTest
File
- tests/
src/ Unit/ ParamConverter/ PluginTypeConverterTest.php, line 16
Namespace
Drupal\Tests\plugin\Unit\ParamConverterView source
class PluginTypeConverterTest extends UnitTestCase {
/**
* The plugin manager.
*
* @var \Drupal\plugin\PluginType\PluginTypeManagerInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $pluginTypeManager;
/**
* The system under test.
*
* @var \Drupal\plugin\ParamConverter\PluginTypeConverter
*/
protected $sut;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->pluginTypeManager = $this
->prophesize(PluginTypeManagerInterface::class);
$this->sut = new PluginTypeConverter($this->pluginTypeManager
->reveal());
}
/**
* @covers ::applies
* @covers ::validateParameterDefinition
* @covers ::getConverterDefinitionConstraint
* @covers ::getConverterDefinition
* @covers ::getConverterDefinitionKey
* @covers ::__construct
*
* @dataProvider provideApplies
*/
public function testApplies($expected, $definition) {
$name = 'foo_bar';
$route = $this
->prophesize(Route::class);
$this
->assertSame($expected, $this->sut
->applies($definition, $name, $route
->reveal()));
}
/**
* Provides data to self::testApplies().
*/
public function provideApplies() {
$data = [];
$data['applies-because-implicitly-enabled'] = [
TRUE,
[
'plugin.plugin_type' => [],
],
];
$data['applies-because-explicitly-enabled'] = [
TRUE,
[
'plugin.plugin_type' => [
'enabled' => TRUE,
],
],
];
$data['applies-not-because-disabled'] = [
FALSE,
[
'plugin.plugin_type' => [
'enabled' => FALSE,
],
],
];
$data['applies-not-because-non-existent'] = [
FALSE,
[],
];
return $data;
}
/**
* @covers ::convert
* @covers ::doConvert
* @covers ::validateParameterDefinition
* @covers ::getConverterDefinitionConstraint
* @covers ::getConverterDefinition
* @covers ::getConverterDefinitionKey
* @covers ::__construct
*/
public function testConvertWithExceptionReturnsNull() {
$plugin_type_id = 'foo_bar.baz';
$definition = [
'plugin.plugin_type' => [],
];
$name = 'foo_bar';
$defaults = [];
$this->pluginTypeManager
->hasPluginType($plugin_type_id)
->willReturn(FALSE);
$original_error_reporting = error_reporting();
error_reporting($original_error_reporting & ~E_USER_WARNING);
$this
->assertNull($this->sut
->convert($plugin_type_id, $definition, $name, $defaults));
error_reporting($original_error_reporting);
}
/**
* @covers ::convert
* @covers ::doConvert
* @covers ::validateParameterDefinition
* @covers ::getConverterDefinitionConstraint
* @covers ::getConverterDefinition
* @covers ::getConverterDefinitionKey
* @covers ::__construct
*/
public function testConvertWithKnownPluginType() {
$plugin_type_id = 'foo_bar.baz';
$definition = [
'plugin.plugin_type' => [],
];
$name = 'foo_bar';
$defaults = [];
$plugin_type = $this
->prophesize(PluginTypeInterface::class);
$this->pluginTypeManager
->hasPluginType($plugin_type_id)
->willReturn(TRUE);
$this->pluginTypeManager
->getPluginType($plugin_type_id)
->willReturn($plugin_type
->reveal());
$this
->assertSame($plugin_type
->reveal(), $this->sut
->convert($plugin_type_id, $definition, $name, $defaults));
}
/**
* @covers ::convert
* @covers ::doConvert
* @covers ::validateParameterDefinition
* @covers ::getConverterDefinitionConstraint
* @covers ::getConverterDefinition
* @covers ::getConverterDefinitionKey
* @covers ::__construct
*/
public function testConvertWithUnknownPluginType() {
$plugin_type_id = 'foo_bar.baz';
$definition = [
'plugin.plugin_type' => [],
];
$name = 'foo_bar';
$defaults = [];
$this->pluginTypeManager
->hasPluginType($plugin_type_id)
->willReturn(FALSE);
$this
->assertNull($this->sut
->convert($plugin_type_id, $definition, $name, $defaults));
}
/**
* @covers ::convert
* @covers ::doConvert
* @covers ::validateParameterDefinition
* @covers ::getConverterDefinitionConstraint
* @covers ::getConverterDefinition
* @covers ::getConverterDefinitionKey
* @covers ::__construct
*/
public function testConvertWithInvalidDefinition() {
// Leave out the "plugin.plugin_type" key.
$definition = [];
$plugin_type_id = 'foozaar.bazaar';
$name = 'foo_bar';
$defaults = [];
$this
->assertNull($this->sut
->convert($plugin_type_id, $definition, $name, $defaults));
}
}
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. | |
PluginTypeConverterTest:: |
protected | property | The plugin manager. | |
PluginTypeConverterTest:: |
protected | property | The system under test. | |
PluginTypeConverterTest:: |
public | function | Provides data to self::testApplies(). | |
PluginTypeConverterTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PluginTypeConverterTest:: |
public | function | @covers ::applies @covers ::validateParameterDefinition @covers ::getConverterDefinitionConstraint @covers ::getConverterDefinition @covers ::getConverterDefinitionKey @covers ::__construct | |
PluginTypeConverterTest:: |
public | function | @covers ::convert @covers ::doConvert @covers ::validateParameterDefinition @covers ::getConverterDefinitionConstraint @covers ::getConverterDefinition @covers ::getConverterDefinitionKey @covers ::__construct | |
PluginTypeConverterTest:: |
public | function | @covers ::convert @covers ::doConvert @covers ::validateParameterDefinition @covers ::getConverterDefinitionConstraint @covers ::getConverterDefinition @covers ::getConverterDefinitionKey @covers ::__construct | |
PluginTypeConverterTest:: |
public | function | @covers ::convert @covers ::doConvert @covers ::validateParameterDefinition @covers ::getConverterDefinitionConstraint @covers ::getConverterDefinition @covers ::getConverterDefinitionKey @covers ::__construct | |
PluginTypeConverterTest:: |
public | function | @covers ::convert @covers ::doConvert @covers ::validateParameterDefinition @covers ::getConverterDefinitionConstraint @covers ::getConverterDefinition @covers ::getConverterDefinitionKey @covers ::__construct | |
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. |