class ListPluginTypesTest in Plugin 8.2
@coversDefaultClass \Drupal\plugin\Controller\ListPluginTypes
@group Plugin
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\plugin\Unit\Controller\ListPluginTypesTest
Expanded class hierarchy of ListPluginTypesTest
File
- tests/
src/ Unit/ Controller/ ListPluginTypesTest.php, line 21
Namespace
Drupal\Tests\plugin\Unit\ControllerView source
class ListPluginTypesTest extends UnitTestCase {
/**
* The service container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $container;
/**
* The class under test.
*
* @var \Drupal\plugin\Controller\ListPluginTypes
*/
protected $sut;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $currentUser;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $moduleHandler;
/**
* The plugin type manager.
*
* @var \Drupal\plugin\PluginType\PluginTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $pluginTypeManager;
/**
* The string translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected $stringTranslation;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->container = $this
->prophesize(ContainerInterface::class);
$this->moduleHandler = $this
->createMock(ModuleHandlerInterface::class);
$this->pluginTypeManager = $this
->createMock(PluginTypeManagerInterface::class);
$this->stringTranslation = new TranslationMock();
$this->sut = new ListPluginTypes($this->stringTranslation, $this->moduleHandler, $this->pluginTypeManager);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = [
[
'module_handler',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->moduleHandler,
],
[
'plugin.plugin_type_manager',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->pluginTypeManager,
],
[
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
],
];
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$sut = ListPluginTypes::create($container);
$this
->assertInstanceOf(ListPluginTypes::class, $sut);
}
/**
* @covers ::execute
*/
public function testExecute() {
$class_resolver = $this
->createMock(ClassResolverInterface::class);
$typed_config_manager = $this
->createMock(TypedConfigManagerInterface::class);
$typed_config_manager
->expects($this
->atLeastOnce())
->method('hasConfigSchema')
->willReturn(TRUE);
$plugin_type_id_a = $this
->randomMachineName();
$plugin_type_label_a = $this
->randomMachineName();
$plugin_type_description_a = $this
->randomMachineName();
$plugin_type_definition_a = [
'id' => $plugin_type_id_a,
'label' => $plugin_type_label_a,
'description' => $plugin_type_description_a,
'provider' => $this
->randomMachineName(),
'plugin_manager_service_id' => 'foo.bar',
];
$plugin_type_a = new PluginType($plugin_type_definition_a, $this->container
->reveal(), $this->stringTranslation, $class_resolver, $typed_config_manager);
$plugin_type_id_b = $this
->randomMachineName();
$plugin_type_label_b = $this
->randomMachineName();
$plugin_type_description_b = '';
$plugin_type_definition_b = [
'id' => $plugin_type_id_b,
'label' => $plugin_type_label_b,
'description' => $plugin_type_description_b,
'provider' => $this
->randomMachineName(),
'plugin_manager_service_id' => 'foo.bar',
];
$plugin_type_b = new PluginType($plugin_type_definition_b, $this->container
->reveal(), $this->stringTranslation, $class_resolver, $typed_config_manager);
$plugin_types = [
$plugin_type_id_a => $plugin_type_a,
$plugin_type_id_b => $plugin_type_b,
];
$this->pluginTypeManager
->expects($this
->atLeastOnce())
->method('getPluginTypes')
->willReturn($plugin_types);
$build = $this->sut
->execute();
$this
->assertSame((string) $build[$plugin_type_id_a]['label']['#markup'], $plugin_type_label_a);
$this
->assertSame((string) $build[$plugin_type_id_a]['description']['#markup'], $plugin_type_description_a);
$this
->assertSame((string) $build[$plugin_type_id_b]['label']['#markup'], $plugin_type_label_b);
$this
->assertSame((string) $build[$plugin_type_id_b]['description']['#markup'], $plugin_type_description_b);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ListPluginTypesTest:: |
protected | property | The service container. | |
ListPluginTypesTest:: |
protected | property | The current user. | |
ListPluginTypesTest:: |
protected | property | The module handler. | |
ListPluginTypesTest:: |
protected | property | The plugin type manager. | |
ListPluginTypesTest:: |
protected | property | The string translator. | |
ListPluginTypesTest:: |
protected | property | The class under test. | |
ListPluginTypesTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ListPluginTypesTest:: |
function | @covers ::create @covers ::__construct | ||
ListPluginTypesTest:: |
public | function | @covers ::execute | |
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. |