]> BookStack Code Mirror - bookstack/blob - tests/Unit/ConfigTest.php
Update common.php
[bookstack] / tests / Unit / ConfigTest.php
1 <?php namespace Tests;
2
3 /**
4  * Class ConfigTest
5  * Many of the tests here are to check on tweaks made
6  * to maintain backwards compatibility.
7  *
8  * @package Tests
9  */
10 class ConfigTest extends TestCase
11 {
12
13     public function test_filesystem_images_falls_back_to_storage_type_var()
14     {
15         putenv('STORAGE_TYPE=local_secure');
16
17         $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', 's3', 'filesystems.images', 's3');
18         $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', null, 'filesystems.images', 'local_secure');
19
20         putenv('STORAGE_TYPE=local');
21     }
22
23     public function test_filesystem_attachments_falls_back_to_storage_type_var()
24     {
25         putenv('STORAGE_TYPE=local_secure');
26
27         $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
28         $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
29
30         putenv('STORAGE_TYPE=local');
31     }
32
33     public function test_app_url_blank_if_old_default_value()
34     {
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', '');
39     }
40
41     /**
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
49      */
50     protected function checkEnvConfigResult(string $envName, $envVal, string $configKey, string $expectedResult)
51     {
52         $originalVal = getenv($envName);
53         $envString = $envName . (is_null($envVal) ? '' : '=') . ($envVal ?? '');
54         putenv($envString);
55         $this->refreshApplication();
56         $this->assertEquals($expectedResult, config($configKey));
57         putenv($envString = $envName . (empty($originalVal) ? '' : '=') . ($originalVal ?? ''));
58     }
59
60 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.