mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-01-03 23:42:28 +03:00
Theme: Added handling for functions.php file load error
This adds specific handling for functions.php error loading to re-throw errors wrapped in a more descriptive message, to make it clear the error is due to an issue in their functions.php file. Decided to throw and stop, rather than ignore & continue, to be on the safe side in the event auth-level (or other security level) customizations have been made via functions.php. Adds test to cover. Closes #4504
This commit is contained in:
@@ -8,6 +8,7 @@ use BookStack\Activity\Models\Webhook;
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Models\Page;
|
||||
use BookStack\Entities\Tools\PageContent;
|
||||
use BookStack\Exceptions\ThemeException;
|
||||
use BookStack\Facades\Theme;
|
||||
use BookStack\Theming\ThemeEvents;
|
||||
use BookStack\Users\Models\User;
|
||||
@@ -51,6 +52,19 @@ class ThemeTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
public function test_theme_functions_loads_errors_are_caught_and_logged()
|
||||
{
|
||||
$this->usingThemeFolder(function ($themeFolder) {
|
||||
$functionsFile = theme_path('functions.php');
|
||||
file_put_contents($functionsFile, "<?php\n\\BookStack\\Biscuits::eat();");
|
||||
|
||||
$this->expectException(ThemeException::class);
|
||||
$this->expectExceptionMessageMatches('/Failed loading theme functions file at ".*?" with error: Class "BookStack\\\\Biscuits" not found/');
|
||||
|
||||
$this->runWithEnv('APP_THEME', $themeFolder, fn() => null);
|
||||
});
|
||||
}
|
||||
|
||||
public function test_event_commonmark_environment_configure()
|
||||
{
|
||||
$callbackCalled = false;
|
||||
|
||||
Reference in New Issue
Block a user