]> BookStack Code Mirror - bookstack/blob - tests/Unit/ConfigTest.php
Update form.blade.php
[bookstack] / tests / Unit / ConfigTest.php
1 <?php namespace Tests\Unit;
2
3 use Illuminate\Support\Facades\Log;
4 use Tests\TestCase;
5
6 /**
7  * Class ConfigTest
8  * Many of the tests here are to check on tweaks made
9  * to maintain backwards compatibility.
10  *
11  * @package Tests
12  */
13 class ConfigTest extends TestCase
14 {
15
16     public function test_filesystem_images_falls_back_to_storage_type_var()
17     {
18         $this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
19             $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', 's3', 'filesystems.images', 's3');
20             $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', null, 'filesystems.images', 'local_secure');
21         });
22     }
23
24     public function test_filesystem_attachments_falls_back_to_storage_type_var()
25     {
26         $this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
27             $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
28             $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
29         });
30     }
31
32     public function test_app_url_blank_if_old_default_value()
33     {
34         $initUrl = 'https://example.com/docs';
35         $oldDefault = 'http://bookstack.dev';
36         $this->checkEnvConfigResult('APP_URL', $initUrl, 'app.url', $initUrl);
37         $this->checkEnvConfigResult('APP_URL', $oldDefault, 'app.url', '');
38     }
39
40     public function test_errorlog_plain_webserver_channel()
41     {
42         // We can't full test this due to it being targeted for the SAPI logging handler
43         // so we just overwrite that component so we can capture the error log output.
44         config()->set([
45             'logging.channels.errorlog_plain_webserver.handler_with' => [0],
46         ]);
47
48         $temp = tempnam(sys_get_temp_dir(), 'bs-test');
49         $original = ini_set( 'error_log', $temp);
50
51         Log::channel('errorlog_plain_webserver')->info('Aww, look, a cute puppy');
52
53         ini_set( 'error_log', $original);
54
55         $output = file_get_contents($temp);
56         $this->assertStringContainsString('Aww, look, a cute puppy', $output);
57         $this->assertStringNotContainsString('INFO', $output);
58         $this->assertStringNotContainsString('info', $output);
59         $this->assertStringNotContainsString('testing', $output);
60     }
61
62     /**
63      * Set an environment variable of the given name and value
64      * then check the given config key to see if it matches the given result.
65      * Providing a null $envVal clears the variable.
66      * @param string $envName
67      * @param string|null $envVal
68      * @param string $configKey
69      * @param string $expectedResult
70      */
71     protected function checkEnvConfigResult(string $envName, $envVal, string $configKey, string $expectedResult)
72     {
73         $this->runWithEnv($envName, $envVal, function() use ($configKey, $expectedResult) {
74             $this->assertEquals($expectedResult, config($configKey));
75         });
76     }
77
78 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.