NOW MANAGED ON CODEBERG
Theme: Added testing of registerViewToRender* functions
Dan Brown9fcfc762ec9b
diff --git a/app/App/helpers.php b/app/App/helpers.phpindex 0e357e36a..8f210ecaf 100644--- a/app/App/helpers.php+++ b/app/App/helpers.php@@ -81,8 +81,7 @@ function setting(?string $key = null, mixed $default = null): mixed/*** Get a path to a theme resource.- * Returns null if a theme is not configured and- * therefore a full path is not available for use.+ * Returns null if a theme is not configured, and therefore a full path is not available for use.*/function theme_path(string $path = ''): ?string{diff --git a/app/Theming/ThemeService.php b/app/Theming/ThemeService.phpindex 9587ceccb..0a6327af8 100644--- a/app/Theming/ThemeService.php+++ b/app/Theming/ThemeService.php@@ -143,7 +143,7 @@ class ThemeService/*** Register a custom view to be rendered before the given target view is included in the template system.*/- public function registerViewRenderBefore(string $targetView, string $localView, int $priority = 50): void+ public function registerViewToRenderBefore(string $targetView, string $localView, int $priority = 50): void{$this->registerAdjacentView($this->beforeViews, $targetView, $localView, $priority);}@@ -151,7 +151,7 @@ class ThemeService/*** Register a custom view to be rendered after the given target view is included in the template system.*/- public function registerViewRenderAfter(string $targetView, string $localView, int $priority = 50): void+ public function registerViewToRenderAfter(string $targetView, string $localView, int $priority = 50): void{$this->registerAdjacentView($this->afterViews, $targetView, $localView, $priority);}diff --git a/tests/ThemeTest.php b/tests/ThemeTest.phpindex 841ff78ca..014f3a92f 100644--- a/tests/ThemeTest.php+++ b/tests/ThemeTest.php@@ -492,6 +492,38 @@ END;});}+ public function test_register_view_to_render_before_and_after()+ {+ $this->usingThemeFolder(function (string $folder) {+ $before = 'this-is-my-before-header-string';+ $afterA = 'this-is-my-after-header-string-a';+ $afterB = 'this-is-my-after-header-string-b';+ $afterC = 'this-is-my-after-header-string-{{ 1+51 }}';++ $functionsContent = <<<'CONTENT'+<?php use BookStack\Facades\Theme;+Theme::registerViewToRenderBefore('layouts.parts.header', 'before', 4);+Theme::registerViewToRenderAfter('layouts.parts.header', 'after-a', 4);+Theme::registerViewToRenderAfter('layouts.parts.header', 'after-b', 1);+Theme::registerViewToRenderAfter('layouts.parts.header', 'after-c', 12);+CONTENT;++ $viewDir = theme_path();+ file_put_contents($viewDir . '/functions.php', $functionsContent);+ file_put_contents($viewDir . '/before.blade.php', $before);+ file_put_contents($viewDir . '/after-a.blade.php', $afterA);+ file_put_contents($viewDir . '/after-b.blade.php', $afterB);+ file_put_contents($viewDir . '/after-c.blade.php', $afterC);++ $this->refreshApplication();++ $resp = $this->get('/login');+ $resp->assertSee($before);+ // Ensure ordering of the multiple after views+ $resp->assertSee($afterB . "\n" . $afterA . "\nthis-is-my-after-header-string-52");+ });+ }+protected function usingThemeFolder(callable $callback){// Create a folder and configure a theme