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