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);
62 public function test_session_cookie_uses_sub_path_from_app_url()
64 $this->checkEnvConfigResult('APP_URL', 'https://example.com', 'session.path', '/');
65 $this->checkEnvConfigResult('APP_URL', 'https://a.com/b', 'session.path', '/b');
66 $this->checkEnvConfigResult('APP_URL', 'https://a.com/b/d/e', 'session.path', '/b/d/e');
67 $this->checkEnvConfigResult('APP_URL', '', 'session.path', '/');
71 * Set an environment variable of the given name and value
72 * then check the given config key to see if it matches the given result.
73 * Providing a null $envVal clears the variable.
75 protected function checkEnvConfigResult(string $envName, ?string $envVal, string $configKey, string $expectedResult)
77 $this->runWithEnv($envName, $envVal, function() use ($configKey, $expectedResult) {
78 $this->assertEquals($expectedResult, config($configKey));