X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/22a9cf1e482d493d4080357be58ef7649cce8fb1..refs/pull/5280/head:/tests/ThemeTest.php diff --git a/tests/ThemeTest.php b/tests/ThemeTest.php index 73b901439..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 = []; @@ -414,6 +451,19 @@ END; }); } + 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