X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/d1f28ed245ae674a610ea6d5094ab3ea5d30b0cc..refs/pull/5280/head:/tests/ThemeTest.php diff --git a/tests/ThemeTest.php b/tests/ThemeTest.php index 53361e351..837b94eee 100644 --- a/tests/ThemeTest.php +++ b/tests/ThemeTest.php @@ -78,7 +78,7 @@ class ThemeTest extends TestCase $page = $this->entities->page(); $content = new PageContent($page); - $content->setNewMarkdown('# test'); + $content->setNewMarkdown('# test', $this->users->editor()); $this->assertTrue($callbackCalled); } @@ -178,6 +178,43 @@ class ThemeTest extends TestCase $this->assertInstanceOf(User::class, $args[1]); } + public function test_event_auth_pre_register() + { + $args = []; + $callback = function (...$eventArgs) use (&$args) { + $args = $eventArgs; + }; + Theme::listen(ThemeEvents::AUTH_PRE_REGISTER, $callback); + $this->setSettings(['registration-enabled' => 'true']); + + $user = User::factory()->make(); + $this->post('/register', ['email' => $user->email, 'name' => $user->name, 'password' => 'password']); + + $this->assertCount(2, $args); + $this->assertEquals('standard', $args[0]); + $this->assertEquals([ + 'email' => $user->email, + 'name' => $user->name, + 'password' => 'password', + ], $args[1]); + $this->assertDatabaseHas('users', ['email' => $user->email]); + } + + public function test_event_auth_pre_register_with_false_return_blocks_registration() + { + $callback = function () { + return false; + }; + Theme::listen(ThemeEvents::AUTH_PRE_REGISTER, $callback); + $this->setSettings(['registration-enabled' => 'true']); + + $user = User::factory()->make(); + $resp = $this->post('/register', ['email' => $user->email, 'name' => $user->name, 'password' => 'password']); + $resp->assertRedirect('/login'); + $this->assertSessionError('User account could not be registered for the provided details'); + $this->assertDatabaseMissing('users', ['email' => $user->email]); + } + public function test_event_webhook_call_before() { $args = []; @@ -256,6 +293,40 @@ class ThemeTest extends TestCase $this->assertEquals($otherPage->id, $args[3]->id); } + public function test_event_routes_register_web_and_web_auth() + { + $functionsContent = <<<'END' +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', [ @@ -380,6 +451,19 @@ class ThemeTest extends TestCase }); } + public function test_custom_settings_category_page_can_be_added_via_view_file() + { + $content = 'My SuperCustomSettings'; + + $this->usingThemeFolder(function (string $folder) use ($content) { + $viewDir = theme_path('settings/categories'); + mkdir($viewDir, 0777, true); + file_put_contents($viewDir . '/beans.blade.php', $content); + + $this->asAdmin()->get('/settings/beans')->assertSee($content); + }); + } + protected function usingThemeFolder(callable $callback) { // Create a folder and configure a theme