loadAll example

/** * Tests loading all modules. * * @covers ::loadAll */
  public function testLoadAllModules() {
    $module_handler = $this->getModuleHandler();
    $module_handler->addModule('module_handler_test_all1', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_all1');
    $module_handler->addModule('module_handler_test_all2', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_all2');
    $this->assertFalse(function_exists('module_handler_test_all1_hook'), 'Function does not exist before being loaded.');
    $this->assertFalse(function_exists('module_handler_test_all2_hook'), 'Function does not exist before being loaded.');
    $module_handler->loadAll();
    $this->assertTrue(function_exists('module_handler_test_all1_hook'), 'Function exists after being loaded.');
    $this->assertTrue(function_exists('module_handler_test_all2_hook'), 'Function exists after being loaded.');
  }

  /** * Tests reload method. * * @covers ::reload */
  public function testModuleReloading() {
    $module_handler = $this->getMockBuilder(ModuleHandler::class)
      
// Remove Drupal's error/exception handlers; they are designed for HTML     // and there is no storage nor a (watchdog) logger here.     restore_error_handler();
    restore_exception_handler();

    // In addition, ensure that PHP errors are not hidden away in logs.     ini_set('display_errors', TRUE);

    parent::boot();

    $this->getContainer()->get('module_handler')->loadAll();

    $test_discovery = new TestDiscovery(
      $this->getContainer()->getParameter('app.root'),
      $this->getContainer()->get('class_loader')
    );
    $test_discovery->registerTestNamespaces();

    // Register stream wrappers.     $this->getContainer()->get('stream_wrapper_manager')->register();

    // Create the build/artifacts directory if necessary.
    // extensions own default config directories.     \Drupal::service('config.installer')
      ->setSourceStorage($this->storageComparer->getSourceStorage());
    if ($type == 'module') {
      $this->moduleInstaller->$op([$name], FALSE);
      // Installing a module can cause a kernel boot therefore reinject all the       // services.       $this->reInjectMe();
      // During a module install or uninstall the container is rebuilt and the       // module handler is called. This causes the container's instance of the       // module handler not to have loaded all the enabled modules.       $this->moduleHandler->loadAll();
    }
    if ($type == 'theme') {
      // Theme uninstalls possible remove default or admin themes therefore we       // need to import this before doing any. If there are no uninstalls and       // the default or admin theme is changing this will be picked up whilst       // processing configuration.       if ($op == 'uninstall' && $this->processedSystemTheme === FALSE) {
        $this->importConfig(StorageInterface::DEFAULT_COLLECTION, 'update', 'system.theme');
        $this->configManager->getConfigFactory()->reset('system.theme');
        $this->processedSystemTheme = TRUE;
      }
      
$this->load($name);
      }
      $this->loaded = TRUE;
    }
  }

  /** * {@inheritdoc} */
  public function reload() {
    $this->loaded = FALSE;
    $this->loadAll();
  }

  /** * {@inheritdoc} */
  public function isLoaded() {
    return $this->loaded;
  }

  /** * {@inheritdoc} */
public function preHandle(Request $request) {
    // Sanitize the request.     $request = RequestSanitizer::sanitize(
      $request,
      (array) Settings::get(RequestSanitizer::SANITIZE_INPUT_SAFE_KEYS, []),
      (bool) Settings::get(RequestSanitizer::SANITIZE_LOG, FALSE)
    );

    $this->loadLegacyIncludes();

    // Load all enabled modules.     $this->container->get('module_handler')->loadAll();

    // Register stream wrappers.     $this->container->get('stream_wrapper_manager')->register();

    // Initialize legacy request globals.     $this->initializeRequestGlobals($request);

    // Put the request on the stack.     $this->container->get('request_stack')->push($request);

    // Set the allowed protocols.
$this->container = $kernel->getContainer();

    // Run database tasks and check for errors.     $installer_class = $namespace . "\\Install\\Tasks";
    $errors = (new $installer_class())->runTasks();
    if (!empty($errors)) {
      $this->fail('Failed to run installer database tasks: ' . implode(', ', $errors));
    }

    if ($modules) {
      $this->container->get('module_handler')->loadAll();
    }

    // Setup the destination to the be frontpage by default.     \Drupal::destination()->set('/');

    // Write the core.extension configuration.     // Required for ConfigInstaller::installDefaultConfig() to work.     $this->container->get('config.storage')->write('core.extension', [
      'module' => array_fill_keys($modules, 0),
      'theme' => [],
      'profile' => '',
    ]);
Home | Imprint | This part of the site doesn't use cookies.