function PluginTypeExampleTest::testPluginExample
Same name in other branches
- 8.x-1.x plugin_type_example/tests/src/Functional/PluginTypeExampleTest.php \Drupal\Tests\plugin_type_example\Functional\PluginTypeExampleTest::testPluginExample()
- 4.0.x modules/plugin_type_example/tests/src/Functional/PluginTypeExampleTest.php \Drupal\Tests\plugin_type_example\Functional\PluginTypeExampleTest::testPluginExample()
Test the plugin manager can be loaded, and the plugins are registered.
@todo https://www.drupal.org/project/examples/issues/2985705
File
-
modules/
plugin_type_example/ tests/ src/ Functional/ PluginTypeExampleTest.php, line 42
Class
- PluginTypeExampleTest
- Test the functionality of the Plugin Type Example module.
Namespace
Drupal\Tests\plugin_type_example\FunctionalCode
public function testPluginExample() {
/** @var \Drupal\plugin_type_example\SandwichPluginManager $manager */
$manager = $this->container
->get('plugin.manager.sandwich');
$sandwich_plugin_definitions = $manager->getDefinitions();
$this->assertCount(2, $sandwich_plugin_definitions, 'There are not two sandwich plugins defined.');
// Check some of the properties of the ham sandwich plugin definition.
$sandwich_plugin_definition = $sandwich_plugin_definitions['ham_sandwich'];
$this->assertEquals(426, $sandwich_plugin_definition['calories'], 'The ham sandwich plugin definition\'s calories property is not set.');
// Create an instance of the ham sandwich plugin to check it works.
$plugin = $manager->createInstance('ham_sandwich', [
'of' => 'configuration values',
]);
$this->assertInstanceOf(ExampleHamSandwich::class, $plugin);
// Create a meatball sandwich so we can check it's special behavior on
// Sundays.
/** @var \Drupal\plugin_type_example\SandwichInterface $meatball */
$meatball = $manager->createInstance('meatball_sandwich');
// Set the $day property to 'Sun'.
$ref_day = new \ReflectionProperty($meatball, 'day');
$ref_day->setAccessible(TRUE);
$ref_day->setValue($meatball, 'Sun');
// Check the special description on Sunday.
$this->assertEquals($meatball->description(), 'Italian style meatballs drenched in irresistible marinara sauce, served on day old bread.');
}