3 namespace Drupal\KernelTests\Core\Plugin;
6 * Tests that plugins implementing PluginInspectionInterface are inspectable.
10 class InspectionTest extends PluginTestBase {
15 public static $modules = ['node', 'user'];
18 * Ensure the test plugins correctly implement getPluginId() and getPluginDefinition().
20 public function testInspection() {
21 foreach (['user_login'] as $id) {
22 $plugin = $this->testPluginManager->createInstance($id);
23 $expected_definition = $this->testPluginExpectedDefinitions[$id];
24 $this->assertIdentical($plugin->getPluginId(), $id);
25 $this->assertIdentical($this->testPluginManager->getDefinition($id), $expected_definition);
26 $this->assertIdentical($plugin->getPluginDefinition(), $expected_definition);
28 // Skip the 'menu' derived blocks, because MockMenuBlock does not implement
29 // PluginInspectionInterface. The others do by extending PluginBase.
30 foreach (['user_login', 'layout'] as $id) {
31 $plugin = $this->mockBlockManager->createInstance($id);
32 $expected_definition = $this->mockBlockExpectedDefinitions[$id];
33 $this->assertIdentical($plugin->getPluginId(), $id);
34 $this->assertIdentical($this->castSafeStrings($this->mockBlockManager->getDefinition($id)), $expected_definition);
35 $this->assertIdentical($this->castSafeStrings($plugin->getPluginDefinition()), $expected_definition);
37 // Test a plugin manager that provides defaults.
38 foreach (['test_block1', 'test_block2'] as $id) {
39 $plugin = $this->defaultsTestPluginManager->createInstance($id);
40 $expected_definition = $this->defaultsTestPluginExpectedDefinitions[$id];
41 $this->assertIdentical($plugin->getPluginId(), $id);
42 $this->assertIdentical($this->defaultsTestPluginManager->getDefinition($id), $expected_definition);
43 $this->assertIdentical($this->castSafeStrings($plugin->getPluginDefinition()), $expected_definition);