diff --git a/module/VuFind/src/VuFind/Bootstrapper.php b/module/VuFind/src/VuFind/Bootstrapper.php index 963788aa4f9..cd8d69495e6 100644 --- a/module/VuFind/src/VuFind/Bootstrapper.php +++ b/module/VuFind/src/VuFind/Bootstrapper.php @@ -241,12 +241,20 @@ protected function initUserLanguage(): void */ protected function initTheme(): void { - // Attach remaining theme configuration to the dispatch event at high - // priority (TODO: use priority constant once defined by framework): - $config = $this->config->Site; - $callback = function ($event) use ($config) { - $theme = new \VuFindTheme\Initializer($config, $event); - $theme->init(); + // Attach remaining theme configuration to the dispatch event at high priority: + $siteConfig = $this->config->Site; + $callback = function ($event) use ($siteConfig) { + $theme = new \VuFindTheme\Initializer($siteConfig, $event); + try { + $theme->init(); + } catch (\Exception $e) { + // Try to display an error page if the theme fails to initialize: + $appConfig = $this->container->get('config'); + $model = $event->getViewModel(); + $model->setTemplate('error/index'); + $model->display_exceptions = $appConfig['view_manager']['display_exceptions'] ?? false; + $model->exception = $e; + } }; $this->events->attach('dispatch.error', $callback, 9000); $this->events->attach('dispatch', $callback, 9000); diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BasicTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BasicTest.php index 3059776f50c..e81b8a3ac49 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BasicTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BasicTest.php @@ -48,7 +48,7 @@ class BasicTest extends \VuFindTest\Integration\MinkTestCase public function testHomePage(): void { $page = $this->getSearchHomePage(); - $this->assertTrue(false !== strstr($page->getContent(), 'VuFind')); + $this->assertStringContainsString('VuFind', $page->getContent()); } /** @@ -142,6 +142,31 @@ public function testThemeSwitcher(): void ); } + /** + * Test graceful handling of an invalid theme. + * + * Note that HTML validation is disabled on this test because an improperly initialized + * theme will not generate a fully-formed page; but we still want to confirm that it + * at least outputs a human-readable error message. + * + * @return void + */ + #[\VuFindTest\Attribute\HtmlValidation(false)] + public function testBadThemeConfig(): void + { + $this->changeConfigs( + [ + 'config' => [ + 'Site' => [ + 'theme' => 'not-a-valid-theme', + ], + ], + ] + ); + $page = $this->getSearchHomePage(); + $this->assertStringContainsString('An error has occurred', $page->getContent()); + } + /** * Test lightbox jump links * diff --git a/module/VuFindTheme/src/VuFindTheme/ThemeInfoFactory.php b/module/VuFindTheme/src/VuFindTheme/ThemeInfoFactory.php index cfa87fced17..2b601311a47 100644 --- a/module/VuFindTheme/src/VuFindTheme/ThemeInfoFactory.php +++ b/module/VuFindTheme/src/VuFindTheme/ThemeInfoFactory.php @@ -71,7 +71,7 @@ public function __invoke( $themeInfo = new $requestedName( realpath(APPLICATION_PATH . '/themes'), - 'bootprint3' + 'sandal5' ); // As of release 1.1.0, the memory storage adapter has a flaw which can cause