public function ListPluginTypesTest::testExecute in Plugin 8.2
@covers ::execute
File
- tests/
src/ Unit/ Controller/ ListPluginTypesTest.php, line 104
Class
- ListPluginTypesTest
- @coversDefaultClass \Drupal\plugin\Controller\ListPluginTypes
Namespace
Drupal\Tests\plugin\Unit\ControllerCode
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);
}