+ 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');
+ }
+
+ public function test_add_social_driver_allows_a_configure_for_redirect_callback_to_be_passed()
+ {
+ Theme::addSocialDriver(
+ 'discord',
+ [
+ 'client_id' => 'abc123',
+ 'client_secret' => 'def456',
+ 'name' => 'Super Cat Name',
+ ],
+ 'SocialiteProviders\Discord\DiscordExtendSocialite@handle',
+ function ($driver) {
+ $driver->with(['donkey' => 'donut']);
+ }
+ );
+
+ $loginResp = $this->get('/login/service/discord');
+ $redirect = $loginResp->headers->get('location');
+ $this->assertStringContainsString('donkey=donut', $redirect);
+ }
+
+ public function test_register_command_allows_provided_command_to_be_usable_via_artisan()
+ {
+ Theme::registerCommand(new MyCustomCommand());
+
+ Artisan::call('bookstack:test-custom-command', []);
+ $output = Artisan::output();
+
+ $this->assertStringContainsString('Command ran!', $output);
+ }
+
+ public function test_base_body_start_and_end_template_files_can_be_used()
+ {
+ $bodyStartStr = 'barry-fought-against-the-panther';
+ $bodyEndStr = 'barry-lost-his-fight-with-grace';
+
+ $this->usingThemeFolder(function (string $folder) use ($bodyStartStr, $bodyEndStr) {
+ $viewDir = theme_path('layouts/parts');
+ mkdir($viewDir, 0777, true);
+ file_put_contents($viewDir . '/base-body-start.blade.php', $bodyStartStr);
+ file_put_contents($viewDir . '/base-body-end.blade.php', $bodyEndStr);
+
+ $resp = $this->asEditor()->get('/');
+ $resp->assertSee($bodyStartStr);
+ $resp->assertSee($bodyEndStr);
+ });
+ }
+
+ public function test_export_body_start_and_end_template_files_can_be_used()
+ {
+ $bodyStartStr = 'barry-fought-against-the-panther';
+ $bodyEndStr = 'barry-lost-his-fight-with-grace';
+ /** @var Page $page */
+ $page = Page::query()->first();
+
+ $this->usingThemeFolder(function (string $folder) use ($bodyStartStr, $bodyEndStr, $page) {
+ $viewDir = theme_path('layouts/parts');
+ mkdir($viewDir, 0777, true);
+ file_put_contents($viewDir . '/export-body-start.blade.php', $bodyStartStr);
+ file_put_contents($viewDir . '/export-body-end.blade.php', $bodyEndStr);
+
+ $resp = $this->asEditor()->get($page->getUrl('/export/html'));
+ $resp->assertSee($bodyStartStr);
+ $resp->assertSee($bodyEndStr);
+ });
+ }
+
+ protected function usingThemeFolder(callable $callback)
+ {
+ // Create a folder and configure a theme
+ $themeFolderName = 'testing_theme_' . rtrim(base64_encode(time()), '=');
+ config()->set('view.theme', $themeFolderName);
+ $themeFolderPath = theme_path('');
+ File::makeDirectory($themeFolderPath);
+
+ // Run provided callback with theme env option set
+ $this->runWithEnv('APP_THEME', $themeFolderName, function () use ($callback, $themeFolderName) {
+ call_user_func($callback, $themeFolderName);
+ });
+
+ // Cleanup the custom theme folder we created
+ File::deleteDirectory($themeFolderPath);
+ }
+}
+
+class MyCustomCommand extends Command
+{
+ protected $signature = 'bookstack:test-custom-command';
+
+ public function handle()
+ {
+ $this->line('Command ran!');
+ }
+}