Skip to content

Commit 9fcfc76

Browse files
committed
Theme: Added testing of registerViewToRender* functions
Updated function name also.
1 parent c32b168 commit 9fcfc76

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

app/App/helpers.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ function setting(?string $key = null, mixed $default = null): mixed
8181

8282
/**
8383
* Get a path to a theme resource.
84-
* Returns null if a theme is not configured and
85-
* therefore a full path is not available for use.
84+
* Returns null if a theme is not configured, and therefore a full path is not available for use.
8685
*/
8786
function theme_path(string $path = ''): ?string
8887
{

app/Theming/ThemeService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ public function handleViewInclude(string $viewPath, array $data = []): string
143143
/**
144144
* Register a custom view to be rendered before the given target view is included in the template system.
145145
*/
146-
public function registerViewRenderBefore(string $targetView, string $localView, int $priority = 50): void
146+
public function registerViewToRenderBefore(string $targetView, string $localView, int $priority = 50): void
147147
{
148148
$this->registerAdjacentView($this->beforeViews, $targetView, $localView, $priority);
149149
}
150150

151151
/**
152152
* Register a custom view to be rendered after the given target view is included in the template system.
153153
*/
154-
public function registerViewRenderAfter(string $targetView, string $localView, int $priority = 50): void
154+
public function registerViewToRenderAfter(string $targetView, string $localView, int $priority = 50): void
155155
{
156156
$this->registerAdjacentView($this->afterViews, $targetView, $localView, $priority);
157157
}

tests/ThemeTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,38 @@ public function test_public_folder_contents_accessible_via_route()
492492
});
493493
}
494494

495+
public function test_register_view_to_render_before_and_after()
496+
{
497+
$this->usingThemeFolder(function (string $folder) {
498+
$before = 'this-is-my-before-header-string';
499+
$afterA = 'this-is-my-after-header-string-a';
500+
$afterB = 'this-is-my-after-header-string-b';
501+
$afterC = 'this-is-my-after-header-string-{{ 1+51 }}';
502+
503+
$functionsContent = <<<'CONTENT'
504+
<?php use BookStack\Facades\Theme;
505+
Theme::registerViewToRenderBefore('layouts.parts.header', 'before', 4);
506+
Theme::registerViewToRenderAfter('layouts.parts.header', 'after-a', 4);
507+
Theme::registerViewToRenderAfter('layouts.parts.header', 'after-b', 1);
508+
Theme::registerViewToRenderAfter('layouts.parts.header', 'after-c', 12);
509+
CONTENT;
510+
511+
$viewDir = theme_path();
512+
file_put_contents($viewDir . '/functions.php', $functionsContent);
513+
file_put_contents($viewDir . '/before.blade.php', $before);
514+
file_put_contents($viewDir . '/after-a.blade.php', $afterA);
515+
file_put_contents($viewDir . '/after-b.blade.php', $afterB);
516+
file_put_contents($viewDir . '/after-c.blade.php', $afterC);
517+
518+
$this->refreshApplication();
519+
520+
$resp = $this->get('/login');
521+
$resp->assertSee($before);
522+
// Ensure ordering of the multiple after views
523+
$resp->assertSee($afterB . "\n" . $afterA . "\nthis-is-my-after-header-string-52");
524+
});
525+
}
526+
495527
protected function usingThemeFolder(callable $callback)
496528
{
497529
// Create a folder and configure a theme

0 commit comments

Comments
 (0)