]> BookStack Code Mirror - bookstack/blob - tests/Unit/ConfigTest.php
Merge branch 'feature/#1598' of git://github.com/cw1998/BookStack into cw1998-feature...
[bookstack] / tests / Unit / ConfigTest.php
1 <?php namespace Tests\Unit;
2
3 use Tests\TestCase;
4
5 /**
6  * Class ConfigTest
7  * Many of the tests here are to check on tweaks made
8  * to maintain backwards compatibility.
9  *
10  * @package Tests
11  */
12 class ConfigTest extends TestCase
13 {
14
15     public function test_filesystem_images_falls_back_to_storage_type_var()
16     {
17         $this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
18             $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', 's3', 'filesystems.images', 's3');
19             $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', null, 'filesystems.images', 'local_secure');
20         });
21     }
22
23     public function test_filesystem_attachments_falls_back_to_storage_type_var()
24     {
25         $this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
26             $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
27             $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
28         });
29     }
30
31     public function test_app_url_blank_if_old_default_value()
32     {
33         $initUrl = 'https://example.com/docs';
34         $oldDefault = 'http://bookstack.dev';
35         $this->checkEnvConfigResult('APP_URL', $initUrl, 'app.url', $initUrl);
36         $this->checkEnvConfigResult('APP_URL', $oldDefault, 'app.url', '');
37     }
38
39     /**
40      * Set an environment variable of the given name and value
41      * then check the given config key to see if it matches the given result.
42      * Providing a null $envVal clears the variable.
43      * @param string $envName
44      * @param string|null $envVal
45      * @param string $configKey
46      * @param string $expectedResult
47      */
48     protected function checkEnvConfigResult(string $envName, $envVal, string $configKey, string $expectedResult)
49     {
50         $this->runWithEnv($envName, $envVal, function() use ($configKey, $expectedResult) {
51             $this->assertEquals($expectedResult, config($configKey));
52         });
53     }
54
55 }