From 0bb7bf20d90cac9050b4f780a191ea43a496c9d6 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Tue, 17 Feb 2026 18:18:28 +1100 Subject: [PATCH] Increased test coverage for Acquia env settings. --- .../tests/phpunit/Drupal/SettingsTestCase.php | 4 +- .../Drupal/EnvironmentSettingsTest.php | 56 ++++++++++++++++++- .../tests/phpunit/Drupal/SettingsTestCase.php | 2 +- .../Drupal/EnvironmentSettingsTest.php | 56 ++++++++++++++++++- .../tests/phpunit/Drupal/SettingsTestCase.php | 2 +- .../Drupal/EnvironmentSettingsTest.php | 55 ++++++++++++++++++ tests/phpunit/Drupal/SettingsTestCase.php | 4 +- 7 files changed, 171 insertions(+), 8 deletions(-) diff --git a/.vortex/installer/tests/Fixtures/handler_process/_baseline/tests/phpunit/Drupal/SettingsTestCase.php b/.vortex/installer/tests/Fixtures/handler_process/_baseline/tests/phpunit/Drupal/SettingsTestCase.php index f7d42a1fb..bd76e3775 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/_baseline/tests/phpunit/Drupal/SettingsTestCase.php +++ b/.vortex/installer/tests/Fixtures/handler_process/_baseline/tests/phpunit/Drupal/SettingsTestCase.php @@ -201,7 +201,7 @@ protected function unsetEnvVars(): void { /** * Require settings file. */ - protected function requireSettingsFile(): void { + protected function requireSettingsFile(array $pre_settings = []): void { $app_root = getcwd() . '/web'; if (!file_exists($app_root)) { @@ -210,7 +210,7 @@ protected function requireSettingsFile(): void { $site_path = 'sites/default'; $config = []; - $settings = []; + $settings = $pre_settings; $databases = []; require $app_root . DIRECTORY_SEPARATOR . $site_path . DIRECTORY_SEPARATOR . 'settings.php'; diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/tests/phpunit/Drupal/EnvironmentSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/tests/phpunit/Drupal/EnvironmentSettingsTest.php index 61b3e762a..d45f2d491 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/tests/phpunit/Drupal/EnvironmentSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/tests/phpunit/Drupal/EnvironmentSettingsTest.php @@ -49,7 +49,7 @@ ]; } -@@ -325,6 +369,229 @@ +@@ -325,6 +369,283 @@ $settings['skip_permissions_hardening'] = TRUE; $settings['config_sync_directory'] = '../config/default'; $settings['suspend_mail_send'] = TRUE; @@ -275,6 +275,60 @@ + 'bower_components', + ]; + $settings['hash_salt'] = hash('sha256', getenv('DATABASE_HOST') ?: 'localhost'); ++ $settings['maintenance_theme'] = 'claro'; ++ $settings['trusted_host_patterns'] = [ ++ '^localhost$', ++ ]; ++ $this->assertSettings($settings); ++ } ++ ++ /** ++ * Test Acquia config_sync_directory fallback to config_vcs_directory. ++ * ++ * When DRUPAL_CONFIG_PATH is not set but config_vcs_directory is provided ++ * by the Acquia-included settings file, config_sync_directory should fall ++ * back to config_vcs_directory. ++ */ ++ public function testEnvironmentAcquiaConfigVcsDirectoryFallback(): void { ++ $this->setEnvVars([ ++ 'AH_SITE_ENVIRONMENT' => 1, ++ ]); ++ ++ // Pre-seed config_vcs_directory to simulate the value set by the ++ // Acquia-included settings file from /var/www/site-php/. ++ $this->requireSettingsFile([ ++ 'config_vcs_directory' => '/var/www/site-php/mysite/config', ++ ]); ++ ++ $config['acquia_hosting_settings_autoconnect'] = FALSE; ++ $config['config_split.config_split.dev']['status'] = TRUE; ++ $config['environment_indicator.indicator']['bg_color'] = '#4caf50'; ++ $config['environment_indicator.indicator']['fg_color'] = '#000000'; ++ $config['environment_indicator.indicator']['name'] = self::ENVIRONMENT_DEV; ++ $config['environment_indicator.settings']['favicon'] = TRUE; ++ $config['environment_indicator.settings']['toolbar_integration'] = [TRUE]; ++ $config['robotstxt.settings']['content'] = "User-agent: *\nDisallow: /"; ++ $config['shield.settings']['shield_enable'] = TRUE; ++ $config['xmlsitemap.settings']['disable_cron_regeneration'] = TRUE; ++ $config['xmlsitemap_engines.settings']['submit'] = FALSE; ++ $config['system.performance']['cache']['page']['max_age'] = 900; ++ $this->assertConfig($config); ++ ++ $settings['auto_create_htaccess'] = TRUE; ++ $settings['config_exclude_modules'] = []; ++ $settings['config_sync_directory'] = '/var/www/site-php/mysite/config'; ++ $settings['config_vcs_directory'] = '/var/www/site-php/mysite/config'; ++ $settings['container_yamls'][0] = $this->app_root . '/' . $this->site_path . '/services.yml'; ++ $settings['entity_update_batch_size'] = 50; ++ $settings['environment'] = self::ENVIRONMENT_DEV; ++ $settings['file_public_path'] = 'sites/default/files'; ++ $settings['file_private_path'] = 'sites/default/files/private'; ++ $settings['file_temp_path'] = '/tmp'; ++ $settings['file_scan_ignore_directories'] = [ ++ 'node_modules', ++ 'bower_components', ++ ]; ++ $settings['hash_salt'] = hash('sha256', getenv('DATABASE_HOST') ?: 'localhost'); + $settings['maintenance_theme'] = 'claro'; $settings['trusted_host_patterns'] = [ '^localhost$', diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/tests/phpunit/Drupal/SettingsTestCase.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/tests/phpunit/Drupal/SettingsTestCase.php index eda23426b..a6359591a 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/tests/phpunit/Drupal/SettingsTestCase.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/tests/phpunit/Drupal/SettingsTestCase.php @@ -1,7 +1,7 @@ @@ -202,7 +202,7 @@ * Require settings file. */ - protected function requireSettingsFile(): void { + protected function requireSettingsFile(array $pre_settings = []): void { - $app_root = getcwd() . '/web'; + $app_root = getcwd() . '/docroot'; diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/tests/phpunit/Drupal/EnvironmentSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/tests/phpunit/Drupal/EnvironmentSettingsTest.php index 61b3e762a..d45f2d491 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/tests/phpunit/Drupal/EnvironmentSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/tests/phpunit/Drupal/EnvironmentSettingsTest.php @@ -49,7 +49,7 @@ ]; } -@@ -325,6 +369,229 @@ +@@ -325,6 +369,283 @@ $settings['skip_permissions_hardening'] = TRUE; $settings['config_sync_directory'] = '../config/default'; $settings['suspend_mail_send'] = TRUE; @@ -275,6 +275,60 @@ + 'bower_components', + ]; + $settings['hash_salt'] = hash('sha256', getenv('DATABASE_HOST') ?: 'localhost'); ++ $settings['maintenance_theme'] = 'claro'; ++ $settings['trusted_host_patterns'] = [ ++ '^localhost$', ++ ]; ++ $this->assertSettings($settings); ++ } ++ ++ /** ++ * Test Acquia config_sync_directory fallback to config_vcs_directory. ++ * ++ * When DRUPAL_CONFIG_PATH is not set but config_vcs_directory is provided ++ * by the Acquia-included settings file, config_sync_directory should fall ++ * back to config_vcs_directory. ++ */ ++ public function testEnvironmentAcquiaConfigVcsDirectoryFallback(): void { ++ $this->setEnvVars([ ++ 'AH_SITE_ENVIRONMENT' => 1, ++ ]); ++ ++ // Pre-seed config_vcs_directory to simulate the value set by the ++ // Acquia-included settings file from /var/www/site-php/. ++ $this->requireSettingsFile([ ++ 'config_vcs_directory' => '/var/www/site-php/mysite/config', ++ ]); ++ ++ $config['acquia_hosting_settings_autoconnect'] = FALSE; ++ $config['config_split.config_split.dev']['status'] = TRUE; ++ $config['environment_indicator.indicator']['bg_color'] = '#4caf50'; ++ $config['environment_indicator.indicator']['fg_color'] = '#000000'; ++ $config['environment_indicator.indicator']['name'] = self::ENVIRONMENT_DEV; ++ $config['environment_indicator.settings']['favicon'] = TRUE; ++ $config['environment_indicator.settings']['toolbar_integration'] = [TRUE]; ++ $config['robotstxt.settings']['content'] = "User-agent: *\nDisallow: /"; ++ $config['shield.settings']['shield_enable'] = TRUE; ++ $config['xmlsitemap.settings']['disable_cron_regeneration'] = TRUE; ++ $config['xmlsitemap_engines.settings']['submit'] = FALSE; ++ $config['system.performance']['cache']['page']['max_age'] = 900; ++ $this->assertConfig($config); ++ ++ $settings['auto_create_htaccess'] = TRUE; ++ $settings['config_exclude_modules'] = []; ++ $settings['config_sync_directory'] = '/var/www/site-php/mysite/config'; ++ $settings['config_vcs_directory'] = '/var/www/site-php/mysite/config'; ++ $settings['container_yamls'][0] = $this->app_root . '/' . $this->site_path . '/services.yml'; ++ $settings['entity_update_batch_size'] = 50; ++ $settings['environment'] = self::ENVIRONMENT_DEV; ++ $settings['file_public_path'] = 'sites/default/files'; ++ $settings['file_private_path'] = 'sites/default/files/private'; ++ $settings['file_temp_path'] = '/tmp'; ++ $settings['file_scan_ignore_directories'] = [ ++ 'node_modules', ++ 'bower_components', ++ ]; ++ $settings['hash_salt'] = hash('sha256', getenv('DATABASE_HOST') ?: 'localhost'); + $settings['maintenance_theme'] = 'claro'; $settings['trusted_host_patterns'] = [ '^localhost$', diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/tests/phpunit/Drupal/SettingsTestCase.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/tests/phpunit/Drupal/SettingsTestCase.php index eda23426b..a6359591a 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/tests/phpunit/Drupal/SettingsTestCase.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/tests/phpunit/Drupal/SettingsTestCase.php @@ -1,7 +1,7 @@ @@ -202,7 +202,7 @@ * Require settings file. */ - protected function requireSettingsFile(): void { + protected function requireSettingsFile(array $pre_settings = []): void { - $app_root = getcwd() . '/web'; + $app_root = getcwd() . '/docroot'; diff --git a/tests/phpunit/Drupal/EnvironmentSettingsTest.php b/tests/phpunit/Drupal/EnvironmentSettingsTest.php index 5882dddc6..38ce8d897 100644 --- a/tests/phpunit/Drupal/EnvironmentSettingsTest.php +++ b/tests/phpunit/Drupal/EnvironmentSettingsTest.php @@ -847,6 +847,61 @@ public function testEnvironmentAcquiaConfigPathOverride(): void { ]; $this->assertSettings($settings); } + + /** + * Test Acquia config_sync_directory fallback to config_vcs_directory. + * + * When DRUPAL_CONFIG_PATH is not set but config_vcs_directory is provided + * by the Acquia-included settings file, config_sync_directory should fall + * back to config_vcs_directory. + */ + public function testEnvironmentAcquiaConfigVcsDirectoryFallback(): void { + $this->setEnvVars([ + 'AH_SITE_ENVIRONMENT' => 1, + ]); + + // Pre-seed config_vcs_directory to simulate the value set by the + // Acquia-included settings file from /var/www/site-php/. + $this->requireSettingsFile([ + 'config_vcs_directory' => '/var/www/site-php/mysite/config', + ]); + + $config['acquia_hosting_settings_autoconnect'] = FALSE; + $config['config_split.config_split.dev']['status'] = TRUE; + $config['environment_indicator.indicator']['bg_color'] = '#4caf50'; + $config['environment_indicator.indicator']['fg_color'] = '#000000'; + $config['environment_indicator.indicator']['name'] = self::ENVIRONMENT_DEV; + $config['environment_indicator.settings']['favicon'] = TRUE; + $config['environment_indicator.settings']['toolbar_integration'] = [TRUE]; + $config['robotstxt.settings']['content'] = "User-agent: *\nDisallow: /"; + $config['shield.settings']['shield_enable'] = TRUE; + $config['xmlsitemap.settings']['disable_cron_regeneration'] = TRUE; + $config['xmlsitemap_engines.settings']['submit'] = FALSE; + $config['system.performance']['cache']['page']['max_age'] = 900; + $this->assertConfig($config); + + $settings['auto_create_htaccess'] = TRUE; + $settings['config_exclude_modules'] = []; + $settings['config_sync_directory'] = '/var/www/site-php/mysite/config'; + $settings['config_vcs_directory'] = '/var/www/site-php/mysite/config'; + $settings['container_yamls'][0] = $this->app_root . '/' . $this->site_path . '/services.yml'; + $settings['entity_update_batch_size'] = 50; + $settings['environment'] = self::ENVIRONMENT_DEV; + $settings['file_public_path'] = 'sites/default/files'; + $settings['file_private_path'] = 'sites/default/files/private'; + $settings['file_temp_path'] = '/tmp'; + $settings['file_scan_ignore_directories'] = [ + 'node_modules', + 'bower_components', + ]; + $settings['hash_salt'] = hash('sha256', getenv('DATABASE_HOST') ?: 'localhost'); + $settings['maintenance_theme'] = 'claro'; + $settings['trusted_host_patterns'] = [ + '^localhost$', + ]; + $this->assertSettings($settings); + } + // phpcs:ignore #;> SETTINGS_PROVIDER_ACQUIA // phpcs:ignore #;< SETTINGS_PROVIDER_LAGOON /** diff --git a/tests/phpunit/Drupal/SettingsTestCase.php b/tests/phpunit/Drupal/SettingsTestCase.php index e5e3c59d8..46ce1c3eb 100644 --- a/tests/phpunit/Drupal/SettingsTestCase.php +++ b/tests/phpunit/Drupal/SettingsTestCase.php @@ -205,7 +205,7 @@ protected function unsetEnvVars(): void { /** * Require settings file. */ - protected function requireSettingsFile(): void { + protected function requireSettingsFile(array $pre_settings = []): void { $app_root = getcwd() . '/web'; if (!file_exists($app_root)) { @@ -214,7 +214,7 @@ protected function requireSettingsFile(): void { $site_path = 'sites/default'; $config = []; - $settings = []; + $settings = $pre_settings; $databases = []; require $app_root . DIRECTORY_SEPARATOR . $site_path . DIRECTORY_SEPARATOR . 'settings.php';