TestPluginManager example

public function testDefaultPluginManagerWithPluginExtendingNonInstalledClass() {
    $definitions = [];
    $definitions['extending_non_installed_class'] = [
      'id' => 'extending_non_installed_class',
      'label' => 'A plugin whose class is extending from a non-installed module class',
      'color' => 'pink',
      'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\ExtendingNonInstalledClass',
      'provider' => 'plugin_test',
    ];

    $module_handler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
    $plugin_manager = new TestPluginManager($this->namespaces, $definitions$module_handler, 'test_alter_hook', '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface');
    $plugin_manager->getDefinition('plugin_test', FALSE);
    $this->assertTrue(TRUE, 'No PHP fatal error occurred when retrieving the definitions of a module with plugins that depend on a non-installed module class should not cause a PHP fatal.');
  }

  /** * Tests the plugin manager with a disabled module. */
  public function testDefaultPluginManagerWithDisabledModule() {
    $definitions = $this->expectedDefinitions;
    $definitions['cherry'] = [
      'id' => 'cherry',
      
protected function setUp(): void {
    parent::setUp();

    // Real modules implementing plugin types may expose a module-specific API     // for retrieving each type's plugin manager, or make them available in     // Drupal's dependency injection container, but for unit testing, we get     // the managers directly.     // - TestPluginManager is a bare bones manager with no support for     // derivatives, and uses DefaultFactory for plugin instantiation.     // - MockBlockManager is used for testing more advanced functionality such     // as derivatives and ReflectionFactory.     $this->testPluginManager = new TestPluginManager();
    $this->mockBlockManager = new MockBlockManager();
    $module_handler = new ModuleHandler($this->root, []new MemoryBackend());
    $this->defaultsTestPluginManager = new DefaultsTestPluginManager($module_handler);

    // The expected plugin definitions within each manager. Several tests assert     // that these plugins and their definitions are found and returned by the     // necessary API functions.     // @see TestPluginManager::_construct().     // @see MockBlockManager::_construct().     $this->testPluginExpectedDefinitions = [
      'user_login' => [
        
Home | Imprint | This part of the site doesn't use cookies.