PluginTypeExampleTest.php
Namespace
Drupal\Tests\plugin_type_example\Functional
File
-
modules/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';
protected 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->assertEquals($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');
$assert->pageTextContains('Ham, mustard, rocket, sun-dried tomatoes.');
}
}
Classes