1 <?php namespace Tests\Unit;
3 use Illuminate\Support\Facades\Log;
8 * Many of the tests here are to check on tweaks made
9 * to maintain backwards compatibility.
13 class ConfigTest extends TestCase
16 public function test_filesystem_images_falls_back_to_storage_type_var()
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');
24 public function test_filesystem_attachments_falls_back_to_storage_type_var()
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');
32 public function test_app_url_blank_if_old_default_value()
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', '');
40 public function test_errorlog_plain_webserver_channel()
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.
45 'logging.channels.errorlog_plain_webserver.handler_with' => [0],
48 $temp = tempnam(sys_get_temp_dir(), 'bs-test');
49 $original = ini_set( 'error_log', $temp);
51 Log::channel('errorlog_plain_webserver')->info('Aww, look, a cute puppy');
53 ini_set( 'error_log', $original);
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);
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
71 protected function checkEnvConfigResult(string $envName, $envVal, string $configKey, string $expectedResult)
73 $this->runWithEnv($envName, $envVal, function() use ($configKey, $expectedResult) {
74 $this->assertEquals($expectedResult, config($configKey));