X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/9d37af94537d40b32d9d7416d54fa8fc0e0169e9..refs/pull/2734/head:/tests/ThemeTest.php diff --git a/tests/ThemeTest.php b/tests/ThemeTest.php index 82a4625ac..7a0cd49cb 100644 --- a/tests/ThemeTest.php +++ b/tests/ThemeTest.php @@ -1,5 +1,7 @@ assertStatus(443); } + public function test_event_auth_login_standard() + { + $args = []; + $callback = function (...$eventArgs) use (&$args) { + $args = $eventArgs; + }; + + Theme::listen(ThemeEvents::AUTH_LOGIN, $callback); + $this->post('/login', ['email' => 'admin@admin.com', 'password' => 'password']); + + $this->assertCount(2, $args); + $this->assertEquals('standard', $args[0]); + $this->assertInstanceOf(User::class, $args[1]); + } + + public function test_event_auth_register_standard() + { + $args = []; + $callback = function (...$eventArgs) use (&$args) { + $args = $eventArgs; + }; + Theme::listen(ThemeEvents::AUTH_REGISTER, $callback); + $this->setSettings(['registration-enabled' => 'true']); + + $user = factory(User::class)->make(); + $this->post('/register', ['email' => $user->email, 'name' => $user->name, 'password' => 'password']); + + $this->assertCount(2, $args); + $this->assertEquals('standard', $args[0]); + $this->assertInstanceOf(User::class, $args[1]); + } + + public function test_add_social_driver() + { + Theme::addSocialDriver('catnet', [ + 'client_id' => 'abc123', + 'client_secret' => 'def456' + ], 'SocialiteProviders\Discord\DiscordExtendSocialite@handleTesting'); + + $this->assertEquals('catnet', config('services.catnet.name')); + $this->assertEquals('abc123', config('services.catnet.client_id')); + $this->assertEquals(url('/login/service/catnet/callback'), config('services.catnet.redirect')); + + $loginResp = $this->get('/login'); + $loginResp->assertSee('login/service/catnet'); + } + + public function test_add_social_driver_uses_name_in_config_if_given() + { + Theme::addSocialDriver('catnet', [ + 'client_id' => 'abc123', + 'client_secret' => 'def456', + 'name' => 'Super Cat Name', + ], 'SocialiteProviders\Discord\DiscordExtendSocialite@handleTesting'); + + $this->assertEquals('Super Cat Name', config('services.catnet.name')); + $loginResp = $this->get('/login'); + $loginResp->assertSee('Super Cat Name'); + } + protected function usingThemeFolder(callable $callback) { // Create a folder and configure a theme