diff --git a/commands/web/drupal b/commands/web/drupal index de9bbe8..6f88c66 100755 --- a/commands/web/drupal +++ b/commands/web/drupal @@ -25,6 +25,7 @@ use DrupalCoreDev\Command\LintPhpCsCommand; use DrupalCoreDev\Command\LintPhpStanCommand; use DrupalCoreDev\Command\ModuleInstallCommand; use DrupalCoreDev\Command\TestBrowserCommand; +use DrupalCoreDev\Command\TestExtensionsCommand; use DrupalCoreDev\Command\TestCommand; use DrupalCoreDev\Command\UninstallCommand; use Symfony\Component\Console\Application; @@ -46,6 +47,7 @@ $application->add(new CacheCommand($loader)); $application->add(new AdminLoginCommand($loader)); $application->add(new GenerateTheme()); $application->add(new TestCommand()); +$application->add(new TestExtensionsCommand()); $application->add(new TestBrowserCommand()); $application->add(new LintPhpCsCommand()); $application->add(new LintPhpStanCommand()); diff --git a/core-dev/src/Command/ModuleInstallCommand.php b/core-dev/src/Command/ModuleInstallCommand.php index d6f8de5..b6dc17e 100644 --- a/core-dev/src/Command/ModuleInstallCommand.php +++ b/core-dev/src/Command/ModuleInstallCommand.php @@ -29,6 +29,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $module_installer = \Drupal::service('module_installer'); assert($module_installer instanceof ModuleInstallerInterface); $module_installer->install($modules); + $kernel = \Drupal::service('kernel'); + $kernel->rebuildContainer(); } return 0; } diff --git a/core-dev/src/Command/TestExtensionsCommand.php b/core-dev/src/Command/TestExtensionsCommand.php new file mode 100644 index 0000000..bb7484a --- /dev/null +++ b/core-dev/src/Command/TestExtensionsCommand.php @@ -0,0 +1,65 @@ +setName('test:extensions-enable') + ->setDescription('Allow test modules and themes to be installed'); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output): int { + $io = new SymfonyStyle($input, $output); + $setting = "\$settings['extension_discovery_scan_tests'] = TRUE;\n"; + $file = __DIR__ . '/../../../../sites/default/settings.php'; + $data = file_get_contents($file); + if (str_contains($data, $setting)) { + return 0; + } + + $mode = null; + if (!is_writable($file)) { + try { + $stat = stat($file); + chmod($file, 0744); + } + catch (\Error $e) { + $io->getErrorStyle()->error("Could not set $file to writeable"); + return 1; + } + $mode = $stat['mode'] & 000777; + } + + + file_put_contents($file, $setting, FILE_APPEND); + $output->writeln('extension_discovery_scan_tests enabled in settings.php'); + + if (!is_null($mode)) { + // Reverse the array of unhardened paths because we want to change the + // child item before the parent item. + try { + chmod($file, $mode); + } + catch (\Error $e) { + $io->getErrorStyle()->error("Unable to reharden permissions for $file"); + return 1; + } + } + + return 0; + } +} diff --git a/install.yaml b/install.yaml index c70c41c..217a555 100644 --- a/install.yaml +++ b/install.yaml @@ -17,6 +17,7 @@ project_files: - core-dev/src/Command/CacheCommand.php - core-dev/src/Command/TestCommand.php - core-dev/src/Command/TestBrowserCommand.php + - core-dev/src/Command/TestExtensionsCommand.php - core-dev/src/Command/UninstallCommand.php - core-dev/src/Command/LintPhpCsCommand.php - core-dev/src/Command/LintPhpStanCommand.php