1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00

LogicalTheme: Added events for registering web routes

Added to allow easier registration of routes.
Added for normal web and authed routes.
Included testing to cover.
This commit is contained in:
Dan Brown
2023-11-17 13:45:57 +00:00
parent 37a17e858a
commit 22a9cf1e48
4 changed files with 65 additions and 1 deletions

View File

@@ -256,6 +256,40 @@ class ThemeTest extends TestCase
$this->assertEquals($otherPage->id, $args[3]->id);
}
public function test_event_routes_register_web_and_web_auth()
{
$functionsContent = <<<'END'
<?php
use BookStack\Theming\ThemeEvents;
use BookStack\Facades\Theme;
use Illuminate\Routing\Router;
Theme::listen(ThemeEvents::ROUTES_REGISTER_WEB, function (Router $router) {
$router->get('/cat', fn () => 'cat')->name('say.cat');
});
Theme::listen(ThemeEvents::ROUTES_REGISTER_WEB_AUTH, function (Router $router) {
$router->get('/dog', fn () => 'dog')->name('say.dog');
});
END;
$this->usingThemeFolder(function () use ($functionsContent) {
$functionsFile = theme_path('functions.php');
file_put_contents($functionsFile, $functionsContent);
$app = $this->createApplication();
/** @var \Illuminate\Routing\Router $router */
$router = $app->get('router');
/** @var \Illuminate\Routing\Route $catRoute */
$catRoute = $router->getRoutes()->getRoutesByName()['say.cat'];
$this->assertEquals(['web'], $catRoute->middleware());
/** @var \Illuminate\Routing\Route $dogRoute */
$dogRoute = $router->getRoutes()->getRoutesByName()['say.dog'];
$this->assertEquals(['web', 'auth'], $dogRoute->middleware());
});
}
public function test_add_social_driver()
{
Theme::addSocialDriver('catnet', [