function FactoryTest::testDefaultFactory in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Plugin/FactoryTest.php \Drupal\system\Tests\Plugin\FactoryTest::testDefaultFactory()
Test that DefaultFactory can create a plugin instance.
File
- core/
modules/ system/ src/ Tests/ Plugin/ FactoryTest.php, line 22 - Contains \Drupal\system\Tests\Plugin\FactoryTest.
Class
- FactoryTest
- Tests that plugins are correctly instantiated.
Namespace
Drupal\system\Tests\PluginCode
function testDefaultFactory() {
// Ensure a non-derivative plugin can be instantiated.
$plugin = $this->testPluginManager
->createInstance('user_login', array(
'title' => 'Please enter your login name and password',
));
$this
->assertIdentical(get_class($plugin), 'Drupal\\plugin_test\\Plugin\\plugin_test\\mock_block\\MockUserLoginBlock', 'Correct plugin class instantiated with default factory.');
$this
->assertIdentical($plugin
->getTitle(), 'Please enter your login name and password', 'Plugin instance correctly configured.');
// Ensure that attempting to instantiate non-existing plugins throws a
// PluginException.
try {
$this->testPluginManager
->createInstance('non_existing');
$this
->fail('Drupal\\Component\\Plugin\\Exception\\ExceptionInterface expected');
} catch (ExceptionInterface $e) {
$this
->pass('Drupal\\Component\\Plugin\\Exception\\ExceptionInterface expected and caught.');
} catch (\Exception $e) {
$this
->fail('Drupal\\Component\\Plugin\\Exception\\ExceptionInterface expected, but ' . get_class($e) . ' was thrown.');
}
}