setModuleList example

// Move ban to the end of the array.     unset($module_list[array_search('ban', $module_list)]);
    $module_list[] = 'ban';
    $this->assertModuleList($module_list, 'After changing weights');

    // Test the fixed list feature.     $fixed_list = [
      'system' => 'core/modules/system/system.module',
      'menu' => 'core/modules/menu/menu.module',
    ];
    $this->moduleHandler()->setModuleList($fixed_list);
    $new_module_list = array_combine(array_keys($fixed_list)array_keys($fixed_list));
    $this->assertModuleList($new_module_list, 'When using a fixed list');
  }

  /** * Assert that the extension handler returns the expected values. * * @param array $expected_values * The expected values, sorted by weight and module name. * @param string $condition * The condition being tested, such as 'After adding a module'. * * @internal */
    $module_handler = $this->container->get('module_handler');
    $module_filenames = $module_handler->getModuleList();
    $extension_config = $this->config('core.extension');
    foreach ($modules as $module) {
      if (!$module_handler->moduleExists($module)) {
        throw new \LogicException("$module module cannot be uninstalled because it is not installed.");
      }
      unset($module_filenames[$module]);
      $extension_config->clear('module.' . $module);
    }
    $extension_config->save();
    $module_handler->setModuleList($module_filenames);
    $module_handler->resetImplementations();
    // Update the kernel to remove their services.     $this->container->get('kernel')->updateModules($module_filenames$module_filenames);

    // Ensure isLoaded() is TRUE in order to make     // \Drupal\Core\Theme\ThemeManagerInterface::render() work.     // Note that the kernel has rebuilt the container; this $module_handler is     // no longer the $module_handler instance from above.     $module_handler = $this->container->get('module_handler');
    $module_handler->reload();
    foreach ($modules as $module) {
      

          else {
            $module_path = \Drupal::service('extension.list.module')->getPath($name);
            $pathname = "$module_path/$name.info.yml";
            $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL;
            $module_filenames[$name] = new Extension($this->root, 'module', $pathname$filename);
          }
        }

        // Update the module handler in order to have the correct module list         // for the kernel update.         $this->moduleHandler->setModuleList($module_filenames);

        // Clear the static cache of the "extension.list.module" service to pick         // up the new module, since it merges the installation status of modules         // into its statically cached list.         \Drupal::service('extension.list.module')->reset();

        // Update the kernel to include it.         $this->updateKernel($module_filenames);

        // Load the module's .module and .install files.         $this->moduleHandler->load($module);
        

      ->onlyMethods(['resetImplementations'])
      ->getMock();

    // Ensure we reset implementations when settings a new modules list.     $module_handler->expects($this->once())->method('resetImplementations');

    // Make sure we're starting empty.     $this->assertEquals([]$module_handler->getModuleList());

    // Replace the list with a prebuilt list.     $module_handler->setModuleList($fixture_module_handler->getModuleList());

    // Ensure those changes are stored.     $this->assertEquals($fixture_module_handler->getModuleList()$module_handler->getModuleList());
  }

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