class PluginSelectorBaseTest in Plugin 8.2
@coversDefaultClass \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorBase
@group Plugin
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\plugin\Unit\Plugin\Plugin\PluginSelector\PluginSelectorBaseTestBase
- class \Drupal\Tests\plugin\Unit\Plugin\Plugin\PluginSelector\PluginSelectorBaseTest
- class \Drupal\Tests\plugin\Unit\Plugin\Plugin\PluginSelector\PluginSelectorBaseTestBase
Expanded class hierarchy of PluginSelectorBaseTest
File
- tests/
src/ Unit/ Plugin/ Plugin/ PluginSelector/ PluginSelectorBaseTest.php, line 17
Namespace
Drupal\Tests\plugin\Unit\Plugin\Plugin\PluginSelectorView source
class PluginSelectorBaseTest extends PluginSelectorBaseTestBase {
/**
* The class under test.
*
* @var \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorBase|\PHPUnit_Framework_MockObject_MockObject
*/
protected $sut;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$configuration = [];
$this->sut = $this
->getMockBuilder(PluginSelectorBase::class)
->setConstructorArgs([
$configuration,
$this->pluginId,
$this->pluginDefinition,
$this->defaultPluginResolver,
])
->getMockForAbstractClass();
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = [
[
'plugin.default_plugin_resolver',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->defaultPluginResolver,
],
];
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
/** @var \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorBase $class */
$class = get_class($this->sut);
$plugin = $class::create($container, [], $this->pluginId, $this->pluginDefinition);
$this
->assertInstanceOf(get_class($this->sut), $plugin);
}
/**
* @covers ::defaultConfiguration
*/
public function testDefaultConfiguration() {
$configuration = $this->sut
->defaultConfiguration();
$this
->assertIsArray($configuration);
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies() {
$this
->assertSame([], $this->sut
->calculateDependencies());
}
/**
* @covers ::setConfiguration
* @covers ::getConfiguration
*/
public function testGetConfiguration() {
$configuration = array(
$this
->randomMachineName(),
);
$this
->assertSame($this->sut, $this->sut
->setConfiguration($configuration));
$this
->assertSame($configuration, $this->sut
->getConfiguration());
}
/**
* @covers ::setLabel
* @covers ::getLabel
*/
public function testGetLabel() {
$label = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setLabel($label));
$this
->assertSame($label, $this->sut
->getLabel());
}
/**
* @covers ::setDescription
* @covers ::getDescription
*/
public function testGetDescription() {
$description = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setDescription($description));
$this
->assertSame($description, $this->sut
->getDescription());
}
/**
* @covers ::setCollectPluginConfiguration
* @covers ::getCollectPluginConfiguration
*/
public function testGetCollectPluginConfiguration() {
$collect = (bool) mt_rand(0, 1);
$this
->assertSame($this->sut, $this->sut
->setCollectPluginConfiguration($collect));
$this
->assertSame($collect, $this->sut
->getCollectPluginConfiguration());
}
/**
* @covers ::setPreviouslySelectedPlugins
* @covers ::getPreviouslySelectedPlugins
*/
public function testGetPreviouslySelectedPlugins() {
$plugin = $this
->createMock(PluginInspectionInterface::class);
$this->sut
->setPreviouslySelectedPlugins([
$plugin,
]);
$this
->assertSame([
$plugin,
], $this->sut
->getPreviouslySelectedPlugins());
}
/**
* @covers ::setKeepPreviouslySelectedPlugins
* @covers ::getKeepPreviouslySelectedPlugins
*
* @depends testGetPreviouslySelectedPlugins
*/
public function testGetKeepPreviouslySelectedPlugins() {
$keep = (bool) mt_rand(0, 1);
$plugin = $this
->createMock(PluginInspectionInterface::class);
$this->sut
->setPreviouslySelectedPlugins([
$plugin,
]);
$this
->assertSame($this->sut, $this->sut
->setKeepPreviouslySelectedPlugins($keep));
$this
->assertSame($keep, $this->sut
->getKeepPreviouslySelectedPlugins());
// Confirm that all previously selected plugins are removed.
$this->sut
->setPreviouslySelectedPlugins([
$plugin,
]);
$this->sut
->setKeepPreviouslySelectedPlugins(FALSE);
$this
->assertEmpty($this->sut
->getPreviouslySelectedPlugins());
}
/**
* @covers ::setSelectedPlugin
* @covers ::getSelectedPlugin
*/
public function testGetSelectedPlugin() {
$this->sut
->setSelectablePluginType($this->selectablePluginType);
$plugin = $this
->createMock(PluginInspectionInterface::class);
$this
->assertSame($this->sut, $this->sut
->setSelectedPlugin($plugin));
$this
->assertSame($plugin, $this->sut
->getSelectedPlugin());
}
/**
* @covers ::setRequired
* @covers ::isRequired
*/
public function testGetRequired() {
$this
->assertFalse($this->sut
->isRequired());
$this
->assertSame($this->sut, $this->sut
->setRequired());
$this
->assertTrue($this->sut
->isRequired());
$this->sut
->setRequired(FALSE);
$this
->assertFalse($this->sut
->isRequired());
}
/**
* @covers ::buildSelectorForm
* @covers ::setSelectablePluginType
*/
public function testBuildSelectorForm() {
$this->sut
->setSelectablePluginType($this->selectablePluginType);
$form = [];
$form_state = new FormState();
$form = $this->sut
->buildSelectorForm($form, $form_state);
$this
->assertIsArray($form);
}
}
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. | |
PluginSelectorBaseTest:: |
protected | property |
The class under test. Overrides PluginSelectorBaseTestBase:: |
|
PluginSelectorBaseTest:: |
protected | function |
Overrides PluginSelectorBaseTestBase:: |
|
PluginSelectorBaseTest:: |
public | function | @covers ::buildSelectorForm @covers ::setSelectablePluginType | |
PluginSelectorBaseTest:: |
public | function | @covers ::calculateDependencies | |
PluginSelectorBaseTest:: |
function | @covers ::create @covers ::__construct | ||
PluginSelectorBaseTest:: |
public | function | @covers ::defaultConfiguration | |
PluginSelectorBaseTest:: |
public | function | @covers ::setCollectPluginConfiguration @covers ::getCollectPluginConfiguration | |
PluginSelectorBaseTest:: |
public | function | @covers ::setConfiguration @covers ::getConfiguration | |
PluginSelectorBaseTest:: |
public | function | @covers ::setDescription @covers ::getDescription | |
PluginSelectorBaseTest:: |
public | function | @covers ::setKeepPreviouslySelectedPlugins @covers ::getKeepPreviouslySelectedPlugins | |
PluginSelectorBaseTest:: |
public | function | @covers ::setLabel @covers ::getLabel | |
PluginSelectorBaseTest:: |
public | function | @covers ::setPreviouslySelectedPlugins @covers ::getPreviouslySelectedPlugins | |
PluginSelectorBaseTest:: |
public | function | @covers ::setRequired @covers ::isRequired | |
PluginSelectorBaseTest:: |
public | function | @covers ::setSelectedPlugin @covers ::getSelectedPlugin | |
PluginSelectorBaseTestBase:: |
protected | property | The default plugin resolver. | |
PluginSelectorBaseTestBase:: |
protected | property | The plugin definition of the class under test. | |
PluginSelectorBaseTestBase:: |
protected | property | The plugin ID of the class plugin under test. | |
PluginSelectorBaseTestBase:: |
protected | property | The plugin manager through which to select plugins. | |
PluginSelectorBaseTestBase:: |
protected | property | The plugin type of which to select plugins. | |
PluginSelectorBaseTestBase:: |
protected | property | The selected plugin. | |
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. |