PluginTypeExampleTest.php in Examples for Developers 8
File
plugin_type_example/tests/src/Functional/PluginTypeExampleTest.php
View source
<?php
namespace Drupal\Tests\plugin_type_example\Functional;
use Drupal\plugin_type_example\Plugin\Sandwich\ExampleHamSandwich;
use Drupal\Tests\examples\Functional\ExamplesBrowserTestBase;
class PluginTypeExampleTest extends ExamplesBrowserTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'plugin_type_example',
];
protected $profile = 'minimal';
public function testPluginExample() {
$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.');
$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.');
$plugin = $manager
->createInstance('ham_sandwich', [
'of' => 'configuration values',
]);
$this
->assertInstanceOf(ExampleHamSandwich::class, $plugin);
$meatball = $manager
->createInstance('meatball_sandwich');
$ref_day = new \ReflectionProperty($meatball, 'day');
$ref_day
->setAccessible(TRUE);
$ref_day
->setValue($meatball, 'Sun');
$this
->assertEqual($meatball
->description(), 'Italian style meatballs drenched in irresistible marinara sauce, served on day old bread.');
}
public function testPluginExamplePage() {
$assert = $this
->assertSession();
$this
->drupalGet('examples/plugin-type-example');
$assert
->statusCodeEquals(200);
$assert
->pageTextContains('ham_sandwich', 'The plugin ID was not output.');
$assert
->pageTextContains('Ham, mustard, rocket, sun-dried tomatoes.', 'The plugin description was not output.');
}
}