From f7f6ef9dd20d6ba78baf0e780065e185b3da9dae Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Wed, 9 Sep 2026 09:11:06 +1000 Subject: [PATCH 1/5] [#3112] Settled one environment variable guard form across the Drupal settings includes. Boolean flags are read with a strict comparison against '1', so every other value - unset, empty, '0', 'true' - leaves the behavior off. Value-carrying variables keep the '!empty()' presence check and are bound to a variable when the value is read again after the guard. Every comparison is strict. The contrib-presence guard now applies only where the include loads a file from the module directory or registers its paths, so 'settings.clamav.php' no longer checks for the module. --- .../modules/contributed-modules.mdx | 35 ++- .vortex/docs/content/development/settings.mdx | 15 + .vortex/docs/content/hosting/acquia.mdx | 2 +- .../Drupal/EnvironmentSettingsTest.php | 85 ++++++ .../phpunit/Drupal/SwitchableSettingsTest.php | 260 +++++++++++------- .../includes/modules/settings.clamav.php | 2 +- .../includes/modules/settings.redis.php | 2 +- .../modules/settings.reroute_email.php | 2 +- .../includes/modules/settings.shield.php | 17 +- .../includes/providers/settings.acquia.php | 13 +- .../includes/providers/settings.lagoon.php | 20 +- web/sites/default/settings.php | 5 +- 12 files changed, 318 insertions(+), 140 deletions(-) diff --git a/.vortex/docs/content/development/modules/contributed-modules.mdx b/.vortex/docs/content/development/modules/contributed-modules.mdx index 8ed87de48b..9e2211bae6 100644 --- a/.vortex/docs/content/development/modules/contributed-modules.mdx +++ b/.vortex/docs/content/development/modules/contributed-modules.mdx @@ -15,13 +15,13 @@ sidebar_position: 2 ### Configuration -[`settings.clamav.php`](https://github.com/drevops/vortex/blob/main/web/sites/default/includes/modules/settings.clamav.php) selects daemon or executable mode and points the daemon at the ClamAV service, but only when `DRUPAL_CLAMAV_ENABLED` is set. +[`settings.clamav.php`](https://github.com/drevops/vortex/blob/main/web/sites/default/includes/modules/settings.clamav.php) selects daemon or executable mode and points the daemon at the ClamAV service, but only when `DRUPAL_CLAMAV_ENABLED` is set to `1`. -| Variable | Purpose | -|------------------------------|------------------------------------| -| `DRUPAL_CLAMAV_ENABLED` | Applies the override only when set | -| `DRUPAL_CLAMAV_MODE` | Selects daemon or executable mode | -| `CLAMAV_HOST`, `CLAMAV_PORT` | Daemon host and port | +| Variable | Purpose | +|------------------------------|-------------------------------------------| +| `DRUPAL_CLAMAV_ENABLED` | Applies the override only when set to `1` | +| `DRUPAL_CLAMAV_MODE` | Selects daemon or executable mode | +| `CLAMAV_HOST`, `CLAMAV_PORT` | Daemon host and port | ## Coffee @@ -163,10 +163,10 @@ No settings override. [`settings.redis.php`](https://github.com/drevops/vortex/blob/main/web/sites/default/includes/modules/settings.redis.php) makes Redis the default cache backend, registers the module container YAML files and swaps the bootstrap container over - all gated on `DRUPAL_REDIS_ENABLED` and on the `redis` PHP extension being loaded, so a two-stage deployment can provision the service before switching the cache. -| Variable | Purpose | -|------------------------------------|------------------------------------| -| `DRUPAL_REDIS_ENABLED` | Applies the override only when set | -| `REDIS_HOST`, `REDIS_SERVICE_PORT` | Connection host and port | +| Variable | Purpose | +|------------------------------------|-------------------------------------------| +| `DRUPAL_REDIS_ENABLED` | Applies the override only when set to `1` | +| `REDIS_HOST`, `REDIS_SERVICE_PORT` | Connection host and port | ## Reroute Email @@ -212,9 +212,9 @@ A site that deselects this module during [installation](../../installation.mdx) **Overriding default behavior:** -Set `DRUPAL_REROUTE_EMAIL_DISABLED` to any non-empty value to completely disable -email rerouting in an environment where it would otherwise be enabled. This is -the supported way for a `stage` environment to send real mail during UAT. +Set `DRUPAL_REROUTE_EMAIL_DISABLED` to `1` to completely disable email rerouting +in an environment where it would otherwise be enabled. This is the supported way +for a `stage` environment to send real mail during UAT.
Example of the `Reroute Email` module `settings.reroute_email.php` file @@ -292,14 +292,13 @@ No settings override. | `DRUPAL_SHIELD_USER` | | HTTP authentication username | | `DRUPAL_SHIELD_PASS` | | HTTP authentication password | | `DRUPAL_SHIELD_PRINT` | | Message shown in the authentication popup (module default when unset) | -| `DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE` | | Set to any non-empty value to keep the `/.well-known/acme-challenge/*` path open for Let's Encrypt certificate generation | +| `DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE` | | Set to `1` to keep the `/.well-known/acme-challenge/*` path open for Let's Encrypt certificate generation | **Overriding default behavior:** -Set `DRUPAL_SHIELD_DISABLED` to any non-empty value to completely disable Shield -in an environment where it would otherwise be enabled. This is useful for -temporary access during debugging or when an environment does not require -protection. +Set `DRUPAL_SHIELD_DISABLED` to `1` to completely disable Shield in an +environment where it would otherwise be enabled. This is useful for temporary +access during debugging or when an environment does not require protection.
Example of the `Shield` module `settings.shield.php` file diff --git a/.vortex/docs/content/development/settings.mdx b/.vortex/docs/content/development/settings.mdx index 75ce468f05..830209f494 100644 --- a/.vortex/docs/content/development/settings.mdx +++ b/.vortex/docs/content/development/settings.mdx @@ -349,6 +349,21 @@ Prefix all such variables with `DRUPAL_` (e.g. `DRUPAL_MY_SETTING`) to distinguish them from other environment variables.
Always define a default hardcoded value for each environment variable. +- **Guard a variable by what it holds.**
+A _boolean flag_ - a variable whose only job is to switch behavior on - is read +with `getenv('DRUPAL_MY_FLAG') === '1'`. Every other value, including an unset +variable, an empty string, `0`, `true` and `yes`, leaves the behavior off.
+A _value carrier_ - a variable whose value is used - is read with +`!empty(getenv('DRUPAL_MY_VALUE'))`. Assign it to a variable first when the +value is needed after the guard.
+Compare with `===` and `!==`, never with `==`. + +- **Gate on the presence of a contributed module only when the file needs it.**
+`file_exists($contrib_path . '/my_module')` belongs in an override file that +loads a file from the module directory or registers its paths. An override file +that only writes `$config` or `$settings` needs no such guard, because Drupal +ignores overrides for a module that is not installed. + - **Use conditions based on _environment type_ within per-module override files.**
This allows for environment-specific configuration without cluttering the main `settings.php` file.
diff --git a/.vortex/docs/content/hosting/acquia.mdx b/.vortex/docs/content/hosting/acquia.mdx index b5be36a41e..436383476a 100644 --- a/.vortex/docs/content/hosting/acquia.mdx +++ b/.vortex/docs/content/hosting/acquia.mdx @@ -62,7 +62,7 @@ by setting the `DRUPAL_ACQUIA_SETTINGS_FILE` environment variable. three-tier priority: 1. **Default**: `/tmp` -2. **Shared GFS mount**: If `DRUPAL_TMP_PATH_IS_SHARED` is set, uses +2. **Shared GFS mount**: If `DRUPAL_TMP_PATH_IS_SHARED` is set to `1`, uses `/mnt/gfs/{group}.{env}/tmp` - a per-head mounted directory on Acquia's shared filesystem. This is useful for operations like bulk uploads that require a shared temporary directory across web heads. See diff --git a/tests/phpunit/Drupal/EnvironmentSettingsTest.php b/tests/phpunit/Drupal/EnvironmentSettingsTest.php index b6c9c4e044..8ccc460240 100644 --- a/tests/phpunit/Drupal/EnvironmentSettingsTest.php +++ b/tests/phpunit/Drupal/EnvironmentSettingsTest.php @@ -23,6 +23,26 @@ #[Group('drupal_settings')] class EnvironmentSettingsTest extends SettingsTestCase { + // phpcs:ignore #;< SETTINGS_PROVIDER_ACQUIA + + /** + * Path to the Acquia settings file fixture. + */ + protected ?string $acquiaSettingsFixture = NULL; + + /** + * {@inheritdoc} + */ + protected function tearDown(): void { + if (!is_null($this->acquiaSettingsFixture)) { + unlink($this->acquiaSettingsFixture); + } + + parent::tearDown(); + } + + // phpcs:ignore #;> SETTINGS_PROVIDER_ACQUIA + /** * Test the detection of the resulting environment type. */ @@ -1347,6 +1367,71 @@ public function testEnvironmentAcquiaConfigVcsDirectoryFallback(): void { $this->assertSettings($settings); } + /** + * Test the temporary file path resolution on Acquia. + */ + #[DataProvider('dataProviderEnvironmentAcquiaTempPath')] + public function testEnvironmentAcquiaTempPath(array $vars, string $expected_path): void { + $this->acquiaSettingsFixture = getcwd() . '/.artifacts/tmp/' . uniqid('acquia-settings-') . '.inc'; + file_put_contents($this->acquiaSettingsFixture, "setEnvVars($vars + ['DRUPAL_ACQUIA_SETTINGS_FILE' => $this->acquiaSettingsFixture]); + + $this->requireSettingsFile(); + + $this->assertSettingsContains(['file_temp_path' => $expected_path]); + } + + /** + * Data provider for testEnvironmentAcquiaTempPath(). + */ + public static function dataProviderEnvironmentAcquiaTempPath(): \Iterator { + yield 'default' => [ + ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite'], + '/tmp', + ]; + + yield 'shared mount' => [ + ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => '1'], + '/mnt/gfs/mysite.dev/tmp', + ]; + + yield 'shared mount without a site group' => [ + ['AH_SITE_ENVIRONMENT' => 'dev', 'DRUPAL_TMP_PATH_IS_SHARED' => '1'], + '/tmp', + ]; + + yield 'shared mount variable set to an empty value' => [ + ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => ''], + '/tmp', + ]; + + yield 'shared mount variable set to zero' => [ + ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => '0'], + '/tmp', + ]; + + yield 'shared mount variable set to a non-numeric truthy value' => [ + ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => 'true'], + '/tmp', + ]; + + yield 'explicit override' => [ + ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH' => '/custom/tmp'], + '/custom/tmp', + ]; + + yield 'explicit override wins over the shared mount' => [ + ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => '1', 'DRUPAL_TMP_PATH' => '/custom/tmp'], + '/custom/tmp', + ]; + + yield 'explicit override set to an empty value' => [ + ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH' => ''], + '/tmp', + ]; + } + // phpcs:ignore #;> SETTINGS_PROVIDER_ACQUIA // phpcs:ignore #;< SETTINGS_PROVIDER_LAGOON /** diff --git a/tests/phpunit/Drupal/SwitchableSettingsTest.php b/tests/phpunit/Drupal/SwitchableSettingsTest.php index 5a04bd78eb..e13c21894a 100644 --- a/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -45,59 +45,84 @@ protected function tearDown(): void { // phpcs:ignore #;< SERVICE_CLAMAV /** - * Test ClamAV configs in Daemon mode with defaults. + * Test ClamAV config. */ - public function testClamavDaemonCustom(): void { - $this->setEnvVars([ - 'DRUPAL_CLAMAV_ENABLED' => TRUE, - 'DRUPAL_CLAMAV_MODE' => 'daemon', - 'CLAMAV_HOST' => 'custom_clamav_host', - 'CLAMAV_PORT' => 3333, - ]); + #[DataProvider('dataProviderClamav')] + public function testClamav(array $vars, array $expected_present, array $expected_absent = []): void { + $this->setEnvVars($vars); $this->requireSettingsFile(); - $config['clamav.settings']['scan_mode'] = 0; - $config['clamav.settings']['mode_daemon_tcpip']['hostname'] = 'custom_clamav_host'; - $config['clamav.settings']['mode_daemon_tcpip']['port'] = 3333; - - $this->assertConfigContains($config); + $this->assertConfigContains($expected_present); + $this->assertConfigNotContains($expected_absent); } /** - * Test ClamAV configs in Executable mode. + * Data provider for testClamav(). */ - public function testClamavExecutable(): void { - $this->setEnvVars([ - 'DRUPAL_CLAMAV_ENABLED' => TRUE, - 'CLAMAV_HOST' => 'custom_clamav_host', - 'CLAMAV_PORT' => 3333, - ]); - - $this->requireSettingsFile(); + public static function dataProviderClamav(): \Iterator { + yield 'daemon mode with custom host and port' => [ + [ + 'DRUPAL_CLAMAV_ENABLED' => 1, + 'DRUPAL_CLAMAV_MODE' => 'daemon', + 'CLAMAV_HOST' => 'custom_clamav_host', + 'CLAMAV_PORT' => 3333, + ], + [ + 'clamav.settings' => [ + 'scan_mode' => 0, + 'mode_daemon_tcpip' => ['hostname' => 'custom_clamav_host', 'port' => 3333], + ], + ], + ]; - $config['clamav.settings']['scan_mode'] = 1; - $config['clamav.settings']['executable_path'] = '/usr/bin/clamscan'; + yield 'daemon mode with defaults' => [ + [ + 'DRUPAL_CLAMAV_ENABLED' => 1, + 'DRUPAL_CLAMAV_MODE' => 'daemon', + ], + [ + 'clamav.settings' => [ + 'scan_mode' => 0, + 'mode_daemon_tcpip' => ['hostname' => 'clamav', 'port' => 3310], + ], + ], + ]; - $this->assertConfigContains($config); - } + yield 'executable mode' => [ + [ + 'DRUPAL_CLAMAV_ENABLED' => 1, + 'CLAMAV_HOST' => 'custom_clamav_host', + 'CLAMAV_PORT' => 3333, + ], + [ + 'clamav.settings' => ['scan_mode' => 1, 'executable_path' => '/usr/bin/clamscan'], + ], + ]; - /** - * Test ClamAV configs in Daemon mode with defaults. - */ - public function testClamavDaemonDefaults(): void { - $this->setEnvVars([ - 'DRUPAL_CLAMAV_ENABLED' => TRUE, - 'DRUPAL_CLAMAV_MODE' => 'daemon', - ]); + yield 'variable not set' => [ + [], + [], + ['clamav.settings' => ['scan_mode' => NULL]], + ]; - $this->requireSettingsFile(); + yield 'variable set to an empty value' => [ + ['DRUPAL_CLAMAV_ENABLED' => ''], + [], + ['clamav.settings' => ['scan_mode' => NULL]], + ]; - $config['clamav.settings']['scan_mode'] = 0; - $config['clamav.settings']['mode_daemon_tcpip']['hostname'] = 'clamav'; - $config['clamav.settings']['mode_daemon_tcpip']['port'] = 3310; + yield 'variable set to zero' => [ + ['DRUPAL_CLAMAV_ENABLED' => '0'], + [], + ['clamav.settings' => ['scan_mode' => NULL]], + ]; - $this->assertConfigContains($config); + yield 'variable set to a non-numeric truthy value' => [ + ['DRUPAL_CLAMAV_ENABLED' => 'true'], + [], + ['clamav.settings' => ['scan_mode' => NULL]], + ]; } // phpcs:ignore #;> SERVICE_CLAMAV @@ -366,73 +391,80 @@ protected function removeContribFixture(string $path): void { /** * Test Redis settings. */ - public function testRedis(): void { - $this->setEnvVars([ - 'DRUPAL_REDIS_ENABLED' => 1, - 'REDIS_HOST' => 'redis_host', - 'REDIS_SERVICE_PORT' => 1234, - 'VORTEX_REDIS_EXTENSION_LOADED' => 1, - ]); + #[DataProvider('dataProviderRedis')] + public function testRedis(array $vars, bool $expected_enabled, array $expected_settings): void { + $this->setEnvVars($vars); $this->requireSettingsFile(); - $settings['redis.connection']['interface'] = 'PhpRedis'; - $settings['redis.connection']['host'] = 'redis_host'; - $settings['redis.connection']['port'] = 1234; - $settings['cache']['default'] = 'cache.backend.redis'; - - $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); + $this->assertSame($expected_enabled, array_key_exists('bootstrap_container_definition', $this->settings), 'Bootstrap container definition'); unset($this->settings['bootstrap_container_definition']); - $this->assertSettingsContains($settings); - } + if ($expected_enabled) { + $this->assertSettingsContains($expected_settings); - /** - * Test Redis settings with REDIS_* environment variables. - */ - public function testRedisVariables(): void { - $this->setEnvVars([ - 'DRUPAL_REDIS_ENABLED' => 1, - 'REDIS_HOST' => 'redis_host', - 'REDIS_SERVICE_PORT' => 6380, - 'VORTEX_REDIS_EXTENSION_LOADED' => 1, - ]); - - $this->requireSettingsFile(); - - $settings['redis.connection']['interface'] = 'PhpRedis'; - $settings['redis.connection']['host'] = 'redis_host'; - $settings['redis.connection']['port'] = 6380; - $settings['cache']['default'] = 'cache.backend.redis'; - - $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); - unset($this->settings['bootstrap_container_definition']); + return; + } - $this->assertSettingsContains($settings); + $this->assertSettingsNotContains($expected_settings); } /** - * Test Redis settings with custom port. + * Data provider for testRedis(). */ - public function testRedisCustomPort(): void { - $this->setEnvVars([ - 'DRUPAL_REDIS_ENABLED' => 1, - 'REDIS_HOST' => 'custom_redis_host', - 'REDIS_SERVICE_PORT' => 6380, - 'VORTEX_REDIS_EXTENSION_LOADED' => 1, - ]); + public static function dataProviderRedis(): \Iterator { + $disabled_settings = ['redis.connection' => ['interface' => NULL], 'cache' => ['default' => NULL]]; - $this->requireSettingsFile(); + yield 'default port' => [ + [ + 'DRUPAL_REDIS_ENABLED' => 1, + 'REDIS_HOST' => 'redis_host', + 'VORTEX_REDIS_EXTENSION_LOADED' => 1, + ], + TRUE, + [ + 'redis.connection' => ['interface' => 'PhpRedis', 'host' => 'redis_host', 'port' => '6379'], + 'cache' => ['default' => 'cache.backend.redis'], + ], + ]; + + yield 'custom host and port' => [ + [ + 'DRUPAL_REDIS_ENABLED' => 1, + 'REDIS_HOST' => 'custom_redis_host', + 'REDIS_SERVICE_PORT' => 6380, + 'VORTEX_REDIS_EXTENSION_LOADED' => 1, + ], + TRUE, + [ + 'redis.connection' => ['interface' => 'PhpRedis', 'host' => 'custom_redis_host', 'port' => 6380], + 'cache' => ['default' => 'cache.backend.redis'], + ], + ]; - $settings['redis.connection']['interface'] = 'PhpRedis'; - $settings['redis.connection']['host'] = 'custom_redis_host'; - $settings['redis.connection']['port'] = 6380; - $settings['cache']['default'] = 'cache.backend.redis'; + yield 'variable not set' => [ + ['VORTEX_REDIS_EXTENSION_LOADED' => 1], + FALSE, + $disabled_settings, + ]; - $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); - unset($this->settings['bootstrap_container_definition']); + yield 'variable set to an empty value' => [ + ['DRUPAL_REDIS_ENABLED' => '', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], + FALSE, + $disabled_settings, + ]; - $this->assertSettingsContains($settings); + yield 'variable set to zero' => [ + ['DRUPAL_REDIS_ENABLED' => '0', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], + FALSE, + $disabled_settings, + ]; + + yield 'variable set to a non-numeric truthy value' => [ + ['DRUPAL_REDIS_ENABLED' => 'true', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], + FALSE, + $disabled_settings, + ]; } // phpcs:ignore #;> SERVICE_REDIS @@ -623,7 +655,7 @@ public static function dataProviderShield(): \Iterator { 'DRUPAL_SHIELD_DISABLED' => 'false', ], [ - 'shield.settings' => ['shield_enable' => FALSE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], + 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], ], ]; yield [ @@ -635,7 +667,19 @@ public static function dataProviderShield(): \Iterator { 'DRUPAL_SHIELD_DISABLED' => 'true', ], [ - 'shield.settings' => ['shield_enable' => FALSE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], + 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], + ], + ]; + yield [ + self::ENVIRONMENT_DEV, + [ + 'DRUPAL_SHIELD_USER' => 'drupal_shield_user', + 'DRUPAL_SHIELD_PASS' => 'drupal_shield_pass', + 'DRUPAL_SHIELD_PRINT' => 'drupal_shield_print', + 'DRUPAL_SHIELD_DISABLED' => '01', + ], + [ + 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], ], ]; @@ -750,6 +794,24 @@ public static function dataProviderShield(): \Iterator { 'shield.settings' => ['method' => NULL, 'paths' => NULL], ], ]; + // ACME challenge with a non-numeric truthy value - should not set. + yield [ + self::ENVIRONMENT_DEV, + [ + 'DRUPAL_SHIELD_USER' => 'drupal_shield_user', + 'DRUPAL_SHIELD_PASS' => 'drupal_shield_pass', + 'DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE' => 'true', + ], + [ + 'shield.settings' => [ + 'shield_enable' => TRUE, + 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], + ], + ], + [ + 'shield.settings' => ['method' => NULL, 'paths' => NULL], + ], + ]; yield [ self::ENVIRONMENT_DEV, @@ -958,6 +1020,18 @@ public static function dataProviderRerouteEmail(): \Iterator { 'reroute_email.settings' => ['enable' => FALSE], ], ]; + + // DRUPAL_REROUTE_EMAIL_DISABLED with a non-numeric truthy value: not + // disabled. + yield [ + self::ENVIRONMENT_DEV, + [ + 'DRUPAL_REROUTE_EMAIL_DISABLED' => 'true', + ], + [ + 'reroute_email.settings' => ['enable' => TRUE], + ], + ]; } // phpcs:ignore #;> MODULE_REROUTE_EMAIL diff --git a/web/sites/default/includes/modules/settings.clamav.php b/web/sites/default/includes/modules/settings.clamav.php index e0997a1e88..a6f815c15d 100644 --- a/web/sites/default/includes/modules/settings.clamav.php +++ b/web/sites/default/includes/modules/settings.clamav.php @@ -7,7 +7,7 @@ declare(strict_types=1); -if (file_exists($contrib_path . '/clamav') && !empty(getenv('DRUPAL_CLAMAV_ENABLED'))) { +if (getenv('DRUPAL_CLAMAV_ENABLED') === '1') { $clamav_mode = getenv('DRUPAL_CLAMAV_MODE') ?: NULL; if (in_array(strtolower((string) $clamav_mode), ['0', 'daemon'], TRUE)) { // Drupal\clamav\Config::MODE_DAEMON. diff --git a/web/sites/default/includes/modules/settings.redis.php b/web/sites/default/includes/modules/settings.redis.php index 0c3d8fc6aa..a864e63435 100644 --- a/web/sites/default/includes/modules/settings.redis.php +++ b/web/sites/default/includes/modules/settings.redis.php @@ -22,7 +22,7 @@ // can be set as a per-project variable and the per-environment variables // removed; the next deployment (#3) uses the project-wide variable with the // same value '1', so behavior does not change. -if (file_exists($contrib_path . '/redis') && !empty(getenv('DRUPAL_REDIS_ENABLED'))) { +if (file_exists($contrib_path . '/redis') && getenv('DRUPAL_REDIS_ENABLED') === '1') { // Some providers use `REDIS_`-prefixed environment variables. $settings['redis.connection']['host'] = getenv('REDIS_HOST') ?: 'redis'; $settings['redis.connection']['port'] = getenv('REDIS_SERVICE_PORT') ?: '6379'; diff --git a/web/sites/default/includes/modules/settings.reroute_email.php b/web/sites/default/includes/modules/settings.reroute_email.php index 94bbed06bc..f2a237d9bf 100644 --- a/web/sites/default/includes/modules/settings.reroute_email.php +++ b/web/sites/default/includes/modules/settings.reroute_email.php @@ -24,7 +24,7 @@ } // Allow an environment to opt out of the rerouting set above. -if (!empty(getenv('DRUPAL_REROUTE_EMAIL_DISABLED'))) { +if (getenv('DRUPAL_REROUTE_EMAIL_DISABLED') === '1') { // Deliver every message to its intended recipient. $config['reroute_email.settings']['enable'] = FALSE; } diff --git a/web/sites/default/includes/modules/settings.shield.php b/web/sites/default/includes/modules/settings.shield.php index c0ebe482ca..ddf24897d6 100644 --- a/web/sites/default/includes/modules/settings.shield.php +++ b/web/sites/default/includes/modules/settings.shield.php @@ -24,23 +24,26 @@ } } -if (!empty(getenv('DRUPAL_SHIELD_USER')) && !empty(getenv('DRUPAL_SHIELD_PASS'))) { - $config['shield.settings']['credentials']['shield']['user'] = getenv('DRUPAL_SHIELD_USER'); - $config['shield.settings']['credentials']['shield']['pass'] = getenv('DRUPAL_SHIELD_PASS'); +$shield_user = getenv('DRUPAL_SHIELD_USER'); +$shield_pass = getenv('DRUPAL_SHIELD_PASS'); +if (!empty($shield_user) && !empty($shield_pass)) { + $config['shield.settings']['credentials']['shield']['user'] = $shield_user; + $config['shield.settings']['credentials']['shield']['pass'] = $shield_pass; } // Allow overriding the title of the Shield pop-up. -if (getenv('DRUPAL_SHIELD_PRINT')) { - $config['shield.settings']['print'] = getenv('DRUPAL_SHIELD_PRINT'); +$shield_print = getenv('DRUPAL_SHIELD_PRINT'); +if (!empty($shield_print)) { + $config['shield.settings']['print'] = $shield_print; } // Allow disabling Shield completely in an environment. -if (!empty(getenv('DRUPAL_SHIELD_DISABLED'))) { +if (getenv('DRUPAL_SHIELD_DISABLED') === '1') { $config['shield.settings']['shield_enable'] = FALSE; } // Allow ACME challenge path for Let's Encrypt certificate generation. -if (!empty(getenv('DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE'))) { +if (getenv('DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE') === '1') { $config['shield.settings']['method'] = 0; $shield_acme_path = '/.well-known/acme-challenge/*'; $shield_existing_paths = $config['shield.settings']['paths'] ?? ''; diff --git a/web/sites/default/includes/providers/settings.acquia.php b/web/sites/default/includes/providers/settings.acquia.php index 194b7bc7fe..694a148f8c 100644 --- a/web/sites/default/includes/providers/settings.acquia.php +++ b/web/sites/default/includes/providers/settings.acquia.php @@ -14,9 +14,9 @@ declare(strict_types=1); -if (!empty(getenv('AH_SITE_ENVIRONMENT'))) { +$ah_site_env = getenv('AH_SITE_ENVIRONMENT'); +if (!empty($ah_site_env)) { $ah_site_group = getenv('AH_SITE_GROUP'); - $ah_site_env = getenv('AH_SITE_ENVIRONMENT'); // Delay the initial database connection. $config['acquia_hosting_settings_autoconnect'] = FALSE; @@ -34,7 +34,7 @@ // Default all environments to 'dev', including ODE environments. $settings['environment'] = ENVIRONMENT_DEV; - switch (getenv('AH_SITE_ENVIRONMENT')) { + switch ($ah_site_env) { case 'prod': $settings['environment'] = ENVIRONMENT_PROD; break; @@ -64,12 +64,13 @@ // @see https://docs.acquia.com/acquia-cloud-platform/manage-apps/files/temporary#section-important-considerations $settings['file_temp_path'] = '/tmp'; - if (!empty($ah_site_group) && getenv('DRUPAL_TMP_PATH_IS_SHARED')) { + if (!empty($ah_site_group) && getenv('DRUPAL_TMP_PATH_IS_SHARED') === '1') { // @see https://acquia.my.site.com/s/article/360054835954-Bulk-Upload-Not-Working-Correctly $settings['file_temp_path'] = sprintf('/mnt/gfs/%s.%s/tmp', $ah_site_group, $ah_site_env); } - if (getenv('DRUPAL_TMP_PATH')) { - $settings['file_temp_path'] = getenv('DRUPAL_TMP_PATH'); + $acquia_tmp_path = getenv('DRUPAL_TMP_PATH'); + if (!empty($acquia_tmp_path)) { + $settings['file_temp_path'] = $acquia_tmp_path; } } diff --git a/web/sites/default/includes/providers/settings.lagoon.php b/web/sites/default/includes/providers/settings.lagoon.php index 48af018642..aebfeff969 100644 --- a/web/sites/default/includes/providers/settings.lagoon.php +++ b/web/sites/default/includes/providers/settings.lagoon.php @@ -13,7 +13,10 @@ declare(strict_types=1); if (!empty(getenv('LAGOON_KUBERNETES'))) { - if (getenv('LAGOON_ENVIRONMENT_TYPE') == 'production') { + $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); + $lagoon_production_branch = getenv('VORTEX_LAGOON_PRODUCTION_BRANCH'); + + if (getenv('LAGOON_ENVIRONMENT_TYPE') === 'production') { $settings['environment'] = ENVIRONMENT_PROD; } else { @@ -21,20 +24,17 @@ // The environment may not be marked as 'production' in Lagoon yet, so // detect the production environment by the branch name as well. - if (!empty(getenv('LAGOON_GIT_BRANCH')) && !empty(getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) && getenv('LAGOON_GIT_BRANCH') === getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) { + if (!empty($lagoon_git_branch) && !empty($lagoon_production_branch) && $lagoon_git_branch === $lagoon_production_branch) { $settings['environment'] = ENVIRONMENT_PROD; } // Dedicated test environment based on a branch name. - elseif (getenv('LAGOON_GIT_BRANCH') == 'main' || getenv('LAGOON_GIT_BRANCH') == 'master') { + elseif ($lagoon_git_branch === 'main' || $lagoon_git_branch === 'master') { $settings['environment'] = ENVIRONMENT_STAGE; } // Test environment based on a branch prefix for release and // hotfix branches. - elseif (!empty(getenv('LAGOON_GIT_BRANCH'))) { - $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); - if ($lagoon_git_branch && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { - $settings['environment'] = ENVIRONMENT_STAGE; - } + elseif (!empty($lagoon_git_branch) && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { + $settings['environment'] = ENVIRONMENT_STAGE; } } @@ -45,7 +45,7 @@ $settings['reverse_proxy'] = TRUE; $settings['reverse_proxy_header'] = 'HTTP_TRUE_CLIENT_IP'; - $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')); + $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: $lagoon_production_branch); // Trusted host patterns for Lagoon internal routes. // Do not modify this section. Instead, add your custom patterns to the @@ -55,7 +55,7 @@ // Trust amazee.io's autogenerated internal routes, served under *.amazee.io. $settings['trusted_host_patterns'][] = '^.+\.amazee\.io$'; $lagoon_routes = getenv('LAGOON_ROUTES'); - if ($lagoon_routes) { + if (!empty($lagoon_routes)) { $lagoon_route_urls = array_map(trim(...), explode(',', $lagoon_routes)); foreach ($lagoon_route_urls as $lagoon_route_url) { // parse_url() reads a scheme-less value as a path, so re-parse with '//' diff --git a/web/sites/default/settings.php b/web/sites/default/settings.php index e691a1e9ba..f7098296d9 100644 --- a/web/sites/default/settings.php +++ b/web/sites/default/settings.php @@ -147,8 +147,9 @@ } // Allow overriding the environment type using the ENVIRONMENT_TYPE variable. -if (!empty(getenv('ENVIRONMENT_TYPE'))) { - $settings['environment'] = getenv('ENVIRONMENT_TYPE'); +$environment_type = getenv('ENVIRONMENT_TYPE'); +if (!empty($environment_type)) { + $settings['environment'] = $environment_type; } //////////////////////////////////////////////////////////////////////////////// From b896449c546b24f696d366e2bebc04f22e494f95 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Wed, 9 Sep 2026 09:11:18 +1000 Subject: [PATCH 2/5] Updated snapshots. --- .../phpunit/Drupal/SwitchableSettingsTest.php | 260 +++++++++++------- .../includes/modules/settings.clamav.php | 2 +- .../includes/modules/settings.redis.php | 2 +- .../modules/settings.reroute_email.php | 2 +- .../includes/modules/settings.shield.php | 17 +- .../_baseline/web/sites/default/settings.php | 5 +- .../includes/modules/settings.clamav.php | 2 +- .../includes/modules/settings.redis.php | 2 +- .../modules/settings.reroute_email.php | 2 +- .../includes/modules/settings.shield.php | 17 +- .../includes/providers/settings.acquia.php | 13 +- .../docroot/sites/default/settings.php | 5 +- .../Drupal/EnvironmentSettingsTest.php | 114 +++++++- .../includes/providers/settings.lagoon.php | 20 +- .../includes/modules/settings.clamav.php | 2 +- .../includes/modules/settings.redis.php | 2 +- .../modules/settings.reroute_email.php | 2 +- .../includes/modules/settings.shield.php | 17 +- .../includes/providers/settings.acquia.php | 13 +- .../docroot/sites/default/settings.php | 5 +- .../Drupal/EnvironmentSettingsTest.php | 114 +++++++- .../includes/providers/settings.lagoon.php | 20 +- .../includes/providers/settings.lagoon.php | 20 +- .../web/sites/default/settings.php | 2 +- .../web/sites/default/settings.php | 2 +- .../includes/providers/settings.lagoon.php | 20 +- .../web/sites/default/settings.php | 2 +- .../web/sites/default/settings.php | 2 +- .../web/sites/default/settings.php | 2 +- .../web/sites/default/settings.php | 2 +- .../web/sites/default/settings.php | 2 +- .../web/sites/default/settings.php | 2 +- .../web/sites/default/settings.php | 2 +- .../phpunit/Drupal/SwitchableSettingsTest.php | 2 +- .../phpunit/Drupal/SwitchableSettingsTest.php | 14 +- .../phpunit/Drupal/SwitchableSettingsTest.php | 2 +- .../phpunit/Drupal/SwitchableSettingsTest.php | 6 +- .../phpunit/Drupal/SwitchableSettingsTest.php | 14 +- .../phpunit/Drupal/SwitchableSettingsTest.php | 40 ++- .../phpunit/Drupal/SwitchableSettingsTest.php | 36 ++- .../phpunit/Drupal/SwitchableSettingsTest.php | 2 +- .../phpunit/Drupal/SwitchableSettingsTest.php | 66 ++++- .../phpunit/Drupal/SwitchableSettingsTest.php | 12 +- .../phpunit/Drupal/SwitchableSettingsTest.php | 113 ++++---- .../phpunit/Drupal/SwitchableSettingsTest.php | 105 ++++--- .../includes/providers/settings.lagoon.php | 20 +- .../phpunit/Drupal/SwitchableSettingsTest.php | 105 ++++--- .../phpunit/Drupal/SwitchableSettingsTest.php | 113 ++++---- .../phpunit/Drupal/SwitchableSettingsTest.php | 238 +++++++++------- 49 files changed, 1035 insertions(+), 549 deletions(-) diff --git a/.vortex/installer/tests/Fixtures/handler_process/_baseline/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/_baseline/tests/phpunit/Drupal/SwitchableSettingsTest.php index 2b0db7f6c9..a920877e6c 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/_baseline/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/_baseline/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -38,59 +38,84 @@ protected function tearDown(): void { } /** - * Test ClamAV configs in Daemon mode with defaults. + * Test ClamAV config. */ - public function testClamavDaemonCustom(): void { - $this->setEnvVars([ - 'DRUPAL_CLAMAV_ENABLED' => TRUE, - 'DRUPAL_CLAMAV_MODE' => 'daemon', - 'CLAMAV_HOST' => 'custom_clamav_host', - 'CLAMAV_PORT' => 3333, - ]); + #[DataProvider('dataProviderClamav')] + public function testClamav(array $vars, array $expected_present, array $expected_absent = []): void { + $this->setEnvVars($vars); $this->requireSettingsFile(); - $config['clamav.settings']['scan_mode'] = 0; - $config['clamav.settings']['mode_daemon_tcpip']['hostname'] = 'custom_clamav_host'; - $config['clamav.settings']['mode_daemon_tcpip']['port'] = 3333; - - $this->assertConfigContains($config); + $this->assertConfigContains($expected_present); + $this->assertConfigNotContains($expected_absent); } /** - * Test ClamAV configs in Executable mode. + * Data provider for testClamav(). */ - public function testClamavExecutable(): void { - $this->setEnvVars([ - 'DRUPAL_CLAMAV_ENABLED' => TRUE, - 'CLAMAV_HOST' => 'custom_clamav_host', - 'CLAMAV_PORT' => 3333, - ]); - - $this->requireSettingsFile(); + public static function dataProviderClamav(): \Iterator { + yield 'daemon mode with custom host and port' => [ + [ + 'DRUPAL_CLAMAV_ENABLED' => 1, + 'DRUPAL_CLAMAV_MODE' => 'daemon', + 'CLAMAV_HOST' => 'custom_clamav_host', + 'CLAMAV_PORT' => 3333, + ], + [ + 'clamav.settings' => [ + 'scan_mode' => 0, + 'mode_daemon_tcpip' => ['hostname' => 'custom_clamav_host', 'port' => 3333], + ], + ], + ]; - $config['clamav.settings']['scan_mode'] = 1; - $config['clamav.settings']['executable_path'] = '/usr/bin/clamscan'; + yield 'daemon mode with defaults' => [ + [ + 'DRUPAL_CLAMAV_ENABLED' => 1, + 'DRUPAL_CLAMAV_MODE' => 'daemon', + ], + [ + 'clamav.settings' => [ + 'scan_mode' => 0, + 'mode_daemon_tcpip' => ['hostname' => 'clamav', 'port' => 3310], + ], + ], + ]; - $this->assertConfigContains($config); - } + yield 'executable mode' => [ + [ + 'DRUPAL_CLAMAV_ENABLED' => 1, + 'CLAMAV_HOST' => 'custom_clamav_host', + 'CLAMAV_PORT' => 3333, + ], + [ + 'clamav.settings' => ['scan_mode' => 1, 'executable_path' => '/usr/bin/clamscan'], + ], + ]; - /** - * Test ClamAV configs in Daemon mode with defaults. - */ - public function testClamavDaemonDefaults(): void { - $this->setEnvVars([ - 'DRUPAL_CLAMAV_ENABLED' => TRUE, - 'DRUPAL_CLAMAV_MODE' => 'daemon', - ]); + yield 'variable not set' => [ + [], + [], + ['clamav.settings' => ['scan_mode' => NULL]], + ]; - $this->requireSettingsFile(); + yield 'variable set to an empty value' => [ + ['DRUPAL_CLAMAV_ENABLED' => ''], + [], + ['clamav.settings' => ['scan_mode' => NULL]], + ]; - $config['clamav.settings']['scan_mode'] = 0; - $config['clamav.settings']['mode_daemon_tcpip']['hostname'] = 'clamav'; - $config['clamav.settings']['mode_daemon_tcpip']['port'] = 3310; + yield 'variable set to zero' => [ + ['DRUPAL_CLAMAV_ENABLED' => '0'], + [], + ['clamav.settings' => ['scan_mode' => NULL]], + ]; - $this->assertConfigContains($config); + yield 'variable set to a non-numeric truthy value' => [ + ['DRUPAL_CLAMAV_ENABLED' => 'true'], + [], + ['clamav.settings' => ['scan_mode' => NULL]], + ]; } /** @@ -347,73 +372,80 @@ protected function removeContribFixture(string $path): void { /** * Test Redis settings. */ - public function testRedis(): void { - $this->setEnvVars([ - 'DRUPAL_REDIS_ENABLED' => 1, - 'REDIS_HOST' => 'redis_host', - 'REDIS_SERVICE_PORT' => 1234, - 'VORTEX_REDIS_EXTENSION_LOADED' => 1, - ]); + #[DataProvider('dataProviderRedis')] + public function testRedis(array $vars, bool $expected_enabled, array $expected_settings): void { + $this->setEnvVars($vars); $this->requireSettingsFile(); - $settings['redis.connection']['interface'] = 'PhpRedis'; - $settings['redis.connection']['host'] = 'redis_host'; - $settings['redis.connection']['port'] = 1234; - $settings['cache']['default'] = 'cache.backend.redis'; - - $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); + $this->assertSame($expected_enabled, array_key_exists('bootstrap_container_definition', $this->settings), 'Bootstrap container definition'); unset($this->settings['bootstrap_container_definition']); - $this->assertSettingsContains($settings); - } + if ($expected_enabled) { + $this->assertSettingsContains($expected_settings); - /** - * Test Redis settings with REDIS_* environment variables. - */ - public function testRedisVariables(): void { - $this->setEnvVars([ - 'DRUPAL_REDIS_ENABLED' => 1, - 'REDIS_HOST' => 'redis_host', - 'REDIS_SERVICE_PORT' => 6380, - 'VORTEX_REDIS_EXTENSION_LOADED' => 1, - ]); - - $this->requireSettingsFile(); - - $settings['redis.connection']['interface'] = 'PhpRedis'; - $settings['redis.connection']['host'] = 'redis_host'; - $settings['redis.connection']['port'] = 6380; - $settings['cache']['default'] = 'cache.backend.redis'; - - $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); - unset($this->settings['bootstrap_container_definition']); + return; + } - $this->assertSettingsContains($settings); + $this->assertSettingsNotContains($expected_settings); } /** - * Test Redis settings with custom port. + * Data provider for testRedis(). */ - public function testRedisCustomPort(): void { - $this->setEnvVars([ - 'DRUPAL_REDIS_ENABLED' => 1, - 'REDIS_HOST' => 'custom_redis_host', - 'REDIS_SERVICE_PORT' => 6380, - 'VORTEX_REDIS_EXTENSION_LOADED' => 1, - ]); + public static function dataProviderRedis(): \Iterator { + $disabled_settings = ['redis.connection' => ['interface' => NULL], 'cache' => ['default' => NULL]]; - $this->requireSettingsFile(); + yield 'default port' => [ + [ + 'DRUPAL_REDIS_ENABLED' => 1, + 'REDIS_HOST' => 'redis_host', + 'VORTEX_REDIS_EXTENSION_LOADED' => 1, + ], + TRUE, + [ + 'redis.connection' => ['interface' => 'PhpRedis', 'host' => 'redis_host', 'port' => '6379'], + 'cache' => ['default' => 'cache.backend.redis'], + ], + ]; + + yield 'custom host and port' => [ + [ + 'DRUPAL_REDIS_ENABLED' => 1, + 'REDIS_HOST' => 'custom_redis_host', + 'REDIS_SERVICE_PORT' => 6380, + 'VORTEX_REDIS_EXTENSION_LOADED' => 1, + ], + TRUE, + [ + 'redis.connection' => ['interface' => 'PhpRedis', 'host' => 'custom_redis_host', 'port' => 6380], + 'cache' => ['default' => 'cache.backend.redis'], + ], + ]; - $settings['redis.connection']['interface'] = 'PhpRedis'; - $settings['redis.connection']['host'] = 'custom_redis_host'; - $settings['redis.connection']['port'] = 6380; - $settings['cache']['default'] = 'cache.backend.redis'; + yield 'variable not set' => [ + ['VORTEX_REDIS_EXTENSION_LOADED' => 1], + FALSE, + $disabled_settings, + ]; - $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); - unset($this->settings['bootstrap_container_definition']); + yield 'variable set to an empty value' => [ + ['DRUPAL_REDIS_ENABLED' => '', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], + FALSE, + $disabled_settings, + ]; - $this->assertSettingsContains($settings); + yield 'variable set to zero' => [ + ['DRUPAL_REDIS_ENABLED' => '0', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], + FALSE, + $disabled_settings, + ]; + + yield 'variable set to a non-numeric truthy value' => [ + ['DRUPAL_REDIS_ENABLED' => 'true', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], + FALSE, + $disabled_settings, + ]; } /** @@ -601,7 +633,7 @@ public static function dataProviderShield(): \Iterator { 'DRUPAL_SHIELD_DISABLED' => 'false', ], [ - 'shield.settings' => ['shield_enable' => FALSE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], + 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], ], ]; yield [ @@ -613,7 +645,19 @@ public static function dataProviderShield(): \Iterator { 'DRUPAL_SHIELD_DISABLED' => 'true', ], [ - 'shield.settings' => ['shield_enable' => FALSE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], + 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], + ], + ]; + yield [ + self::ENVIRONMENT_DEV, + [ + 'DRUPAL_SHIELD_USER' => 'drupal_shield_user', + 'DRUPAL_SHIELD_PASS' => 'drupal_shield_pass', + 'DRUPAL_SHIELD_PRINT' => 'drupal_shield_print', + 'DRUPAL_SHIELD_DISABLED' => '01', + ], + [ + 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], ], ]; @@ -728,6 +772,24 @@ public static function dataProviderShield(): \Iterator { 'shield.settings' => ['method' => NULL, 'paths' => NULL], ], ]; + // ACME challenge with a non-numeric truthy value - should not set. + yield [ + self::ENVIRONMENT_DEV, + [ + 'DRUPAL_SHIELD_USER' => 'drupal_shield_user', + 'DRUPAL_SHIELD_PASS' => 'drupal_shield_pass', + 'DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE' => 'true', + ], + [ + 'shield.settings' => [ + 'shield_enable' => TRUE, + 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], + ], + ], + [ + 'shield.settings' => ['method' => NULL, 'paths' => NULL], + ], + ]; yield [ self::ENVIRONMENT_DEV, @@ -933,6 +995,18 @@ public static function dataProviderRerouteEmail(): \Iterator { 'reroute_email.settings' => ['enable' => FALSE], ], ]; + + // DRUPAL_REROUTE_EMAIL_DISABLED with a non-numeric truthy value: not + // disabled. + yield [ + self::ENVIRONMENT_DEV, + [ + 'DRUPAL_REROUTE_EMAIL_DISABLED' => 'true', + ], + [ + 'reroute_email.settings' => ['enable' => TRUE], + ], + ]; } /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.clamav.php b/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.clamav.php index e0997a1e88..a6f815c15d 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.clamav.php +++ b/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.clamav.php @@ -7,7 +7,7 @@ declare(strict_types=1); -if (file_exists($contrib_path . '/clamav') && !empty(getenv('DRUPAL_CLAMAV_ENABLED'))) { +if (getenv('DRUPAL_CLAMAV_ENABLED') === '1') { $clamav_mode = getenv('DRUPAL_CLAMAV_MODE') ?: NULL; if (in_array(strtolower((string) $clamav_mode), ['0', 'daemon'], TRUE)) { // Drupal\clamav\Config::MODE_DAEMON. diff --git a/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.redis.php b/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.redis.php index 0c3d8fc6aa..a864e63435 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.redis.php +++ b/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.redis.php @@ -22,7 +22,7 @@ // can be set as a per-project variable and the per-environment variables // removed; the next deployment (#3) uses the project-wide variable with the // same value '1', so behavior does not change. -if (file_exists($contrib_path . '/redis') && !empty(getenv('DRUPAL_REDIS_ENABLED'))) { +if (file_exists($contrib_path . '/redis') && getenv('DRUPAL_REDIS_ENABLED') === '1') { // Some providers use `REDIS_`-prefixed environment variables. $settings['redis.connection']['host'] = getenv('REDIS_HOST') ?: 'redis'; $settings['redis.connection']['port'] = getenv('REDIS_SERVICE_PORT') ?: '6379'; diff --git a/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.reroute_email.php b/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.reroute_email.php index a0bbc387d8..8a6c7d4592 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.reroute_email.php +++ b/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.reroute_email.php @@ -24,7 +24,7 @@ } // Allow an environment to opt out of the rerouting set above. -if (!empty(getenv('DRUPAL_REROUTE_EMAIL_DISABLED'))) { +if (getenv('DRUPAL_REROUTE_EMAIL_DISABLED') === '1') { // Deliver every message to its intended recipient. $config['reroute_email.settings']['enable'] = FALSE; } diff --git a/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.shield.php b/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.shield.php index c0ebe482ca..ddf24897d6 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.shield.php +++ b/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/includes/modules/settings.shield.php @@ -24,23 +24,26 @@ } } -if (!empty(getenv('DRUPAL_SHIELD_USER')) && !empty(getenv('DRUPAL_SHIELD_PASS'))) { - $config['shield.settings']['credentials']['shield']['user'] = getenv('DRUPAL_SHIELD_USER'); - $config['shield.settings']['credentials']['shield']['pass'] = getenv('DRUPAL_SHIELD_PASS'); +$shield_user = getenv('DRUPAL_SHIELD_USER'); +$shield_pass = getenv('DRUPAL_SHIELD_PASS'); +if (!empty($shield_user) && !empty($shield_pass)) { + $config['shield.settings']['credentials']['shield']['user'] = $shield_user; + $config['shield.settings']['credentials']['shield']['pass'] = $shield_pass; } // Allow overriding the title of the Shield pop-up. -if (getenv('DRUPAL_SHIELD_PRINT')) { - $config['shield.settings']['print'] = getenv('DRUPAL_SHIELD_PRINT'); +$shield_print = getenv('DRUPAL_SHIELD_PRINT'); +if (!empty($shield_print)) { + $config['shield.settings']['print'] = $shield_print; } // Allow disabling Shield completely in an environment. -if (!empty(getenv('DRUPAL_SHIELD_DISABLED'))) { +if (getenv('DRUPAL_SHIELD_DISABLED') === '1') { $config['shield.settings']['shield_enable'] = FALSE; } // Allow ACME challenge path for Let's Encrypt certificate generation. -if (!empty(getenv('DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE'))) { +if (getenv('DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE') === '1') { $config['shield.settings']['method'] = 0; $shield_acme_path = '/.well-known/acme-challenge/*'; $shield_existing_paths = $config['shield.settings']['paths'] ?? ''; diff --git a/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/settings.php index b1fbea70de..fcaa4b4034 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/_baseline/web/sites/default/settings.php @@ -147,8 +147,9 @@ } // Allow overriding the environment type using the ENVIRONMENT_TYPE variable. -if (!empty(getenv('ENVIRONMENT_TYPE'))) { - $settings['environment'] = getenv('ENVIRONMENT_TYPE'); +$environment_type = getenv('ENVIRONMENT_TYPE'); +if (!empty($environment_type)) { + $settings['environment'] = $environment_type; } //////////////////////////////////////////////////////////////////////////////// diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.clamav.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.clamav.php index e0997a1e88..a6f815c15d 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.clamav.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.clamav.php @@ -7,7 +7,7 @@ declare(strict_types=1); -if (file_exists($contrib_path . '/clamav') && !empty(getenv('DRUPAL_CLAMAV_ENABLED'))) { +if (getenv('DRUPAL_CLAMAV_ENABLED') === '1') { $clamav_mode = getenv('DRUPAL_CLAMAV_MODE') ?: NULL; if (in_array(strtolower((string) $clamav_mode), ['0', 'daemon'], TRUE)) { // Drupal\clamav\Config::MODE_DAEMON. diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.redis.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.redis.php index 0c3d8fc6aa..a864e63435 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.redis.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.redis.php @@ -22,7 +22,7 @@ // can be set as a per-project variable and the per-environment variables // removed; the next deployment (#3) uses the project-wide variable with the // same value '1', so behavior does not change. -if (file_exists($contrib_path . '/redis') && !empty(getenv('DRUPAL_REDIS_ENABLED'))) { +if (file_exists($contrib_path . '/redis') && getenv('DRUPAL_REDIS_ENABLED') === '1') { // Some providers use `REDIS_`-prefixed environment variables. $settings['redis.connection']['host'] = getenv('REDIS_HOST') ?: 'redis'; $settings['redis.connection']['port'] = getenv('REDIS_SERVICE_PORT') ?: '6379'; diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.reroute_email.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.reroute_email.php index a0bbc387d8..8a6c7d4592 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.reroute_email.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.reroute_email.php @@ -24,7 +24,7 @@ } // Allow an environment to opt out of the rerouting set above. -if (!empty(getenv('DRUPAL_REROUTE_EMAIL_DISABLED'))) { +if (getenv('DRUPAL_REROUTE_EMAIL_DISABLED') === '1') { // Deliver every message to its intended recipient. $config['reroute_email.settings']['enable'] = FALSE; } diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.shield.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.shield.php index c0ebe482ca..ddf24897d6 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.shield.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/modules/settings.shield.php @@ -24,23 +24,26 @@ } } -if (!empty(getenv('DRUPAL_SHIELD_USER')) && !empty(getenv('DRUPAL_SHIELD_PASS'))) { - $config['shield.settings']['credentials']['shield']['user'] = getenv('DRUPAL_SHIELD_USER'); - $config['shield.settings']['credentials']['shield']['pass'] = getenv('DRUPAL_SHIELD_PASS'); +$shield_user = getenv('DRUPAL_SHIELD_USER'); +$shield_pass = getenv('DRUPAL_SHIELD_PASS'); +if (!empty($shield_user) && !empty($shield_pass)) { + $config['shield.settings']['credentials']['shield']['user'] = $shield_user; + $config['shield.settings']['credentials']['shield']['pass'] = $shield_pass; } // Allow overriding the title of the Shield pop-up. -if (getenv('DRUPAL_SHIELD_PRINT')) { - $config['shield.settings']['print'] = getenv('DRUPAL_SHIELD_PRINT'); +$shield_print = getenv('DRUPAL_SHIELD_PRINT'); +if (!empty($shield_print)) { + $config['shield.settings']['print'] = $shield_print; } // Allow disabling Shield completely in an environment. -if (!empty(getenv('DRUPAL_SHIELD_DISABLED'))) { +if (getenv('DRUPAL_SHIELD_DISABLED') === '1') { $config['shield.settings']['shield_enable'] = FALSE; } // Allow ACME challenge path for Let's Encrypt certificate generation. -if (!empty(getenv('DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE'))) { +if (getenv('DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE') === '1') { $config['shield.settings']['method'] = 0; $shield_acme_path = '/.well-known/acme-challenge/*'; $shield_existing_paths = $config['shield.settings']['paths'] ?? ''; diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/providers/settings.acquia.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/providers/settings.acquia.php index 194b7bc7fe..694a148f8c 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/providers/settings.acquia.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/includes/providers/settings.acquia.php @@ -14,9 +14,9 @@ declare(strict_types=1); -if (!empty(getenv('AH_SITE_ENVIRONMENT'))) { +$ah_site_env = getenv('AH_SITE_ENVIRONMENT'); +if (!empty($ah_site_env)) { $ah_site_group = getenv('AH_SITE_GROUP'); - $ah_site_env = getenv('AH_SITE_ENVIRONMENT'); // Delay the initial database connection. $config['acquia_hosting_settings_autoconnect'] = FALSE; @@ -34,7 +34,7 @@ // Default all environments to 'dev', including ODE environments. $settings['environment'] = ENVIRONMENT_DEV; - switch (getenv('AH_SITE_ENVIRONMENT')) { + switch ($ah_site_env) { case 'prod': $settings['environment'] = ENVIRONMENT_PROD; break; @@ -64,12 +64,13 @@ // @see https://docs.acquia.com/acquia-cloud-platform/manage-apps/files/temporary#section-important-considerations $settings['file_temp_path'] = '/tmp'; - if (!empty($ah_site_group) && getenv('DRUPAL_TMP_PATH_IS_SHARED')) { + if (!empty($ah_site_group) && getenv('DRUPAL_TMP_PATH_IS_SHARED') === '1') { // @see https://acquia.my.site.com/s/article/360054835954-Bulk-Upload-Not-Working-Correctly $settings['file_temp_path'] = sprintf('/mnt/gfs/%s.%s/tmp', $ah_site_group, $ah_site_env); } - if (getenv('DRUPAL_TMP_PATH')) { - $settings['file_temp_path'] = getenv('DRUPAL_TMP_PATH'); + $acquia_tmp_path = getenv('DRUPAL_TMP_PATH'); + if (!empty($acquia_tmp_path)) { + $settings['file_temp_path'] = $acquia_tmp_path; } } diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/settings.php index b1fbea70de..fcaa4b4034 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/docroot/sites/default/settings.php @@ -147,8 +147,9 @@ } // Allow overriding the environment type using the ENVIRONMENT_TYPE variable. -if (!empty(getenv('ENVIRONMENT_TYPE'))) { - $settings['environment'] = getenv('ENVIRONMENT_TYPE'); +$environment_type = getenv('ENVIRONMENT_TYPE'); +if (!empty($environment_type)) { + $settings['environment'] = $environment_type; } //////////////////////////////////////////////////////////////////////////////// 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 be03bd1f06..8e6805b964 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 @@ -1,4 +1,27 @@ -@@ -58,6 +58,50 @@ +@@ -24,6 +24,22 @@ + class EnvironmentSettingsTest extends SettingsTestCase { + + /** ++ * Path to the Acquia settings file fixture. ++ */ ++ protected ?string $acquiaSettingsFixture = NULL; ++ ++ /** ++ * {@inheritdoc} ++ */ ++ protected function tearDown(): void { ++ if (!is_null($this->acquiaSettingsFixture)) { ++ unlink($this->acquiaSettingsFixture); ++ } ++ ++ parent::tearDown(); ++ } ++ ++ /** + * Test the detection of the resulting environment type. + */ + #[DataProvider('dataProviderEnvironmentTypeDetection')] +@@ -58,6 +74,50 @@ self::ENVIRONMENT_LOCAL, ]; @@ -49,15 +72,10 @@ } /** -@@ -471,6 +515,415 @@ - $settings['maintenance_theme'] = 'claro'; - $settings['skip_permissions_hardening'] = TRUE; - $settings['config_sync_directory'] = '../config/default'; -+ $settings['trusted_host_patterns'] = [ -+ '^localhost$', -+ ]; -+ -+ $this->assertSettings($settings); +@@ -476,6 +536,480 @@ + ]; + + $this->assertSettings($settings); + } + + /** @@ -462,6 +480,76 @@ + ]; + $settings['hash_salt'] = hash('sha256', getenv('DATABASE_HOST') ?: 'localhost'); + $settings['maintenance_theme'] = 'claro'; - $settings['trusted_host_patterns'] = [ - '^localhost$', - ]; ++ $settings['trusted_host_patterns'] = [ ++ '^localhost$', ++ ]; ++ ++ $this->assertSettings($settings); ++ } ++ ++ /** ++ * Test the temporary file path resolution on Acquia. ++ */ ++ #[DataProvider('dataProviderEnvironmentAcquiaTempPath')] ++ public function testEnvironmentAcquiaTempPath(array $vars, string $expected_path): void { ++ $this->acquiaSettingsFixture = getcwd() . '/.artifacts/tmp/' . uniqid('acquia-settings-') . '.inc'; ++ file_put_contents($this->acquiaSettingsFixture, "setEnvVars($vars + ['DRUPAL_ACQUIA_SETTINGS_FILE' => $this->acquiaSettingsFixture]); ++ ++ $this->requireSettingsFile(); ++ ++ $this->assertSettingsContains(['file_temp_path' => $expected_path]); ++ } ++ ++ /** ++ * Data provider for testEnvironmentAcquiaTempPath(). ++ */ ++ public static function dataProviderEnvironmentAcquiaTempPath(): \Iterator { ++ yield 'default' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite'], ++ '/tmp', ++ ]; ++ ++ yield 'shared mount' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => '1'], ++ '/mnt/gfs/mysite.dev/tmp', ++ ]; ++ ++ yield 'shared mount without a site group' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'DRUPAL_TMP_PATH_IS_SHARED' => '1'], ++ '/tmp', ++ ]; ++ ++ yield 'shared mount variable set to an empty value' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => ''], ++ '/tmp', ++ ]; ++ ++ yield 'shared mount variable set to zero' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => '0'], ++ '/tmp', ++ ]; ++ ++ yield 'shared mount variable set to a non-numeric truthy value' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => 'true'], ++ '/tmp', ++ ]; ++ ++ yield 'explicit override' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH' => '/custom/tmp'], ++ '/custom/tmp', ++ ]; ++ ++ yield 'explicit override wins over the shared mount' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => '1', 'DRUPAL_TMP_PATH' => '/custom/tmp'], ++ '/custom/tmp', ++ ]; ++ ++ yield 'explicit override set to an empty value' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH' => ''], ++ '/tmp', ++ ]; + } + + } diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_lagoon/web/sites/default/includes/providers/settings.lagoon.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_lagoon/web/sites/default/includes/providers/settings.lagoon.php index 48af018642..aebfeff969 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_lagoon/web/sites/default/includes/providers/settings.lagoon.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_lagoon/web/sites/default/includes/providers/settings.lagoon.php @@ -13,7 +13,10 @@ declare(strict_types=1); if (!empty(getenv('LAGOON_KUBERNETES'))) { - if (getenv('LAGOON_ENVIRONMENT_TYPE') == 'production') { + $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); + $lagoon_production_branch = getenv('VORTEX_LAGOON_PRODUCTION_BRANCH'); + + if (getenv('LAGOON_ENVIRONMENT_TYPE') === 'production') { $settings['environment'] = ENVIRONMENT_PROD; } else { @@ -21,20 +24,17 @@ // The environment may not be marked as 'production' in Lagoon yet, so // detect the production environment by the branch name as well. - if (!empty(getenv('LAGOON_GIT_BRANCH')) && !empty(getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) && getenv('LAGOON_GIT_BRANCH') === getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) { + if (!empty($lagoon_git_branch) && !empty($lagoon_production_branch) && $lagoon_git_branch === $lagoon_production_branch) { $settings['environment'] = ENVIRONMENT_PROD; } // Dedicated test environment based on a branch name. - elseif (getenv('LAGOON_GIT_BRANCH') == 'main' || getenv('LAGOON_GIT_BRANCH') == 'master') { + elseif ($lagoon_git_branch === 'main' || $lagoon_git_branch === 'master') { $settings['environment'] = ENVIRONMENT_STAGE; } // Test environment based on a branch prefix for release and // hotfix branches. - elseif (!empty(getenv('LAGOON_GIT_BRANCH'))) { - $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); - if ($lagoon_git_branch && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { - $settings['environment'] = ENVIRONMENT_STAGE; - } + elseif (!empty($lagoon_git_branch) && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { + $settings['environment'] = ENVIRONMENT_STAGE; } } @@ -45,7 +45,7 @@ $settings['reverse_proxy'] = TRUE; $settings['reverse_proxy_header'] = 'HTTP_TRUE_CLIENT_IP'; - $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')); + $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: $lagoon_production_branch); // Trusted host patterns for Lagoon internal routes. // Do not modify this section. Instead, add your custom patterns to the @@ -55,7 +55,7 @@ // Trust amazee.io's autogenerated internal routes, served under *.amazee.io. $settings['trusted_host_patterns'][] = '^.+\.amazee\.io$'; $lagoon_routes = getenv('LAGOON_ROUTES'); - if ($lagoon_routes) { + if (!empty($lagoon_routes)) { $lagoon_route_urls = array_map(trim(...), explode(',', $lagoon_routes)); foreach ($lagoon_route_urls as $lagoon_route_url) { // parse_url() reads a scheme-less value as a path, so re-parse with '//' diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.clamav.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.clamav.php index e0997a1e88..a6f815c15d 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.clamav.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.clamav.php @@ -7,7 +7,7 @@ declare(strict_types=1); -if (file_exists($contrib_path . '/clamav') && !empty(getenv('DRUPAL_CLAMAV_ENABLED'))) { +if (getenv('DRUPAL_CLAMAV_ENABLED') === '1') { $clamav_mode = getenv('DRUPAL_CLAMAV_MODE') ?: NULL; if (in_array(strtolower((string) $clamav_mode), ['0', 'daemon'], TRUE)) { // Drupal\clamav\Config::MODE_DAEMON. diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.redis.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.redis.php index 0c3d8fc6aa..a864e63435 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.redis.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.redis.php @@ -22,7 +22,7 @@ // can be set as a per-project variable and the per-environment variables // removed; the next deployment (#3) uses the project-wide variable with the // same value '1', so behavior does not change. -if (file_exists($contrib_path . '/redis') && !empty(getenv('DRUPAL_REDIS_ENABLED'))) { +if (file_exists($contrib_path . '/redis') && getenv('DRUPAL_REDIS_ENABLED') === '1') { // Some providers use `REDIS_`-prefixed environment variables. $settings['redis.connection']['host'] = getenv('REDIS_HOST') ?: 'redis'; $settings['redis.connection']['port'] = getenv('REDIS_SERVICE_PORT') ?: '6379'; diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.reroute_email.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.reroute_email.php index a0bbc387d8..8a6c7d4592 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.reroute_email.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.reroute_email.php @@ -24,7 +24,7 @@ } // Allow an environment to opt out of the rerouting set above. -if (!empty(getenv('DRUPAL_REROUTE_EMAIL_DISABLED'))) { +if (getenv('DRUPAL_REROUTE_EMAIL_DISABLED') === '1') { // Deliver every message to its intended recipient. $config['reroute_email.settings']['enable'] = FALSE; } diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.shield.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.shield.php index c0ebe482ca..ddf24897d6 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.shield.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/modules/settings.shield.php @@ -24,23 +24,26 @@ } } -if (!empty(getenv('DRUPAL_SHIELD_USER')) && !empty(getenv('DRUPAL_SHIELD_PASS'))) { - $config['shield.settings']['credentials']['shield']['user'] = getenv('DRUPAL_SHIELD_USER'); - $config['shield.settings']['credentials']['shield']['pass'] = getenv('DRUPAL_SHIELD_PASS'); +$shield_user = getenv('DRUPAL_SHIELD_USER'); +$shield_pass = getenv('DRUPAL_SHIELD_PASS'); +if (!empty($shield_user) && !empty($shield_pass)) { + $config['shield.settings']['credentials']['shield']['user'] = $shield_user; + $config['shield.settings']['credentials']['shield']['pass'] = $shield_pass; } // Allow overriding the title of the Shield pop-up. -if (getenv('DRUPAL_SHIELD_PRINT')) { - $config['shield.settings']['print'] = getenv('DRUPAL_SHIELD_PRINT'); +$shield_print = getenv('DRUPAL_SHIELD_PRINT'); +if (!empty($shield_print)) { + $config['shield.settings']['print'] = $shield_print; } // Allow disabling Shield completely in an environment. -if (!empty(getenv('DRUPAL_SHIELD_DISABLED'))) { +if (getenv('DRUPAL_SHIELD_DISABLED') === '1') { $config['shield.settings']['shield_enable'] = FALSE; } // Allow ACME challenge path for Let's Encrypt certificate generation. -if (!empty(getenv('DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE'))) { +if (getenv('DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE') === '1') { $config['shield.settings']['method'] = 0; $shield_acme_path = '/.well-known/acme-challenge/*'; $shield_existing_paths = $config['shield.settings']['paths'] ?? ''; diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/providers/settings.acquia.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/providers/settings.acquia.php index 194b7bc7fe..694a148f8c 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/providers/settings.acquia.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/includes/providers/settings.acquia.php @@ -14,9 +14,9 @@ declare(strict_types=1); -if (!empty(getenv('AH_SITE_ENVIRONMENT'))) { +$ah_site_env = getenv('AH_SITE_ENVIRONMENT'); +if (!empty($ah_site_env)) { $ah_site_group = getenv('AH_SITE_GROUP'); - $ah_site_env = getenv('AH_SITE_ENVIRONMENT'); // Delay the initial database connection. $config['acquia_hosting_settings_autoconnect'] = FALSE; @@ -34,7 +34,7 @@ // Default all environments to 'dev', including ODE environments. $settings['environment'] = ENVIRONMENT_DEV; - switch (getenv('AH_SITE_ENVIRONMENT')) { + switch ($ah_site_env) { case 'prod': $settings['environment'] = ENVIRONMENT_PROD; break; @@ -64,12 +64,13 @@ // @see https://docs.acquia.com/acquia-cloud-platform/manage-apps/files/temporary#section-important-considerations $settings['file_temp_path'] = '/tmp'; - if (!empty($ah_site_group) && getenv('DRUPAL_TMP_PATH_IS_SHARED')) { + if (!empty($ah_site_group) && getenv('DRUPAL_TMP_PATH_IS_SHARED') === '1') { // @see https://acquia.my.site.com/s/article/360054835954-Bulk-Upload-Not-Working-Correctly $settings['file_temp_path'] = sprintf('/mnt/gfs/%s.%s/tmp', $ah_site_group, $ah_site_env); } - if (getenv('DRUPAL_TMP_PATH')) { - $settings['file_temp_path'] = getenv('DRUPAL_TMP_PATH'); + $acquia_tmp_path = getenv('DRUPAL_TMP_PATH'); + if (!empty($acquia_tmp_path)) { + $settings['file_temp_path'] = $acquia_tmp_path; } } diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/settings.php index b1fbea70de..fcaa4b4034 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/docroot/sites/default/settings.php @@ -147,8 +147,9 @@ } // Allow overriding the environment type using the ENVIRONMENT_TYPE variable. -if (!empty(getenv('ENVIRONMENT_TYPE'))) { - $settings['environment'] = getenv('ENVIRONMENT_TYPE'); +$environment_type = getenv('ENVIRONMENT_TYPE'); +if (!empty($environment_type)) { + $settings['environment'] = $environment_type; } //////////////////////////////////////////////////////////////////////////////// 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 be03bd1f06..8e6805b964 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 @@ -1,4 +1,27 @@ -@@ -58,6 +58,50 @@ +@@ -24,6 +24,22 @@ + class EnvironmentSettingsTest extends SettingsTestCase { + + /** ++ * Path to the Acquia settings file fixture. ++ */ ++ protected ?string $acquiaSettingsFixture = NULL; ++ ++ /** ++ * {@inheritdoc} ++ */ ++ protected function tearDown(): void { ++ if (!is_null($this->acquiaSettingsFixture)) { ++ unlink($this->acquiaSettingsFixture); ++ } ++ ++ parent::tearDown(); ++ } ++ ++ /** + * Test the detection of the resulting environment type. + */ + #[DataProvider('dataProviderEnvironmentTypeDetection')] +@@ -58,6 +74,50 @@ self::ENVIRONMENT_LOCAL, ]; @@ -49,15 +72,10 @@ } /** -@@ -471,6 +515,415 @@ - $settings['maintenance_theme'] = 'claro'; - $settings['skip_permissions_hardening'] = TRUE; - $settings['config_sync_directory'] = '../config/default'; -+ $settings['trusted_host_patterns'] = [ -+ '^localhost$', -+ ]; -+ -+ $this->assertSettings($settings); +@@ -476,6 +536,480 @@ + ]; + + $this->assertSettings($settings); + } + + /** @@ -462,6 +480,76 @@ + ]; + $settings['hash_salt'] = hash('sha256', getenv('DATABASE_HOST') ?: 'localhost'); + $settings['maintenance_theme'] = 'claro'; - $settings['trusted_host_patterns'] = [ - '^localhost$', - ]; ++ $settings['trusted_host_patterns'] = [ ++ '^localhost$', ++ ]; ++ ++ $this->assertSettings($settings); ++ } ++ ++ /** ++ * Test the temporary file path resolution on Acquia. ++ */ ++ #[DataProvider('dataProviderEnvironmentAcquiaTempPath')] ++ public function testEnvironmentAcquiaTempPath(array $vars, string $expected_path): void { ++ $this->acquiaSettingsFixture = getcwd() . '/.artifacts/tmp/' . uniqid('acquia-settings-') . '.inc'; ++ file_put_contents($this->acquiaSettingsFixture, "setEnvVars($vars + ['DRUPAL_ACQUIA_SETTINGS_FILE' => $this->acquiaSettingsFixture]); ++ ++ $this->requireSettingsFile(); ++ ++ $this->assertSettingsContains(['file_temp_path' => $expected_path]); ++ } ++ ++ /** ++ * Data provider for testEnvironmentAcquiaTempPath(). ++ */ ++ public static function dataProviderEnvironmentAcquiaTempPath(): \Iterator { ++ yield 'default' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite'], ++ '/tmp', ++ ]; ++ ++ yield 'shared mount' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => '1'], ++ '/mnt/gfs/mysite.dev/tmp', ++ ]; ++ ++ yield 'shared mount without a site group' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'DRUPAL_TMP_PATH_IS_SHARED' => '1'], ++ '/tmp', ++ ]; ++ ++ yield 'shared mount variable set to an empty value' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => ''], ++ '/tmp', ++ ]; ++ ++ yield 'shared mount variable set to zero' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => '0'], ++ '/tmp', ++ ]; ++ ++ yield 'shared mount variable set to a non-numeric truthy value' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => 'true'], ++ '/tmp', ++ ]; ++ ++ yield 'explicit override' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH' => '/custom/tmp'], ++ '/custom/tmp', ++ ]; ++ ++ yield 'explicit override wins over the shared mount' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH_IS_SHARED' => '1', 'DRUPAL_TMP_PATH' => '/custom/tmp'], ++ '/custom/tmp', ++ ]; ++ ++ yield 'explicit override set to an empty value' => [ ++ ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH' => ''], ++ '/tmp', ++ ]; + } + + } diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___lagoon/web/sites/default/includes/providers/settings.lagoon.php b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___lagoon/web/sites/default/includes/providers/settings.lagoon.php index 48af018642..aebfeff969 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___lagoon/web/sites/default/includes/providers/settings.lagoon.php +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___lagoon/web/sites/default/includes/providers/settings.lagoon.php @@ -13,7 +13,10 @@ declare(strict_types=1); if (!empty(getenv('LAGOON_KUBERNETES'))) { - if (getenv('LAGOON_ENVIRONMENT_TYPE') == 'production') { + $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); + $lagoon_production_branch = getenv('VORTEX_LAGOON_PRODUCTION_BRANCH'); + + if (getenv('LAGOON_ENVIRONMENT_TYPE') === 'production') { $settings['environment'] = ENVIRONMENT_PROD; } else { @@ -21,20 +24,17 @@ // The environment may not be marked as 'production' in Lagoon yet, so // detect the production environment by the branch name as well. - if (!empty(getenv('LAGOON_GIT_BRANCH')) && !empty(getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) && getenv('LAGOON_GIT_BRANCH') === getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) { + if (!empty($lagoon_git_branch) && !empty($lagoon_production_branch) && $lagoon_git_branch === $lagoon_production_branch) { $settings['environment'] = ENVIRONMENT_PROD; } // Dedicated test environment based on a branch name. - elseif (getenv('LAGOON_GIT_BRANCH') == 'main' || getenv('LAGOON_GIT_BRANCH') == 'master') { + elseif ($lagoon_git_branch === 'main' || $lagoon_git_branch === 'master') { $settings['environment'] = ENVIRONMENT_STAGE; } // Test environment based on a branch prefix for release and // hotfix branches. - elseif (!empty(getenv('LAGOON_GIT_BRANCH'))) { - $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); - if ($lagoon_git_branch && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { - $settings['environment'] = ENVIRONMENT_STAGE; - } + elseif (!empty($lagoon_git_branch) && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { + $settings['environment'] = ENVIRONMENT_STAGE; } } @@ -45,7 +45,7 @@ $settings['reverse_proxy'] = TRUE; $settings['reverse_proxy_header'] = 'HTTP_TRUE_CLIENT_IP'; - $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')); + $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: $lagoon_production_branch); // Trusted host patterns for Lagoon internal routes. // Do not modify this section. Instead, add your custom patterns to the @@ -55,7 +55,7 @@ // Trust amazee.io's autogenerated internal routes, served under *.amazee.io. $settings['trusted_host_patterns'][] = '^.+\.amazee\.io$'; $lagoon_routes = getenv('LAGOON_ROUTES'); - if ($lagoon_routes) { + if (!empty($lagoon_routes)) { $lagoon_route_urls = array_map(trim(...), explode(',', $lagoon_routes)); foreach ($lagoon_route_urls as $lagoon_route_url) { // parse_url() reads a scheme-less value as a path, so re-parse with '//' diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_lagoon/web/sites/default/includes/providers/settings.lagoon.php b/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_lagoon/web/sites/default/includes/providers/settings.lagoon.php index 48af018642..aebfeff969 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_lagoon/web/sites/default/includes/providers/settings.lagoon.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_lagoon/web/sites/default/includes/providers/settings.lagoon.php @@ -13,7 +13,10 @@ declare(strict_types=1); if (!empty(getenv('LAGOON_KUBERNETES'))) { - if (getenv('LAGOON_ENVIRONMENT_TYPE') == 'production') { + $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); + $lagoon_production_branch = getenv('VORTEX_LAGOON_PRODUCTION_BRANCH'); + + if (getenv('LAGOON_ENVIRONMENT_TYPE') === 'production') { $settings['environment'] = ENVIRONMENT_PROD; } else { @@ -21,20 +24,17 @@ // The environment may not be marked as 'production' in Lagoon yet, so // detect the production environment by the branch name as well. - if (!empty(getenv('LAGOON_GIT_BRANCH')) && !empty(getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) && getenv('LAGOON_GIT_BRANCH') === getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) { + if (!empty($lagoon_git_branch) && !empty($lagoon_production_branch) && $lagoon_git_branch === $lagoon_production_branch) { $settings['environment'] = ENVIRONMENT_PROD; } // Dedicated test environment based on a branch name. - elseif (getenv('LAGOON_GIT_BRANCH') == 'main' || getenv('LAGOON_GIT_BRANCH') == 'master') { + elseif ($lagoon_git_branch === 'main' || $lagoon_git_branch === 'master') { $settings['environment'] = ENVIRONMENT_STAGE; } // Test environment based on a branch prefix for release and // hotfix branches. - elseif (!empty(getenv('LAGOON_GIT_BRANCH'))) { - $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); - if ($lagoon_git_branch && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { - $settings['environment'] = ENVIRONMENT_STAGE; - } + elseif (!empty($lagoon_git_branch) && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { + $settings['environment'] = ENVIRONMENT_STAGE; } } @@ -45,7 +45,7 @@ $settings['reverse_proxy'] = TRUE; $settings['reverse_proxy_header'] = 'HTTP_TRUE_CLIENT_IP'; - $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')); + $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: $lagoon_production_branch); // Trusted host patterns for Lagoon internal routes. // Do not modify this section. Instead, add your custom patterns to the @@ -55,7 +55,7 @@ // Trust amazee.io's autogenerated internal routes, served under *.amazee.io. $settings['trusted_host_patterns'][] = '^.+\.amazee\.io$'; $lagoon_routes = getenv('LAGOON_ROUTES'); - if ($lagoon_routes) { + if (!empty($lagoon_routes)) { $lagoon_route_urls = array_map(trim(...), explode(',', $lagoon_routes)); foreach ($lagoon_route_urls as $lagoon_route_url) { // parse_url() reads a scheme-less value as a path, so re-parse with '//' diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled/web/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled/web/sites/default/settings.php index 5570421ab9..c04331d75e 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled/web/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled/web/sites/default/settings.php @@ -1,4 +1,4 @@ -@@ -166,6 +166,14 @@ +@@ -167,6 +167,14 @@ } //////////////////////////////////////////////////////////////////////////////// diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/web/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/web/sites/default/settings.php index 5570421ab9..c04331d75e 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/web/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/web/sites/default/settings.php @@ -1,4 +1,4 @@ -@@ -166,6 +166,14 @@ +@@ -167,6 +167,14 @@ } //////////////////////////////////////////////////////////////////////////////// diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_lagoon/web/sites/default/includes/providers/settings.lagoon.php b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_lagoon/web/sites/default/includes/providers/settings.lagoon.php index 48af018642..aebfeff969 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_lagoon/web/sites/default/includes/providers/settings.lagoon.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_lagoon/web/sites/default/includes/providers/settings.lagoon.php @@ -13,7 +13,10 @@ declare(strict_types=1); if (!empty(getenv('LAGOON_KUBERNETES'))) { - if (getenv('LAGOON_ENVIRONMENT_TYPE') == 'production') { + $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); + $lagoon_production_branch = getenv('VORTEX_LAGOON_PRODUCTION_BRANCH'); + + if (getenv('LAGOON_ENVIRONMENT_TYPE') === 'production') { $settings['environment'] = ENVIRONMENT_PROD; } else { @@ -21,20 +24,17 @@ // The environment may not be marked as 'production' in Lagoon yet, so // detect the production environment by the branch name as well. - if (!empty(getenv('LAGOON_GIT_BRANCH')) && !empty(getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) && getenv('LAGOON_GIT_BRANCH') === getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) { + if (!empty($lagoon_git_branch) && !empty($lagoon_production_branch) && $lagoon_git_branch === $lagoon_production_branch) { $settings['environment'] = ENVIRONMENT_PROD; } // Dedicated test environment based on a branch name. - elseif (getenv('LAGOON_GIT_BRANCH') == 'main' || getenv('LAGOON_GIT_BRANCH') == 'master') { + elseif ($lagoon_git_branch === 'main' || $lagoon_git_branch === 'master') { $settings['environment'] = ENVIRONMENT_STAGE; } // Test environment based on a branch prefix for release and // hotfix branches. - elseif (!empty(getenv('LAGOON_GIT_BRANCH'))) { - $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); - if ($lagoon_git_branch && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { - $settings['environment'] = ENVIRONMENT_STAGE; - } + elseif (!empty($lagoon_git_branch) && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { + $settings['environment'] = ENVIRONMENT_STAGE; } } @@ -45,7 +45,7 @@ $settings['reverse_proxy'] = TRUE; $settings['reverse_proxy_header'] = 'HTTP_TRUE_CLIENT_IP'; - $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')); + $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: $lagoon_production_branch); // Trusted host patterns for Lagoon internal routes. // Do not modify this section. Instead, add your custom patterns to the @@ -55,7 +55,7 @@ // Trust amazee.io's autogenerated internal routes, served under *.amazee.io. $settings['trusted_host_patterns'][] = '^.+\.amazee\.io$'; $lagoon_routes = getenv('LAGOON_ROUTES'); - if ($lagoon_routes) { + if (!empty($lagoon_routes)) { $lagoon_route_urls = array_map(trim(...), explode(',', $lagoon_routes)); foreach ($lagoon_route_urls as $lagoon_route_url) { // parse_url() reads a scheme-less value as a path, so re-parse with '//' diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_lagoon/web/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_lagoon/web/sites/default/settings.php index 5570421ab9..c04331d75e 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_lagoon/web/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_lagoon/web/sites/default/settings.php @@ -1,4 +1,4 @@ -@@ -166,6 +166,14 @@ +@@ -167,6 +167,14 @@ } //////////////////////////////////////////////////////////////////////////////// diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_acquia/web/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_acquia/web/sites/default/settings.php index 5570421ab9..c04331d75e 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_acquia/web/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_acquia/web/sites/default/settings.php @@ -1,4 +1,4 @@ -@@ -166,6 +166,14 @@ +@@ -167,6 +167,14 @@ } //////////////////////////////////////////////////////////////////////////////// diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_container_registry/web/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_container_registry/web/sites/default/settings.php index 5570421ab9..c04331d75e 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_container_registry/web/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_container_registry/web/sites/default/settings.php @@ -1,4 +1,4 @@ -@@ -166,6 +166,14 @@ +@@ -167,6 +167,14 @@ } //////////////////////////////////////////////////////////////////////////////// diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_ftp/web/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_ftp/web/sites/default/settings.php index 5570421ab9..c04331d75e 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_ftp/web/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_ftp/web/sites/default/settings.php @@ -1,4 +1,4 @@ -@@ -166,6 +166,14 @@ +@@ -167,6 +167,14 @@ } //////////////////////////////////////////////////////////////////////////////// diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_lagoon/web/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_lagoon/web/sites/default/settings.php index 5570421ab9..c04331d75e 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_lagoon/web/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_lagoon/web/sites/default/settings.php @@ -1,4 +1,4 @@ -@@ -166,6 +166,14 @@ +@@ -167,6 +167,14 @@ } //////////////////////////////////////////////////////////////////////////////// diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_s3/web/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_s3/web/sites/default/settings.php index 5570421ab9..c04331d75e 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_s3/web/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_s3/web/sites/default/settings.php @@ -1,4 +1,4 @@ -@@ -166,6 +166,14 @@ +@@ -167,6 +167,14 @@ } //////////////////////////////////////////////////////////////////////////////// diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_url/web/sites/default/settings.php b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_url/web/sites/default/settings.php index 5570421ab9..c04331d75e 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_url/web/sites/default/settings.php +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_fetch_source_url/web/sites/default/settings.php @@ -1,4 +1,4 @@ -@@ -166,6 +166,14 @@ +@@ -167,6 +167,14 @@ } //////////////////////////////////////////////////////////////////////////////// diff --git a/.vortex/installer/tests/Fixtures/handler_process/modules_no_config_split/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/modules_no_config_split/tests/phpunit/Drupal/SwitchableSettingsTest.php index 62759bede2..33114ffa6f 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/modules_no_config_split/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/modules_no_config_split/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,4 +1,4 @@ -@@ -94,91 +94,6 @@ +@@ -119,91 +119,6 @@ } /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/modules_no_devel_sdc_devel_generated_content_testmode_reroute_email/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/modules_no_devel_sdc_devel_generated_content_testmode_reroute_email/tests/phpunit/Drupal/SwitchableSettingsTest.php index 1d10f69a15..f662c9a3bb 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/modules_no_devel_sdc_devel_generated_content_testmode_reroute_email/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/modules_no_devel_sdc_devel_generated_content_testmode_reroute_email/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,4 +1,4 @@ -@@ -786,156 +786,6 @@ +@@ -848,168 +848,6 @@ } /** @@ -149,6 +149,18 @@ - 'reroute_email.settings' => ['enable' => FALSE], - ], - ]; +- +- // DRUPAL_REROUTE_EMAIL_DISABLED with a non-numeric truthy value: not +- // disabled. +- yield [ +- self::ENVIRONMENT_DEV, +- [ +- 'DRUPAL_REROUTE_EMAIL_DISABLED' => 'true', +- ], +- [ +- 'reroute_email.settings' => ['enable' => TRUE], +- ], +- ]; - } - - /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/modules_no_environment_indicator/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/modules_no_environment_indicator/tests/phpunit/Drupal/SwitchableSettingsTest.php index 040a9cf13f..94b2c64510 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/modules_no_environment_indicator/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/modules_no_environment_indicator/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,4 +1,4 @@ -@@ -179,69 +179,6 @@ +@@ -204,69 +204,6 @@ } /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/modules_no_fast_404/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/modules_no_fast_404/tests/phpunit/Drupal/SwitchableSettingsTest.php index e0831ba701..405c02f06a 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/modules_no_fast_404/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/modules_no_fast_404/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -27,10 +27,10 @@ class SwitchableSettingsTest extends SettingsTestCase { - } - - /** - * Test ClamAV configs in Daemon mode with defaults. + * Test ClamAV config. */ - public function testClamavDaemonCustom(): void { -@@ -239,109 +221,6 @@ + #[DataProvider('dataProviderClamav')] +@@ -264,109 +246,6 @@ 'environment_indicator.settings' => ['toolbar_integration' => [TRUE], 'favicon' => TRUE], ], ]; diff --git a/.vortex/installer/tests/Fixtures/handler_process/modules_no_reroute_email/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/modules_no_reroute_email/tests/phpunit/Drupal/SwitchableSettingsTest.php index 1d10f69a15..f662c9a3bb 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/modules_no_reroute_email/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/modules_no_reroute_email/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,4 +1,4 @@ -@@ -786,156 +786,6 @@ +@@ -848,168 +848,6 @@ } /** @@ -149,6 +149,18 @@ - 'reroute_email.settings' => ['enable' => FALSE], - ], - ]; +- +- // DRUPAL_REROUTE_EMAIL_DISABLED with a non-numeric truthy value: not +- // disabled. +- yield [ +- self::ENVIRONMENT_DEV, +- [ +- 'DRUPAL_REROUTE_EMAIL_DISABLED' => 'true', +- ], +- [ +- 'reroute_email.settings' => ['enable' => TRUE], +- ], +- ]; - } - - /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/modules_no_seckit_shield_stage_file_proxy/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/modules_no_seckit_shield_stage_file_proxy/tests/phpunit/Drupal/SwitchableSettingsTest.php index aea9592deb..a8ca20eea7 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/modules_no_seckit_shield_stage_file_proxy/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/modules_no_seckit_shield_stage_file_proxy/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,4 +1,4 @@ -@@ -417,375 +417,6 @@ +@@ -449,405 +449,6 @@ } /** @@ -186,7 +186,7 @@ - 'DRUPAL_SHIELD_DISABLED' => 'false', - ], - [ -- 'shield.settings' => ['shield_enable' => FALSE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], +- 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], - ], - ]; - yield [ @@ -198,7 +198,19 @@ - 'DRUPAL_SHIELD_DISABLED' => 'true', - ], - [ -- 'shield.settings' => ['shield_enable' => FALSE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], +- 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], +- ], +- ]; +- yield [ +- self::ENVIRONMENT_DEV, +- [ +- 'DRUPAL_SHIELD_USER' => 'drupal_shield_user', +- 'DRUPAL_SHIELD_PASS' => 'drupal_shield_pass', +- 'DRUPAL_SHIELD_PRINT' => 'drupal_shield_print', +- 'DRUPAL_SHIELD_DISABLED' => '01', +- ], +- [ +- 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], - ], - ]; - @@ -313,6 +325,24 @@ - 'shield.settings' => ['method' => NULL, 'paths' => NULL], - ], - ]; +- // ACME challenge with a non-numeric truthy value - should not set. +- yield [ +- self::ENVIRONMENT_DEV, +- [ +- 'DRUPAL_SHIELD_USER' => 'drupal_shield_user', +- 'DRUPAL_SHIELD_PASS' => 'drupal_shield_pass', +- 'DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE' => 'true', +- ], +- [ +- 'shield.settings' => [ +- 'shield_enable' => TRUE, +- 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], +- ], +- ], +- [ +- 'shield.settings' => ['method' => NULL, 'paths' => NULL], +- ], +- ]; - - yield [ - self::ENVIRONMENT_DEV, @@ -374,9 +404,9 @@ * Test Reroute Email config. */ #[DataProvider('dataProviderRerouteEmail')] -@@ -932,131 +563,6 @@ +@@ -1006,131 +607,6 @@ [ - 'reroute_email.settings' => ['enable' => FALSE], + 'reroute_email.settings' => ['enable' => TRUE], ], - ]; - } diff --git a/.vortex/installer/tests/Fixtures/handler_process/modules_no_shield/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/modules_no_shield/tests/phpunit/Drupal/SwitchableSettingsTest.php index 23aff62f50..8305e5b775 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/modules_no_shield/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/modules_no_shield/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,4 +1,4 @@ -@@ -417,375 +417,6 @@ +@@ -449,405 +449,6 @@ } /** @@ -186,7 +186,7 @@ - 'DRUPAL_SHIELD_DISABLED' => 'false', - ], - [ -- 'shield.settings' => ['shield_enable' => FALSE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], +- 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], - ], - ]; - yield [ @@ -198,7 +198,19 @@ - 'DRUPAL_SHIELD_DISABLED' => 'true', - ], - [ -- 'shield.settings' => ['shield_enable' => FALSE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], +- 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], +- ], +- ]; +- yield [ +- self::ENVIRONMENT_DEV, +- [ +- 'DRUPAL_SHIELD_USER' => 'drupal_shield_user', +- 'DRUPAL_SHIELD_PASS' => 'drupal_shield_pass', +- 'DRUPAL_SHIELD_PRINT' => 'drupal_shield_print', +- 'DRUPAL_SHIELD_DISABLED' => '01', +- ], +- [ +- 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], - ], - ]; - @@ -313,6 +325,24 @@ - 'shield.settings' => ['method' => NULL, 'paths' => NULL], - ], - ]; +- // ACME challenge with a non-numeric truthy value - should not set. +- yield [ +- self::ENVIRONMENT_DEV, +- [ +- 'DRUPAL_SHIELD_USER' => 'drupal_shield_user', +- 'DRUPAL_SHIELD_PASS' => 'drupal_shield_pass', +- 'DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE' => 'true', +- ], +- [ +- 'shield.settings' => [ +- 'shield_enable' => TRUE, +- 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], +- ], +- ], +- [ +- 'shield.settings' => ['method' => NULL, 'paths' => NULL], +- ], +- ]; - - yield [ - self::ENVIRONMENT_DEV, diff --git a/.vortex/installer/tests/Fixtures/handler_process/modules_no_stage_file_proxy/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/modules_no_stage_file_proxy/tests/phpunit/Drupal/SwitchableSettingsTest.php index 03829de788..f5ed92d6b4 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/modules_no_stage_file_proxy/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/modules_no_stage_file_proxy/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,4 +1,4 @@ -@@ -936,131 +936,6 @@ +@@ -1010,131 +1010,6 @@ } /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/modules_none/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/modules_none/tests/phpunit/Drupal/SwitchableSettingsTest.php index 6eaef0a475..2a62518d02 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/modules_none/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/modules_none/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -27,10 +27,10 @@ class SwitchableSettingsTest extends SettingsTestCase { - } - - /** - * Test ClamAV configs in Daemon mode with defaults. + * Test ClamAV config. */ - public function testClamavDaemonCustom(): void { -@@ -94,257 +76,6 @@ + #[DataProvider('dataProviderClamav')] +@@ -119,257 +101,6 @@ } /** @@ -287,11 +287,12 @@ public function testClamavDaemonCustom(): void { - /** * Test Redis settings. */ - public function testRedis(): void { -@@ -414,650 +145,6 @@ - unset($this->settings['bootstrap_container_definition']); - - $this->assertSettingsContains($settings); + #[DataProvider('dataProviderRedis')] +@@ -445,692 +176,6 @@ + ['DRUPAL_REDIS_ENABLED' => 'true', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], + FALSE, + $disabled_settings, +- ]; - } - - /** @@ -479,7 +480,7 @@ public function testRedis(): void { - 'DRUPAL_SHIELD_DISABLED' => 'false', - ], - [ -- 'shield.settings' => ['shield_enable' => FALSE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], +- 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], - ], - ]; - yield [ @@ -491,7 +492,19 @@ public function testRedis(): void { - 'DRUPAL_SHIELD_DISABLED' => 'true', - ], - [ -- 'shield.settings' => ['shield_enable' => FALSE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], +- 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], +- ], +- ]; +- yield [ +- self::ENVIRONMENT_DEV, +- [ +- 'DRUPAL_SHIELD_USER' => 'drupal_shield_user', +- 'DRUPAL_SHIELD_PASS' => 'drupal_shield_pass', +- 'DRUPAL_SHIELD_PRINT' => 'drupal_shield_print', +- 'DRUPAL_SHIELD_DISABLED' => '01', +- ], +- [ +- 'shield.settings' => ['shield_enable' => TRUE, 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], 'print' => 'drupal_shield_print'], - ], - ]; - @@ -606,6 +619,24 @@ public function testRedis(): void { - 'shield.settings' => ['method' => NULL, 'paths' => NULL], - ], - ]; +- // ACME challenge with a non-numeric truthy value - should not set. +- yield [ +- self::ENVIRONMENT_DEV, +- [ +- 'DRUPAL_SHIELD_USER' => 'drupal_shield_user', +- 'DRUPAL_SHIELD_PASS' => 'drupal_shield_pass', +- 'DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE' => 'true', +- ], +- [ +- 'shield.settings' => [ +- 'shield_enable' => TRUE, +- 'credentials' => ['shield' => ['user' => 'drupal_shield_user', 'pass' => 'drupal_shield_pass']], +- ], +- ], +- [ +- 'shield.settings' => ['method' => NULL, 'paths' => NULL], +- ], +- ]; - - yield [ - self::ENVIRONMENT_DEV, @@ -811,6 +842,18 @@ public function testRedis(): void { - 'reroute_email.settings' => ['enable' => FALSE], - ], - ]; +- +- // DRUPAL_REROUTE_EMAIL_DISABLED with a non-numeric truthy value: not +- // disabled. +- yield [ +- self::ENVIRONMENT_DEV, +- [ +- 'DRUPAL_REROUTE_EMAIL_DISABLED' => 'true', +- ], +- [ +- 'reroute_email.settings' => ['enable' => TRUE], +- ], +- ]; - } - - /** @@ -935,7 +978,6 @@ public function testRedis(): void { - 'stage_file_proxy.settings' => ['hotlink' => FALSE, 'origin' => 'https://drupal_shield_user:drupal_shield_pass@example.com/'], - ], - [], -- ]; + ]; } - /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/names/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/names/tests/phpunit/Drupal/SwitchableSettingsTest.php index f3a8177854..55d32687ad 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/names/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/names/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,4 +1,4 @@ -@@ -807,7 +807,7 @@ +@@ -869,7 +869,7 @@ self::ENVIRONMENT_LOCAL, [], [ @@ -7,7 +7,7 @@ ], ]; -@@ -816,7 +816,7 @@ +@@ -878,7 +878,7 @@ self::ENVIRONMENT_CI, [], [ @@ -16,7 +16,7 @@ ], ]; -@@ -825,7 +825,7 @@ +@@ -887,7 +887,7 @@ self::ENVIRONMENT_DEV, [], [ @@ -25,7 +25,7 @@ ], ]; -@@ -834,7 +834,7 @@ +@@ -896,7 +896,7 @@ self::ENVIRONMENT_SUT, [], [ @@ -34,7 +34,7 @@ ], ]; -@@ -843,7 +843,7 @@ +@@ -905,7 +905,7 @@ self::ENVIRONMENT_STAGE, [], [ @@ -43,7 +43,7 @@ ], ]; -@@ -852,7 +852,7 @@ +@@ -914,7 +914,7 @@ self::ENVIRONMENT_PROD, [], [ diff --git a/.vortex/installer/tests/Fixtures/handler_process/non_interactive_config_file/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/non_interactive_config_file/tests/phpunit/Drupal/SwitchableSettingsTest.php index ad65210ed5..f89e3ae142 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/non_interactive_config_file/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/non_interactive_config_file/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,76 +1,83 @@ -@@ -345,78 +345,6 @@ +@@ -370,85 +370,6 @@ } /** - * Test Redis settings. - */ -- public function testRedis(): void { -- $this->setEnvVars([ -- 'DRUPAL_REDIS_ENABLED' => 1, -- 'REDIS_HOST' => 'redis_host', -- 'REDIS_SERVICE_PORT' => 1234, -- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, -- ]); +- #[DataProvider('dataProviderRedis')] +- public function testRedis(array $vars, bool $expected_enabled, array $expected_settings): void { +- $this->setEnvVars($vars); - - $this->requireSettingsFile(); - -- $settings['redis.connection']['interface'] = 'PhpRedis'; -- $settings['redis.connection']['host'] = 'redis_host'; -- $settings['redis.connection']['port'] = 1234; -- $settings['cache']['default'] = 'cache.backend.redis'; -- -- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); +- $this->assertSame($expected_enabled, array_key_exists('bootstrap_container_definition', $this->settings), 'Bootstrap container definition'); - unset($this->settings['bootstrap_container_definition']); - -- $this->assertSettingsContains($settings); -- } -- -- /** -- * Test Redis settings with REDIS_* environment variables. -- */ -- public function testRedisVariables(): void { -- $this->setEnvVars([ -- 'DRUPAL_REDIS_ENABLED' => 1, -- 'REDIS_HOST' => 'redis_host', -- 'REDIS_SERVICE_PORT' => 6380, -- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, -- ]); -- -- $this->requireSettingsFile(); +- if ($expected_enabled) { +- $this->assertSettingsContains($expected_settings); - -- $settings['redis.connection']['interface'] = 'PhpRedis'; -- $settings['redis.connection']['host'] = 'redis_host'; -- $settings['redis.connection']['port'] = 6380; -- $settings['cache']['default'] = 'cache.backend.redis'; +- return; +- } - -- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); -- unset($this->settings['bootstrap_container_definition']); -- -- $this->assertSettingsContains($settings); +- $this->assertSettingsNotContains($expected_settings); - } - - /** -- * Test Redis settings with custom port. +- * Data provider for testRedis(). - */ -- public function testRedisCustomPort(): void { -- $this->setEnvVars([ -- 'DRUPAL_REDIS_ENABLED' => 1, -- 'REDIS_HOST' => 'custom_redis_host', -- 'REDIS_SERVICE_PORT' => 6380, -- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, -- ]); +- public static function dataProviderRedis(): \Iterator { +- $disabled_settings = ['redis.connection' => ['interface' => NULL], 'cache' => ['default' => NULL]]; - -- $this->requireSettingsFile(); +- yield 'default port' => [ +- [ +- 'DRUPAL_REDIS_ENABLED' => 1, +- 'REDIS_HOST' => 'redis_host', +- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, +- ], +- TRUE, +- [ +- 'redis.connection' => ['interface' => 'PhpRedis', 'host' => 'redis_host', 'port' => '6379'], +- 'cache' => ['default' => 'cache.backend.redis'], +- ], +- ]; - -- $settings['redis.connection']['interface'] = 'PhpRedis'; -- $settings['redis.connection']['host'] = 'custom_redis_host'; -- $settings['redis.connection']['port'] = 6380; -- $settings['cache']['default'] = 'cache.backend.redis'; +- yield 'custom host and port' => [ +- [ +- 'DRUPAL_REDIS_ENABLED' => 1, +- 'REDIS_HOST' => 'custom_redis_host', +- 'REDIS_SERVICE_PORT' => 6380, +- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, +- ], +- TRUE, +- [ +- 'redis.connection' => ['interface' => 'PhpRedis', 'host' => 'custom_redis_host', 'port' => 6380], +- 'cache' => ['default' => 'cache.backend.redis'], +- ], +- ]; - -- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); -- unset($this->settings['bootstrap_container_definition']); +- yield 'variable not set' => [ +- ['VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; +- +- yield 'variable set to an empty value' => [ +- ['DRUPAL_REDIS_ENABLED' => '', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; +- +- yield 'variable set to zero' => [ +- ['DRUPAL_REDIS_ENABLED' => '0', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; - -- $this->assertSettingsContains($settings); +- yield 'variable set to a non-numeric truthy value' => [ +- ['DRUPAL_REDIS_ENABLED' => 'true', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; - } - - /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/non_interactive_config_string/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/non_interactive_config_string/tests/phpunit/Drupal/SwitchableSettingsTest.php index a2c5670bb2..3bad585270 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/non_interactive_config_string/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/non_interactive_config_string/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,60 +1,85 @@ -@@ -38,62 +38,6 @@ +@@ -38,87 +38,6 @@ } /** -- * Test ClamAV configs in Daemon mode with defaults. +- * Test ClamAV config. - */ -- public function testClamavDaemonCustom(): void { -- $this->setEnvVars([ -- 'DRUPAL_CLAMAV_ENABLED' => TRUE, -- 'DRUPAL_CLAMAV_MODE' => 'daemon', -- 'CLAMAV_HOST' => 'custom_clamav_host', -- 'CLAMAV_PORT' => 3333, -- ]); +- #[DataProvider('dataProviderClamav')] +- public function testClamav(array $vars, array $expected_present, array $expected_absent = []): void { +- $this->setEnvVars($vars); - - $this->requireSettingsFile(); - -- $config['clamav.settings']['scan_mode'] = 0; -- $config['clamav.settings']['mode_daemon_tcpip']['hostname'] = 'custom_clamav_host'; -- $config['clamav.settings']['mode_daemon_tcpip']['port'] = 3333; -- -- $this->assertConfigContains($config); +- $this->assertConfigContains($expected_present); +- $this->assertConfigNotContains($expected_absent); - } - - /** -- * Test ClamAV configs in Executable mode. +- * Data provider for testClamav(). - */ -- public function testClamavExecutable(): void { -- $this->setEnvVars([ -- 'DRUPAL_CLAMAV_ENABLED' => TRUE, -- 'CLAMAV_HOST' => 'custom_clamav_host', -- 'CLAMAV_PORT' => 3333, -- ]); +- public static function dataProviderClamav(): \Iterator { +- yield 'daemon mode with custom host and port' => [ +- [ +- 'DRUPAL_CLAMAV_ENABLED' => 1, +- 'DRUPAL_CLAMAV_MODE' => 'daemon', +- 'CLAMAV_HOST' => 'custom_clamav_host', +- 'CLAMAV_PORT' => 3333, +- ], +- [ +- 'clamav.settings' => [ +- 'scan_mode' => 0, +- 'mode_daemon_tcpip' => ['hostname' => 'custom_clamav_host', 'port' => 3333], +- ], +- ], +- ]; - -- $this->requireSettingsFile(); +- yield 'daemon mode with defaults' => [ +- [ +- 'DRUPAL_CLAMAV_ENABLED' => 1, +- 'DRUPAL_CLAMAV_MODE' => 'daemon', +- ], +- [ +- 'clamav.settings' => [ +- 'scan_mode' => 0, +- 'mode_daemon_tcpip' => ['hostname' => 'clamav', 'port' => 3310], +- ], +- ], +- ]; - -- $config['clamav.settings']['scan_mode'] = 1; -- $config['clamav.settings']['executable_path'] = '/usr/bin/clamscan'; +- yield 'executable mode' => [ +- [ +- 'DRUPAL_CLAMAV_ENABLED' => 1, +- 'CLAMAV_HOST' => 'custom_clamav_host', +- 'CLAMAV_PORT' => 3333, +- ], +- [ +- 'clamav.settings' => ['scan_mode' => 1, 'executable_path' => '/usr/bin/clamscan'], +- ], +- ]; - -- $this->assertConfigContains($config); -- } +- yield 'variable not set' => [ +- [], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; - -- /** -- * Test ClamAV configs in Daemon mode with defaults. -- */ -- public function testClamavDaemonDefaults(): void { -- $this->setEnvVars([ -- 'DRUPAL_CLAMAV_ENABLED' => TRUE, -- 'DRUPAL_CLAMAV_MODE' => 'daemon', -- ]); -- -- $this->requireSettingsFile(); +- yield 'variable set to an empty value' => [ +- ['DRUPAL_CLAMAV_ENABLED' => ''], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; - -- $config['clamav.settings']['scan_mode'] = 0; -- $config['clamav.settings']['mode_daemon_tcpip']['hostname'] = 'clamav'; -- $config['clamav.settings']['mode_daemon_tcpip']['port'] = 3310; +- yield 'variable set to zero' => [ +- ['DRUPAL_CLAMAV_ENABLED' => '0'], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; - -- $this->assertConfigContains($config); +- yield 'variable set to a non-numeric truthy value' => [ +- ['DRUPAL_CLAMAV_ENABLED' => 'true'], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; - } - - /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/provision_database_lagoon/web/sites/default/includes/providers/settings.lagoon.php b/.vortex/installer/tests/Fixtures/handler_process/provision_database_lagoon/web/sites/default/includes/providers/settings.lagoon.php index 48af018642..aebfeff969 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/provision_database_lagoon/web/sites/default/includes/providers/settings.lagoon.php +++ b/.vortex/installer/tests/Fixtures/handler_process/provision_database_lagoon/web/sites/default/includes/providers/settings.lagoon.php @@ -13,7 +13,10 @@ declare(strict_types=1); if (!empty(getenv('LAGOON_KUBERNETES'))) { - if (getenv('LAGOON_ENVIRONMENT_TYPE') == 'production') { + $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); + $lagoon_production_branch = getenv('VORTEX_LAGOON_PRODUCTION_BRANCH'); + + if (getenv('LAGOON_ENVIRONMENT_TYPE') === 'production') { $settings['environment'] = ENVIRONMENT_PROD; } else { @@ -21,20 +24,17 @@ // The environment may not be marked as 'production' in Lagoon yet, so // detect the production environment by the branch name as well. - if (!empty(getenv('LAGOON_GIT_BRANCH')) && !empty(getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) && getenv('LAGOON_GIT_BRANCH') === getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')) { + if (!empty($lagoon_git_branch) && !empty($lagoon_production_branch) && $lagoon_git_branch === $lagoon_production_branch) { $settings['environment'] = ENVIRONMENT_PROD; } // Dedicated test environment based on a branch name. - elseif (getenv('LAGOON_GIT_BRANCH') == 'main' || getenv('LAGOON_GIT_BRANCH') == 'master') { + elseif ($lagoon_git_branch === 'main' || $lagoon_git_branch === 'master') { $settings['environment'] = ENVIRONMENT_STAGE; } // Test environment based on a branch prefix for release and // hotfix branches. - elseif (!empty(getenv('LAGOON_GIT_BRANCH'))) { - $lagoon_git_branch = getenv('LAGOON_GIT_BRANCH'); - if ($lagoon_git_branch && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { - $settings['environment'] = ENVIRONMENT_STAGE; - } + elseif (!empty($lagoon_git_branch) && (str_starts_with($lagoon_git_branch, 'release/') || str_starts_with($lagoon_git_branch, 'hotfix/'))) { + $settings['environment'] = ENVIRONMENT_STAGE; } } @@ -45,7 +45,7 @@ $settings['reverse_proxy'] = TRUE; $settings['reverse_proxy_header'] = 'HTTP_TRUE_CLIENT_IP'; - $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: getenv('VORTEX_LAGOON_PRODUCTION_BRANCH')); + $settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('VORTEX_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: $lagoon_production_branch); // Trusted host patterns for Lagoon internal routes. // Do not modify this section. Instead, add your custom patterns to the @@ -55,7 +55,7 @@ // Trust amazee.io's autogenerated internal routes, served under *.amazee.io. $settings['trusted_host_patterns'][] = '^.+\.amazee\.io$'; $lagoon_routes = getenv('LAGOON_ROUTES'); - if ($lagoon_routes) { + if (!empty($lagoon_routes)) { $lagoon_route_urls = array_map(trim(...), explode(',', $lagoon_routes)); foreach ($lagoon_route_urls as $lagoon_route_url) { // parse_url() reads a scheme-less value as a path, so re-parse with '//' diff --git a/.vortex/installer/tests/Fixtures/handler_process/services_no_clamav/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/services_no_clamav/tests/phpunit/Drupal/SwitchableSettingsTest.php index a2c5670bb2..3bad585270 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/services_no_clamav/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/services_no_clamav/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,60 +1,85 @@ -@@ -38,62 +38,6 @@ +@@ -38,87 +38,6 @@ } /** -- * Test ClamAV configs in Daemon mode with defaults. +- * Test ClamAV config. - */ -- public function testClamavDaemonCustom(): void { -- $this->setEnvVars([ -- 'DRUPAL_CLAMAV_ENABLED' => TRUE, -- 'DRUPAL_CLAMAV_MODE' => 'daemon', -- 'CLAMAV_HOST' => 'custom_clamav_host', -- 'CLAMAV_PORT' => 3333, -- ]); +- #[DataProvider('dataProviderClamav')] +- public function testClamav(array $vars, array $expected_present, array $expected_absent = []): void { +- $this->setEnvVars($vars); - - $this->requireSettingsFile(); - -- $config['clamav.settings']['scan_mode'] = 0; -- $config['clamav.settings']['mode_daemon_tcpip']['hostname'] = 'custom_clamav_host'; -- $config['clamav.settings']['mode_daemon_tcpip']['port'] = 3333; -- -- $this->assertConfigContains($config); +- $this->assertConfigContains($expected_present); +- $this->assertConfigNotContains($expected_absent); - } - - /** -- * Test ClamAV configs in Executable mode. +- * Data provider for testClamav(). - */ -- public function testClamavExecutable(): void { -- $this->setEnvVars([ -- 'DRUPAL_CLAMAV_ENABLED' => TRUE, -- 'CLAMAV_HOST' => 'custom_clamav_host', -- 'CLAMAV_PORT' => 3333, -- ]); +- public static function dataProviderClamav(): \Iterator { +- yield 'daemon mode with custom host and port' => [ +- [ +- 'DRUPAL_CLAMAV_ENABLED' => 1, +- 'DRUPAL_CLAMAV_MODE' => 'daemon', +- 'CLAMAV_HOST' => 'custom_clamav_host', +- 'CLAMAV_PORT' => 3333, +- ], +- [ +- 'clamav.settings' => [ +- 'scan_mode' => 0, +- 'mode_daemon_tcpip' => ['hostname' => 'custom_clamav_host', 'port' => 3333], +- ], +- ], +- ]; - -- $this->requireSettingsFile(); +- yield 'daemon mode with defaults' => [ +- [ +- 'DRUPAL_CLAMAV_ENABLED' => 1, +- 'DRUPAL_CLAMAV_MODE' => 'daemon', +- ], +- [ +- 'clamav.settings' => [ +- 'scan_mode' => 0, +- 'mode_daemon_tcpip' => ['hostname' => 'clamav', 'port' => 3310], +- ], +- ], +- ]; - -- $config['clamav.settings']['scan_mode'] = 1; -- $config['clamav.settings']['executable_path'] = '/usr/bin/clamscan'; +- yield 'executable mode' => [ +- [ +- 'DRUPAL_CLAMAV_ENABLED' => 1, +- 'CLAMAV_HOST' => 'custom_clamav_host', +- 'CLAMAV_PORT' => 3333, +- ], +- [ +- 'clamav.settings' => ['scan_mode' => 1, 'executable_path' => '/usr/bin/clamscan'], +- ], +- ]; - -- $this->assertConfigContains($config); -- } +- yield 'variable not set' => [ +- [], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; - -- /** -- * Test ClamAV configs in Daemon mode with defaults. -- */ -- public function testClamavDaemonDefaults(): void { -- $this->setEnvVars([ -- 'DRUPAL_CLAMAV_ENABLED' => TRUE, -- 'DRUPAL_CLAMAV_MODE' => 'daemon', -- ]); -- -- $this->requireSettingsFile(); +- yield 'variable set to an empty value' => [ +- ['DRUPAL_CLAMAV_ENABLED' => ''], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; - -- $config['clamav.settings']['scan_mode'] = 0; -- $config['clamav.settings']['mode_daemon_tcpip']['hostname'] = 'clamav'; -- $config['clamav.settings']['mode_daemon_tcpip']['port'] = 3310; +- yield 'variable set to zero' => [ +- ['DRUPAL_CLAMAV_ENABLED' => '0'], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; - -- $this->assertConfigContains($config); +- yield 'variable set to a non-numeric truthy value' => [ +- ['DRUPAL_CLAMAV_ENABLED' => 'true'], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; - } - - /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/services_no_redis/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/services_no_redis/tests/phpunit/Drupal/SwitchableSettingsTest.php index ad65210ed5..f89e3ae142 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/services_no_redis/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/services_no_redis/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,76 +1,83 @@ -@@ -345,78 +345,6 @@ +@@ -370,85 +370,6 @@ } /** - * Test Redis settings. - */ -- public function testRedis(): void { -- $this->setEnvVars([ -- 'DRUPAL_REDIS_ENABLED' => 1, -- 'REDIS_HOST' => 'redis_host', -- 'REDIS_SERVICE_PORT' => 1234, -- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, -- ]); +- #[DataProvider('dataProviderRedis')] +- public function testRedis(array $vars, bool $expected_enabled, array $expected_settings): void { +- $this->setEnvVars($vars); - - $this->requireSettingsFile(); - -- $settings['redis.connection']['interface'] = 'PhpRedis'; -- $settings['redis.connection']['host'] = 'redis_host'; -- $settings['redis.connection']['port'] = 1234; -- $settings['cache']['default'] = 'cache.backend.redis'; -- -- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); +- $this->assertSame($expected_enabled, array_key_exists('bootstrap_container_definition', $this->settings), 'Bootstrap container definition'); - unset($this->settings['bootstrap_container_definition']); - -- $this->assertSettingsContains($settings); -- } -- -- /** -- * Test Redis settings with REDIS_* environment variables. -- */ -- public function testRedisVariables(): void { -- $this->setEnvVars([ -- 'DRUPAL_REDIS_ENABLED' => 1, -- 'REDIS_HOST' => 'redis_host', -- 'REDIS_SERVICE_PORT' => 6380, -- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, -- ]); -- -- $this->requireSettingsFile(); +- if ($expected_enabled) { +- $this->assertSettingsContains($expected_settings); - -- $settings['redis.connection']['interface'] = 'PhpRedis'; -- $settings['redis.connection']['host'] = 'redis_host'; -- $settings['redis.connection']['port'] = 6380; -- $settings['cache']['default'] = 'cache.backend.redis'; +- return; +- } - -- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); -- unset($this->settings['bootstrap_container_definition']); -- -- $this->assertSettingsContains($settings); +- $this->assertSettingsNotContains($expected_settings); - } - - /** -- * Test Redis settings with custom port. +- * Data provider for testRedis(). - */ -- public function testRedisCustomPort(): void { -- $this->setEnvVars([ -- 'DRUPAL_REDIS_ENABLED' => 1, -- 'REDIS_HOST' => 'custom_redis_host', -- 'REDIS_SERVICE_PORT' => 6380, -- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, -- ]); +- public static function dataProviderRedis(): \Iterator { +- $disabled_settings = ['redis.connection' => ['interface' => NULL], 'cache' => ['default' => NULL]]; - -- $this->requireSettingsFile(); +- yield 'default port' => [ +- [ +- 'DRUPAL_REDIS_ENABLED' => 1, +- 'REDIS_HOST' => 'redis_host', +- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, +- ], +- TRUE, +- [ +- 'redis.connection' => ['interface' => 'PhpRedis', 'host' => 'redis_host', 'port' => '6379'], +- 'cache' => ['default' => 'cache.backend.redis'], +- ], +- ]; - -- $settings['redis.connection']['interface'] = 'PhpRedis'; -- $settings['redis.connection']['host'] = 'custom_redis_host'; -- $settings['redis.connection']['port'] = 6380; -- $settings['cache']['default'] = 'cache.backend.redis'; +- yield 'custom host and port' => [ +- [ +- 'DRUPAL_REDIS_ENABLED' => 1, +- 'REDIS_HOST' => 'custom_redis_host', +- 'REDIS_SERVICE_PORT' => 6380, +- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, +- ], +- TRUE, +- [ +- 'redis.connection' => ['interface' => 'PhpRedis', 'host' => 'custom_redis_host', 'port' => 6380], +- 'cache' => ['default' => 'cache.backend.redis'], +- ], +- ]; - -- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); -- unset($this->settings['bootstrap_container_definition']); +- yield 'variable not set' => [ +- ['VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; +- +- yield 'variable set to an empty value' => [ +- ['DRUPAL_REDIS_ENABLED' => '', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; +- +- yield 'variable set to zero' => [ +- ['DRUPAL_REDIS_ENABLED' => '0', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; - -- $this->assertSettingsContains($settings); +- yield 'variable set to a non-numeric truthy value' => [ +- ['DRUPAL_REDIS_ENABLED' => 'true', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; - } - - /** diff --git a/.vortex/installer/tests/Fixtures/handler_process/services_none/tests/phpunit/Drupal/SwitchableSettingsTest.php b/.vortex/installer/tests/Fixtures/handler_process/services_none/tests/phpunit/Drupal/SwitchableSettingsTest.php index 8243b5bfc0..999904ab4a 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/services_none/tests/phpunit/Drupal/SwitchableSettingsTest.php +++ b/.vortex/installer/tests/Fixtures/handler_process/services_none/tests/phpunit/Drupal/SwitchableSettingsTest.php @@ -1,67 +1,92 @@ -@@ -38,62 +38,6 @@ +@@ -38,87 +38,6 @@ } /** -- * Test ClamAV configs in Daemon mode with defaults. +- * Test ClamAV config. - */ -- public function testClamavDaemonCustom(): void { -- $this->setEnvVars([ -- 'DRUPAL_CLAMAV_ENABLED' => TRUE, -- 'DRUPAL_CLAMAV_MODE' => 'daemon', -- 'CLAMAV_HOST' => 'custom_clamav_host', -- 'CLAMAV_PORT' => 3333, -- ]); +- #[DataProvider('dataProviderClamav')] +- public function testClamav(array $vars, array $expected_present, array $expected_absent = []): void { +- $this->setEnvVars($vars); - - $this->requireSettingsFile(); - -- $config['clamav.settings']['scan_mode'] = 0; -- $config['clamav.settings']['mode_daemon_tcpip']['hostname'] = 'custom_clamav_host'; -- $config['clamav.settings']['mode_daemon_tcpip']['port'] = 3333; -- -- $this->assertConfigContains($config); -- } -- -- /** -- * Test ClamAV configs in Executable mode. -- */ -- public function testClamavExecutable(): void { -- $this->setEnvVars([ -- 'DRUPAL_CLAMAV_ENABLED' => TRUE, -- 'CLAMAV_HOST' => 'custom_clamav_host', -- 'CLAMAV_PORT' => 3333, -- ]); -- -- $this->requireSettingsFile(); -- -- $config['clamav.settings']['scan_mode'] = 1; -- $config['clamav.settings']['executable_path'] = '/usr/bin/clamscan'; -- -- $this->assertConfigContains($config); +- $this->assertConfigContains($expected_present); +- $this->assertConfigNotContains($expected_absent); - } - - /** -- * Test ClamAV configs in Daemon mode with defaults. +- * Data provider for testClamav(). - */ -- public function testClamavDaemonDefaults(): void { -- $this->setEnvVars([ -- 'DRUPAL_CLAMAV_ENABLED' => TRUE, -- 'DRUPAL_CLAMAV_MODE' => 'daemon', -- ]); -- -- $this->requireSettingsFile(); -- -- $config['clamav.settings']['scan_mode'] = 0; -- $config['clamav.settings']['mode_daemon_tcpip']['hostname'] = 'clamav'; -- $config['clamav.settings']['mode_daemon_tcpip']['port'] = 3310; -- -- $this->assertConfigContains($config); +- public static function dataProviderClamav(): \Iterator { +- yield 'daemon mode with custom host and port' => [ +- [ +- 'DRUPAL_CLAMAV_ENABLED' => 1, +- 'DRUPAL_CLAMAV_MODE' => 'daemon', +- 'CLAMAV_HOST' => 'custom_clamav_host', +- 'CLAMAV_PORT' => 3333, +- ], +- [ +- 'clamav.settings' => [ +- 'scan_mode' => 0, +- 'mode_daemon_tcpip' => ['hostname' => 'custom_clamav_host', 'port' => 3333], +- ], +- ], +- ]; +- +- yield 'daemon mode with defaults' => [ +- [ +- 'DRUPAL_CLAMAV_ENABLED' => 1, +- 'DRUPAL_CLAMAV_MODE' => 'daemon', +- ], +- [ +- 'clamav.settings' => [ +- 'scan_mode' => 0, +- 'mode_daemon_tcpip' => ['hostname' => 'clamav', 'port' => 3310], +- ], +- ], +- ]; +- +- yield 'executable mode' => [ +- [ +- 'DRUPAL_CLAMAV_ENABLED' => 1, +- 'CLAMAV_HOST' => 'custom_clamav_host', +- 'CLAMAV_PORT' => 3333, +- ], +- [ +- 'clamav.settings' => ['scan_mode' => 1, 'executable_path' => '/usr/bin/clamscan'], +- ], +- ]; +- +- yield 'variable not set' => [ +- [], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; +- +- yield 'variable set to an empty value' => [ +- ['DRUPAL_CLAMAV_ENABLED' => ''], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; +- +- yield 'variable set to zero' => [ +- ['DRUPAL_CLAMAV_ENABLED' => '0'], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; +- +- yield 'variable set to a non-numeric truthy value' => [ +- ['DRUPAL_CLAMAV_ENABLED' => 'true'], +- [], +- ['clamav.settings' => ['scan_mode' => NULL]], +- ]; - } - - /** * Test Config Split config. */ #[DataProvider('dataProviderConfigSplit')] -@@ -342,78 +286,6 @@ +@@ -367,85 +286,6 @@ } rmdir($path); @@ -70,73 +95,80 @@ - /** - * Test Redis settings. - */ -- public function testRedis(): void { -- $this->setEnvVars([ -- 'DRUPAL_REDIS_ENABLED' => 1, -- 'REDIS_HOST' => 'redis_host', -- 'REDIS_SERVICE_PORT' => 1234, -- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, -- ]); +- #[DataProvider('dataProviderRedis')] +- public function testRedis(array $vars, bool $expected_enabled, array $expected_settings): void { +- $this->setEnvVars($vars); - - $this->requireSettingsFile(); - -- $settings['redis.connection']['interface'] = 'PhpRedis'; -- $settings['redis.connection']['host'] = 'redis_host'; -- $settings['redis.connection']['port'] = 1234; -- $settings['cache']['default'] = 'cache.backend.redis'; -- -- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); +- $this->assertSame($expected_enabled, array_key_exists('bootstrap_container_definition', $this->settings), 'Bootstrap container definition'); - unset($this->settings['bootstrap_container_definition']); - -- $this->assertSettingsContains($settings); -- } -- -- /** -- * Test Redis settings with REDIS_* environment variables. -- */ -- public function testRedisVariables(): void { -- $this->setEnvVars([ -- 'DRUPAL_REDIS_ENABLED' => 1, -- 'REDIS_HOST' => 'redis_host', -- 'REDIS_SERVICE_PORT' => 6380, -- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, -- ]); -- -- $this->requireSettingsFile(); -- -- $settings['redis.connection']['interface'] = 'PhpRedis'; -- $settings['redis.connection']['host'] = 'redis_host'; -- $settings['redis.connection']['port'] = 6380; -- $settings['cache']['default'] = 'cache.backend.redis'; +- if ($expected_enabled) { +- $this->assertSettingsContains($expected_settings); - -- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); -- unset($this->settings['bootstrap_container_definition']); +- return; +- } - -- $this->assertSettingsContains($settings); +- $this->assertSettingsNotContains($expected_settings); - } - - /** -- * Test Redis settings with custom port. +- * Data provider for testRedis(). - */ -- public function testRedisCustomPort(): void { -- $this->setEnvVars([ -- 'DRUPAL_REDIS_ENABLED' => 1, -- 'REDIS_HOST' => 'custom_redis_host', -- 'REDIS_SERVICE_PORT' => 6380, -- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, -- ]); -- -- $this->requireSettingsFile(); -- -- $settings['redis.connection']['interface'] = 'PhpRedis'; -- $settings['redis.connection']['host'] = 'custom_redis_host'; -- $settings['redis.connection']['port'] = 6380; -- $settings['cache']['default'] = 'cache.backend.redis'; -- -- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings); -- unset($this->settings['bootstrap_container_definition']); -- -- $this->assertSettingsContains($settings); +- public static function dataProviderRedis(): \Iterator { +- $disabled_settings = ['redis.connection' => ['interface' => NULL], 'cache' => ['default' => NULL]]; +- +- yield 'default port' => [ +- [ +- 'DRUPAL_REDIS_ENABLED' => 1, +- 'REDIS_HOST' => 'redis_host', +- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, +- ], +- TRUE, +- [ +- 'redis.connection' => ['interface' => 'PhpRedis', 'host' => 'redis_host', 'port' => '6379'], +- 'cache' => ['default' => 'cache.backend.redis'], +- ], +- ]; +- +- yield 'custom host and port' => [ +- [ +- 'DRUPAL_REDIS_ENABLED' => 1, +- 'REDIS_HOST' => 'custom_redis_host', +- 'REDIS_SERVICE_PORT' => 6380, +- 'VORTEX_REDIS_EXTENSION_LOADED' => 1, +- ], +- TRUE, +- [ +- 'redis.connection' => ['interface' => 'PhpRedis', 'host' => 'custom_redis_host', 'port' => 6380], +- 'cache' => ['default' => 'cache.backend.redis'], +- ], +- ]; +- +- yield 'variable not set' => [ +- ['VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; +- +- yield 'variable set to an empty value' => [ +- ['DRUPAL_REDIS_ENABLED' => '', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; +- +- yield 'variable set to zero' => [ +- ['DRUPAL_REDIS_ENABLED' => '0', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; +- +- yield 'variable set to a non-numeric truthy value' => [ +- ['DRUPAL_REDIS_ENABLED' => 'true', 'VORTEX_REDIS_EXTENSION_LOADED' => 1], +- FALSE, +- $disabled_settings, +- ]; } /** From 4d446ceee9b83e24c8eea894d1a95048805a8e8b Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Wed, 9 Sep 2026 09:46:54 +1000 Subject: [PATCH 3/5] [#3112] Created the scratch directory before writing the Acquia settings fixture. A clean checkout has no '.artifacts/tmp', so 'file_put_contents()' failed and the settings file guard threw before the temporary path assertions ran. --- .../Drupal/EnvironmentSettingsTest.php | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/Drupal/EnvironmentSettingsTest.php b/tests/phpunit/Drupal/EnvironmentSettingsTest.php index 8ccc460240..127c2b8e62 100644 --- a/tests/phpunit/Drupal/EnvironmentSettingsTest.php +++ b/tests/phpunit/Drupal/EnvironmentSettingsTest.php @@ -34,7 +34,7 @@ class EnvironmentSettingsTest extends SettingsTestCase { * {@inheritdoc} */ protected function tearDown(): void { - if (!is_null($this->acquiaSettingsFixture)) { + if (!is_null($this->acquiaSettingsFixture) && file_exists($this->acquiaSettingsFixture)) { unlink($this->acquiaSettingsFixture); } @@ -1372,8 +1372,7 @@ public function testEnvironmentAcquiaConfigVcsDirectoryFallback(): void { */ #[DataProvider('dataProviderEnvironmentAcquiaTempPath')] public function testEnvironmentAcquiaTempPath(array $vars, string $expected_path): void { - $this->acquiaSettingsFixture = getcwd() . '/.artifacts/tmp/' . uniqid('acquia-settings-') . '.inc'; - file_put_contents($this->acquiaSettingsFixture, "acquiaSettingsFixture = $this->createAcquiaSettingsFixture(); $this->setEnvVars($vars + ['DRUPAL_ACQUIA_SETTINGS_FILE' => $this->acquiaSettingsFixture]); @@ -1432,6 +1431,28 @@ public static function dataProviderEnvironmentAcquiaTempPath(): \Iterator { ]; } + /** + * Create an Acquia settings file fixture. + * + * The settings file is required when a site group is set, so the shared + * mount branch can only be reached through a file that exists. + * + * @return string + * Path to the settings file fixture. + */ + protected function createAcquiaSettingsFixture(): string { + $dir = getcwd() . '/.artifacts/tmp'; + + if (!is_dir($dir)) { + mkdir($dir, 0777, TRUE); + } + + $file = $dir . '/' . uniqid('acquia-settings-') . '.inc'; + file_put_contents($file, " SETTINGS_PROVIDER_ACQUIA // phpcs:ignore #;< SETTINGS_PROVIDER_LAGOON /** From afd6f100db4531f613ab73b63981267a431ecff9 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Wed, 9 Sep 2026 09:48:28 +1000 Subject: [PATCH 4/5] Updated snapshots. --- .../Drupal/EnvironmentSettingsTest.php | 29 ++++++++++++++++--- .../Drupal/EnvironmentSettingsTest.php | 29 ++++++++++++++++--- 2 files changed, 50 insertions(+), 8 deletions(-) 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 8e6805b964..e4c7a138fa 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 @@ -10,7 +10,7 @@ class EnvironmentSettingsTest extends SettingsTestCase { + * {@inheritdoc} + */ + protected function tearDown(): void { -+ if (!is_null($this->acquiaSettingsFixture)) { ++ if (!is_null($this->acquiaSettingsFixture) && file_exists($this->acquiaSettingsFixture)) { + unlink($this->acquiaSettingsFixture); + } + @@ -72,7 +72,7 @@ class EnvironmentSettingsTest extends SettingsTestCase { } /** -@@ -476,6 +536,480 @@ +@@ -476,6 +536,501 @@ ]; $this->assertSettings($settings); @@ -492,8 +492,7 @@ class EnvironmentSettingsTest extends SettingsTestCase { + */ + #[DataProvider('dataProviderEnvironmentAcquiaTempPath')] + public function testEnvironmentAcquiaTempPath(array $vars, string $expected_path): void { -+ $this->acquiaSettingsFixture = getcwd() . '/.artifacts/tmp/' . uniqid('acquia-settings-') . '.inc'; -+ file_put_contents($this->acquiaSettingsFixture, "acquiaSettingsFixture = $this->createAcquiaSettingsFixture(); + + $this->setEnvVars($vars + ['DRUPAL_ACQUIA_SETTINGS_FILE' => $this->acquiaSettingsFixture]); + @@ -550,6 +549,28 @@ class EnvironmentSettingsTest extends SettingsTestCase { + ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH' => ''], + '/tmp', + ]; ++ } ++ ++ /** ++ * Create an Acquia settings file fixture. ++ * ++ * The settings file is required when a site group is set, so the shared ++ * mount branch can only be reached through a file that exists. ++ * ++ * @return string ++ * Path to the settings file fixture. ++ */ ++ protected function createAcquiaSettingsFixture(): string { ++ $dir = getcwd() . '/.artifacts/tmp'; ++ ++ if (!is_dir($dir)) { ++ mkdir($dir, 0777, TRUE); ++ } ++ ++ $file = $dir . '/' . uniqid('acquia-settings-') . '.inc'; ++ file_put_contents($file, "acquiaSettingsFixture)) { ++ if (!is_null($this->acquiaSettingsFixture) && file_exists($this->acquiaSettingsFixture)) { + unlink($this->acquiaSettingsFixture); + } + @@ -72,7 +72,7 @@ class EnvironmentSettingsTest extends SettingsTestCase { } /** -@@ -476,6 +536,480 @@ +@@ -476,6 +536,501 @@ ]; $this->assertSettings($settings); @@ -492,8 +492,7 @@ class EnvironmentSettingsTest extends SettingsTestCase { + */ + #[DataProvider('dataProviderEnvironmentAcquiaTempPath')] + public function testEnvironmentAcquiaTempPath(array $vars, string $expected_path): void { -+ $this->acquiaSettingsFixture = getcwd() . '/.artifacts/tmp/' . uniqid('acquia-settings-') . '.inc'; -+ file_put_contents($this->acquiaSettingsFixture, "acquiaSettingsFixture = $this->createAcquiaSettingsFixture(); + + $this->setEnvVars($vars + ['DRUPAL_ACQUIA_SETTINGS_FILE' => $this->acquiaSettingsFixture]); + @@ -550,6 +549,28 @@ class EnvironmentSettingsTest extends SettingsTestCase { + ['AH_SITE_ENVIRONMENT' => 'dev', 'AH_SITE_GROUP' => 'mysite', 'DRUPAL_TMP_PATH' => ''], + '/tmp', + ]; ++ } ++ ++ /** ++ * Create an Acquia settings file fixture. ++ * ++ * The settings file is required when a site group is set, so the shared ++ * mount branch can only be reached through a file that exists. ++ * ++ * @return string ++ * Path to the settings file fixture. ++ */ ++ protected function createAcquiaSettingsFixture(): string { ++ $dir = getcwd() . '/.artifacts/tmp'; ++ ++ if (!is_dir($dir)) { ++ mkdir($dir, 0777, TRUE); ++ } ++ ++ $file = $dir . '/' . uniqid('acquia-settings-') . '.inc'; ++ file_put_contents($file, " Date: Wed, 9 Sep 2026 10:11:14 +1000 Subject: [PATCH 5/5] Addressed code review: documented that shipped flags accept only '1'. An environment carrying a legacy 'true' or 'yes' value silently turns the behavior off after the upgrade, so the settings guide now names every affected variable and the value to set. --- .vortex/docs/content/development/settings.mdx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.vortex/docs/content/development/settings.mdx b/.vortex/docs/content/development/settings.mdx index 830209f494..33584b5be2 100644 --- a/.vortex/docs/content/development/settings.mdx +++ b/.vortex/docs/content/development/settings.mdx @@ -358,6 +358,17 @@ A _value carrier_ - a variable whose value is used - is read with value is needed after the guard.
Compare with `===` and `!==`, never with `==`. +:::warning Flags accept only `1` + +An environment that sets a shipped flag to `true`, `yes`, `on` or any other +non-empty value gets the behavior turned **off**. Set every flag below to `1` +in your hosting provider's environment variables: `DRUPAL_CLAMAV_ENABLED`, +`DRUPAL_REDIS_ENABLED`, `DRUPAL_REROUTE_EMAIL_DISABLED`, +`DRUPAL_SHIELD_DISABLED`, `DRUPAL_SHIELD_ALLOW_ACME_CHALLENGE`, +`DRUPAL_TMP_PATH_IS_SHARED` and `DRUPAL_SETTINGS_LOCAL_SKIP`. + +::: + - **Gate on the presence of a contributed module only when the file needs it.**
`file_exists($contrib_path . '/my_module')` belongs in an override file that loads a file from the module directory or registers its paths. An override file