]> BookStack Code Mirror - bookstack/blobdiff - tests/ThemeTest.php
Fixed comment count update error
[bookstack] / tests / ThemeTest.php
index fe816255997b638d0233c6c175ba642734083e6a..85b8b9d364135e564f29415755d9518b52eee51c 100644 (file)
@@ -170,6 +170,7 @@ class ThemeTest extends TestCase
         $args = [];
         $callback = function (...$eventArgs) use (&$args) {
             $args = $eventArgs;
+
             return ['test' => 'hello!'];
         };
         Theme::listen(ThemeEvents::WEBHOOK_CALL_BEFORE, $callback);
@@ -185,7 +186,7 @@ class ThemeTest extends TestCase
 
         dispatch((new DispatchWebhookJob($webhook, $event, $detail)));
 
-        $this->assertCount(3, $args);
+        $this->assertCount(5, $args);
         $this->assertEquals($event, $args[0]);
         $this->assertEquals($webhook->id, $args[1]->id);
         $this->assertEquals($detail->id, $args[2]->id);
@@ -253,6 +254,23 @@ class ThemeTest extends TestCase
         $this->assertStringContainsString('Command ran!', $output);
     }
 
+    public function test_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);
+        });
+    }
+
     protected function usingThemeFolder(callable $callback)
     {
         // Create a folder and configure a theme
@@ -261,7 +279,10 @@ class ThemeTest extends TestCase
         $themeFolderPath = theme_path('');
         File::makeDirectory($themeFolderPath);
 
-        call_user_func($callback, $themeFolderName);
+        // 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);