5 * Many of the tests here are to check on tweaks made
6 * to maintain backwards compatibility.
10 class ConfigTest extends TestCase
13 public function test_filesystem_images_falls_back_to_storage_type_var()
15 putenv('STORAGE_TYPE=local_secure');
17 $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', 's3', 'filesystems.images', 's3');
18 $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', null, 'filesystems.images', 'local_secure');
20 putenv('STORAGE_TYPE=local');
23 public function test_filesystem_attachments_falls_back_to_storage_type_var()
25 putenv('STORAGE_TYPE=local_secure');
27 $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
28 $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
30 putenv('STORAGE_TYPE=local');
33 public function test_app_url_blank_if_old_default_value()
35 $initUrl = 'https://example.com/docs';
36 $oldDefault = 'http://bookstack.dev';
37 $this->checkEnvConfigResult('APP_URL', $initUrl, 'app.url', $initUrl);
38 $this->checkEnvConfigResult('APP_URL', $oldDefault, 'app.url', '');
42 * Set an environment variable of the given name and value
43 * then check the given config key to see if it matches the given result.
44 * Providing a null $envVal clears the variable.
45 * @param string $envName
46 * @param string|null $envVal
47 * @param string $configKey
48 * @param string $expectedResult
50 protected function checkEnvConfigResult(string $envName, $envVal, string $configKey, string $expectedResult)
52 $originalVal = getenv($envName);
53 $envString = $envName . (is_null($envVal) ? '' : '=') . ($envVal ?? '');
55 $this->refreshApplication();
56 $this->assertEquals($expectedResult, config($configKey));
57 putenv($envString = $envName . (empty($originalVal) ? '' : '=') . ($originalVal ?? ''));