]> BookStack Code Mirror - bookstack/blobdiff - tests/ThemeTest.php
Added 'Sort Book' action to chapters
[bookstack] / tests / ThemeTest.php
index 551f8350f33976b6edb61520522a85d2c8d0816a..12a25a6d425131b2d52d21408d283721bafc244d 100644 (file)
@@ -6,6 +6,7 @@ use BookStack\Actions\ActivityType;
 use BookStack\Actions\DispatchWebhookJob;
 use BookStack\Actions\Webhook;
 use BookStack\Auth\User;
+use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Page;
 use BookStack\Entities\Tools\PageContent;
 use BookStack\Facades\Theme;
@@ -17,7 +18,6 @@ use Illuminate\Http\Response;
 use Illuminate\Support\Facades\Artisan;
 use Illuminate\Support\Facades\File;
 use Illuminate\Support\Facades\Http;
-use Illuminate\Support\Str;
 use League\CommonMark\ConfigurableEnvironmentInterface;
 
 class ThemeTest extends TestCase
@@ -37,7 +37,7 @@ class ThemeTest extends TestCase
             file_put_contents($translationPath . '/entities.php', $customTranslations);
 
             $homeRequest = $this->actingAs($this->getViewer())->get('/');
-            $homeRequest->assertElementContains('header nav', 'Sandwiches');
+            $this->withHtml($homeRequest)->assertElementContains('header nav', 'Sandwiches');
         });
     }
 
@@ -197,6 +197,23 @@ class ThemeTest extends TestCase
         });
     }
 
+    public function test_event_activity_logged()
+    {
+        $book = Book::query()->first();
+        $args = [];
+        $callback = function (...$eventArgs) use (&$args) {
+            $args = $eventArgs;
+        };
+
+        Theme::listen(ThemeEvents::ACTIVITY_LOGGED, $callback);
+        $this->asEditor()->put($book->getUrl(), ['name' => 'My cool update book!']);
+
+        $this->assertCount(2, $args);
+        $this->assertEquals(ActivityType::BOOK_UPDATE, $args[0]);
+        $this->assertTrue($args[1] instanceof Book);
+        $this->assertEquals($book->id, $args[1]->id);
+    }
+
     public function test_add_social_driver()
     {
         Theme::addSocialDriver('catnet', [
@@ -260,7 +277,7 @@ class ThemeTest extends TestCase
         $bodyStartStr = 'barry-fought-against-the-panther';
         $bodyEndStr = 'barry-lost-his-fight-with-grace';
 
-        $this->usingThemeFolder(function(string $folder) use ($bodyStartStr, $bodyEndStr) {
+        $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);
@@ -281,7 +298,7 @@ class ThemeTest extends TestCase
         File::makeDirectory($themeFolderPath);
 
         // Run provided callback with theme env option set
-        $this->runWithEnv('APP_THEME', $themeFolderName, function() use ($callback, $themeFolderName) {
+        $this->runWithEnv('APP_THEME', $themeFolderName, function () use ($callback, $themeFolderName) {
             call_user_func($callback, $themeFolderName);
         });