]> BookStack Code Mirror - bookstack/blob - tests/Unit/ConfigTest.php
Allowed different storage types for images and attachments
[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
21     public function test_filesystem_attachments_falls_back_to_storage_type_var()
22     {
23         putenv('STORAGE_TYPE=local_secure');
24
25         $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
26         $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
27     }
28
29     public function test_app_url_blank_if_old_default_value()
30     {
31         $initUrl = 'https://example.com/docs';
32         $oldDefault = 'http://bookstack.dev';
33         $this->checkEnvConfigResult('APP_URL', $initUrl, 'app.url', $initUrl);
34         $this->checkEnvConfigResult('APP_URL', $oldDefault, 'app.url', '');
35     }
36
37     /**
38      * Set an environment variable of the given name and value
39      * then check the given config key to see if it matches the given result.
40      * Providing a null $envVal clears the variable.
41      * @param string $envName
42      * @param string|null $envVal
43      * @param string $configKey
44      * @param string $expectedResult
45      */
46     protected function checkEnvConfigResult(string $envName, $envVal, string $configKey, string $expectedResult)
47     {
48         $envString = $envName . (is_null($envVal) ? '' : '=') . ($envVal ?? '');
49         putenv($envString);
50         $this->refreshApplication();
51         $this->assertEquals($expectedResult, config($configKey));
52     }
53
54 }