ModuleHandler example

// 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' => [
        'label' => 'User login',
        'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockUserLoginBlock',
      ],

  protected function getModuleHandler() {
    $module_handler = new ModuleHandler($this->root, [
      'module_handler_test' => [
        'type' => 'module',
        'pathname' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml',
        'filename' => 'module_handler_test.module',
      ],
    ]$this->cacheBackend);
    return $module_handler;
  }

  /** * Tests loading a module. * * @covers ::load */
Home | Imprint | This part of the site doesn't use cookies.