]> BookStack Code Mirror - bookstack/commitdiff
Input WYSIWYG: Fixed existing tests, fixed empty description handling
authorDan Brown <redacted>
Wed, 20 Dec 2023 17:21:09 +0000 (17:21 +0000)
committerDan Brown <redacted>
Wed, 20 Dec 2023 17:21:09 +0000 (17:21 +0000)
app/Util/HtmlDescriptionFilter.php
database/seeders/DummyContentSeeder.php
tests/Api/SearchApiTest.php
tests/Entity/BookTest.php
tests/Entity/ConvertTest.php
tests/References/ReferencesTest.php
tests/Settings/RegenerateReferencesTest.php

index 4494a73ce8d41e69eeca3d08e5190be43f0a2f09..7287586d16fadff29740760599051630edf5e927 100644 (file)
@@ -31,6 +31,10 @@ class HtmlDescriptionFilter
 
     public static function filterFromString(string $html): string
     {
+        if (empty(trim($html))) {
+            return '';
+        }
+
         $doc = new HtmlDocument($html);
 
         $topLevel = [...$doc->getBodyChildren()];
index 47e8d1d7c1d32e4ed1c14b86601edfa7df736a77..a4383be50a253b1ecf586c4f3b531398de2304b8 100644 (file)
@@ -3,6 +3,7 @@
 namespace Database\Seeders;
 
 use BookStack\Api\ApiToken;
+use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Bookshelf;
 use BookStack\Entities\Models\Chapter;
 use BookStack\Entities\Models\Page;
@@ -38,7 +39,7 @@ class DummyContentSeeder extends Seeder
 
         $byData = ['created_by' => $editorUser->id, 'updated_by' => $editorUser->id, 'owned_by' => $editorUser->id];
 
-        \BookStack\Entities\Models\Book::factory()->count(5)->create($byData)
+        Book::factory()->count(5)->create($byData)
             ->each(function ($book) use ($byData) {
                 $chapters = Chapter::factory()->count(3)->create($byData)
                     ->each(function ($chapter) use ($book, $byData) {
@@ -50,7 +51,7 @@ class DummyContentSeeder extends Seeder
                 $book->pages()->saveMany($pages);
             });
 
-        $largeBook = \BookStack\Entities\Models\Book::factory()->create(array_merge($byData, ['name' => 'Large book' . Str::random(10)]));
+        $largeBook = Book::factory()->create(array_merge($byData, ['name' => 'Large book' . Str::random(10)]));
         $pages = Page::factory()->count(200)->make($byData);
         $chapters = Chapter::factory()->count(50)->make($byData);
         $largeBook->pages()->saveMany($pages);
index cdc954ec3259e7d7827d22e905589c140b33c997..2a186e8d6328c4133b86eeb643d1436f40d5b78b 100644 (file)
@@ -52,7 +52,7 @@ class SearchApiTest extends TestCase
     public function test_all_endpoint_returns_items_with_preview_html()
     {
         $book = $this->entities->book();
-        $book->update(['name' => 'name with superuniquevalue within', 'description' => 'Description with superuniquevalue within']);
+        $book->forceFill(['name' => 'name with superuniquevalue within', 'description' => 'Description with superuniquevalue within'])->save();
         $book->indexForSearch();
 
         $resp = $this->actingAsApiAdmin()->getJson($this->baseEndpoint . '?query=superuniquevalue');
index 3e37e61f7d7b394659ab93c14e2ed1451debcd54..c4872785b88fc2be9df3b623368262090a296630 100644 (file)
@@ -307,6 +307,8 @@ class BookTest extends TestCase
 
         $resp->assertRedirect($copy->getUrl());
         $this->assertEquals($book->getDirectChildren()->count(), $copy->getDirectChildren()->count());
+
+        $this->get($copy->getUrl())->assertSee($book->description_html, false);
     }
 
     public function test_copy_does_not_copy_non_visible_content()
index decda52243f7d39d4169a5b0d4fb2a13e08dc726..d9b1ee466cf1db9656cfd922d7bbdefa585c613d 100644 (file)
@@ -42,6 +42,7 @@ class ConvertTest extends TestCase
         $this->assertEquals('Penguins', $newBook->tags->first()->value);
         $this->assertEquals($chapter->name, $newBook->name);
         $this->assertEquals($chapter->description, $newBook->description);
+        $this->assertEquals($chapter->description_html, $newBook->description_html);
 
         $this->assertActivityExists(ActivityType::BOOK_CREATE_FROM_CHAPTER, $newBook);
     }
@@ -105,6 +106,7 @@ class ConvertTest extends TestCase
         $this->assertEquals('Ducks', $newShelf->tags->first()->value);
         $this->assertEquals($book->name, $newShelf->name);
         $this->assertEquals($book->description, $newShelf->description);
+        $this->assertEquals($book->description_html, $newShelf->description_html);
         $this->assertEquals($newShelf->books()->count(), $bookChapterCount + 1);
         $this->assertEquals($systemBookCount + $bookChapterCount, Book::query()->count());
         $this->assertActivityExists(ActivityType::BOOKSHELF_CREATE_FROM_BOOK, $newShelf);
index bc691b0cd56adcde5684a33fe012770de31e6bde..715f7143534b09ddcf179bd2517c5a11c6461462 100644 (file)
@@ -102,13 +102,13 @@ class ReferencesTest extends TestCase
 
         foreach ($entities as $entity) {
             $resp = $this->get($entity->getUrl());
-            $resp->assertSee('Referenced on 1 page');
-            $resp->assertDontSee('Referenced on 1 pages');
+            $resp->assertSee('Referenced by 1 item');
+            $resp->assertDontSee('Referenced by 1 items');
         }
 
         $this->createReference($otherPage, $entities['page']);
         $resp = $this->get($entities['page']->getUrl());
-        $resp->assertSee('Referenced on 2 pages');
+        $resp->assertSee('Referenced by 2 items');
     }
 
     public function test_references_to_visible_on_references_page()
index 25832b03e58837f8d813ff4e7ff261eef348d3ef..0511f2624cfdc53b52c82e2a6b16591cb2eaf22e 100644 (file)
@@ -21,7 +21,7 @@ class RegenerateReferencesTest extends TestCase
     public function test_action_runs_reference_regen()
     {
         $this->mock(ReferenceStore::class)
-            ->shouldReceive('updateForAllPages')
+            ->shouldReceive('updateForAll')
             ->once();
 
         $resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references');
@@ -45,7 +45,7 @@ class RegenerateReferencesTest extends TestCase
     public function test_action_failed_shown_as_error_notification()
     {
         $this->mock(ReferenceStore::class)
-            ->shouldReceive('updateForAllPages')
+            ->shouldReceive('updateForAll')
             ->andThrow(\Exception::class, 'A badger stopped the task');
 
         $resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references');