Theme: Added testing of registerViewToRender* functions

Updated function name also.
This commit is contained in:
Dan Brown
2026-01-27 00:36:35 +00:00
parent c32b1686a9
commit 9fcfc762ec
3 changed files with 35 additions and 4 deletions

View File

@@ -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
{

View File

@@ -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);
}

View File

@@ -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