]> BookStack Code Mirror - bookstack/blob - tests/Unit/ConfigTest.php
Merge branch 'fix-1575' of git://github.com/james-geiger/BookStack into james-geiger...
[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         $this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
24             $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
25             $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
26         });
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         $this->runWithEnv($envName, $envVal, function() use ($configKey, $expectedResult) {
49             $this->assertEquals($expectedResult, config($configKey));
50         });
51     }
52
53 }