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+ putenv ('STORAGE_TYPE=local_secure ' );
16+
17+ $ this ->checkEnvConfigResult ('STORAGE_IMAGE_TYPE ' , 's3 ' , 'filesystems.images ' , 's3 ' );
18+ $ this ->checkEnvConfigResult ('STORAGE_IMAGE_TYPE ' , null , 'filesystems.images ' , 'local_secure ' );
19+ }
20+
21+ public function test_filesystem_attachments_falls_back_to_storage_type_var ()
22+ {
23+ putenv ('STORAGE_TYPE=local_secure ' );
24+
25+ $ this ->checkEnvConfigResult ('STORAGE_ATTACHMENT_TYPE ' , 's3 ' , 'filesystems.attachments ' , 's3 ' );
26+ $ this ->checkEnvConfigResult ('STORAGE_ATTACHMENT_TYPE ' , null , 'filesystems.attachments ' , 'local_secure ' );
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+ $ envString = $ envName . (is_null ($ envVal ) ? '' : '= ' ) . ($ envVal ?? '' );
49+ putenv ($ envString );
50+ $ this ->refreshApplication ();
51+ $ this ->assertEquals ($ expectedResult , config ($ configKey ));
52+ }
53+
54+ }
0 commit comments