function FactoryTest::testDefaultFactory

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Plugin/FactoryTest.php \Drupal\KernelTests\Core\Plugin\FactoryTest::testDefaultFactory()
  2. 10 core/tests/Drupal/KernelTests/Core/Plugin/FactoryTest.php \Drupal\KernelTests\Core\Plugin\FactoryTest::testDefaultFactory()
  3. 11.x core/tests/Drupal/KernelTests/Core/Plugin/FactoryTest.php \Drupal\KernelTests\Core\Plugin\FactoryTest::testDefaultFactory()

Test that DefaultFactory can create a plugin instance.

File

core/tests/Drupal/KernelTests/Core/Plugin/FactoryTest.php, line 22

Class

FactoryTest
Tests that plugins are correctly instantiated.

Namespace

Drupal\KernelTests\Core\Plugin

Code

public function testDefaultFactory() {
    // Ensure a non-derivative plugin can be instantiated.
    $plugin = $this->testPluginManager
        ->createInstance('user_login', [
        '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 (\Exception $e) {
        $this->assertInstanceOf(ExceptionInterface::class, $e);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.