class CategorizingPluginManagerTraitTest in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Plugin/CategorizingPluginManagerTraitTest.php \Drupal\Tests\Core\Plugin\CategorizingPluginManagerTraitTest
@coversDefaultClass \Drupal\Core\Plugin\CategorizingPluginManagerTrait @group Plugin
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Plugin\CategorizingPluginManagerTraitTest
Expanded class hierarchy of CategorizingPluginManagerTraitTest
File
- core/
tests/ Drupal/ Tests/ Core/ Plugin/ CategorizingPluginManagerTraitTest.php, line 20 - Contains \Drupal\Tests\Core\Plugin\CategorizingPluginManagerTraitTest.
Namespace
Drupal\Tests\Core\PluginView source
class CategorizingPluginManagerTraitTest extends UnitTestCase {
/**
* The plugin manager to test.
*
* @var \Drupal\Component\Plugin\CategorizingPluginManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $pluginManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
$module_handler = $this
->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$module_handler
->expects($this
->any())
->method('getModuleList')
->willReturn([
'node' => [],
]);
$module_handler
->expects($this
->any())
->method('getName')
->with('node')
->willReturn('Node');
$this->pluginManager = new CategorizingPluginManager($module_handler);
$this->pluginManager
->setStringTranslation($this
->getStringTranslationStub());
}
/**
* @covers ::getCategories
*/
public function testGetCategories() {
$this
->assertSame(array_values($this->pluginManager
->getCategories()), [
'fruits',
'vegetables',
]);
}
/**
* @covers ::getSortedDefinitions
*/
public function testGetSortedDefinitions() {
$sorted = $this->pluginManager
->getSortedDefinitions();
$this
->assertSame(array_keys($sorted), [
'apple',
'mango',
'cucumber',
]);
}
/**
* @covers ::getGroupedDefinitions
*/
public function testGetGroupedDefinitions() {
$grouped = $this->pluginManager
->getGroupedDefinitions();
$this
->assertSame(array_keys($grouped), [
'fruits',
'vegetables',
]);
$this
->assertSame(array_keys($grouped['fruits']), [
'apple',
'mango',
]);
$this
->assertSame(array_keys($grouped['vegetables']), [
'cucumber',
]);
}
/**
* @covers ::processDefinitionCategory
*/
public function testProcessDefinitionCategory() {
// Existing category.
$definition = [
'label' => 'some',
'provider' => 'core',
'category' => 'bag',
];
$this->pluginManager
->processDefinition($definition, 'some');
$this
->assertSame($definition['category'], 'bag');
// No category, provider without label.
$definition = [
'label' => 'some',
'provider' => 'core',
];
$this->pluginManager
->processDefinition($definition, 'some');
$this
->assertSame($definition['category'], 'core');
// No category, provider is module with label.
$definition = [
'label' => 'some',
'provider' => 'node',
];
$this->pluginManager
->processDefinition($definition, 'some');
$this
->assertSame($definition['category'], 'Node');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CategorizingPluginManagerTraitTest:: |
protected | property | The plugin manager to test. | |
CategorizingPluginManagerTraitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
CategorizingPluginManagerTraitTest:: |
public | function | @covers ::getCategories | |
CategorizingPluginManagerTraitTest:: |
public | function | @covers ::getGroupedDefinitions | |
CategorizingPluginManagerTraitTest:: |
public | function | @covers ::getSortedDefinitions | |
CategorizingPluginManagerTraitTest:: |
public | function | @covers ::processDefinitionCategory | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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. |