class PluginTypeExampleTest
Same name in other branches
- 3.x modules/plugin_type_example/tests/src/Functional/PluginTypeExampleTest.php \Drupal\Tests\plugin_type_example\Functional\PluginTypeExampleTest
- 4.0.x modules/plugin_type_example/tests/src/Functional/PluginTypeExampleTest.php \Drupal\Tests\plugin_type_example\Functional\PluginTypeExampleTest
Test the functionality of the Plugin Type Example module.
@group plugin_type_example @group examples
Hierarchy
- class \Drupal\Tests\examples\Functional\ExamplesBrowserTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\plugin_type_example\Functional\PluginTypeExampleTest extends \Drupal\Tests\examples\Functional\ExamplesBrowserTestBase
Expanded class hierarchy of PluginTypeExampleTest
Related topics
File
-
plugin_type_example/
tests/ src/ Functional/ PluginTypeExampleTest.php, line 16
Namespace
Drupal\Tests\plugin_type_example\FunctionalView source
class PluginTypeExampleTest extends ExamplesBrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'plugin_type_example',
];
/**
* The installation profile to use with this test.
*
* @var string
*/
protected $profile = 'minimal';
/**
* Test the plugin manager can be loaded, and the plugins are registered.
*
* @todo: https://www.drupal.org/project/examples/issues/2985705
*/
public function testPluginExample() {
/* @var $manager \Drupal\plugin_type_example\SandwichPluginManager */
$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 $meatball \Drupal\plugin_type_example\SandwichInterface */
$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->assertEqual($meatball->description(), 'Italian style meatballs drenched in irresistible marinara sauce, served on day old bread.');
}
/**
* Test the output of the example page.
*/
public function testPluginExamplePage() {
$assert = $this->assertSession();
$this->drupalGet('examples/plugin-type-example');
$assert->statusCodeEquals(200);
// Check we see the plugin id.
$assert->pageTextContains('ham_sandwich', 'The plugin ID was not output.');
// Check we see the plugin description.
$assert->pageTextContains('Ham, mustard, rocket, sun-dried tomatoes.', 'The plugin description was not output.');
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
ExamplesBrowserTestBase::setUp | protected | function | 4 | ||
ExamplesBrowserTestBase::setupExamplesMenus | protected | function | Set up menus and tasks in their regions. | ||
PluginTypeExampleTest::$defaultTheme | protected | property | |||
PluginTypeExampleTest::$modules | public static | property | Modules to enable. | Overrides ExamplesBrowserTestBase::$modules | |
PluginTypeExampleTest::$profile | protected | property | The installation profile to use with this test. | ||
PluginTypeExampleTest::testPluginExample | public | function | Test the plugin manager can be loaded, and the plugins are registered. | ||
PluginTypeExampleTest::testPluginExamplePage | public | function | Test the output of the example page. |