Input WYSIWYG: Fixed existing tests, fixed empty description handling

This commit is contained in:
Dan Brown 2023-12-20 17:21:09 +00:00
parent 7fd6d5b2cc
commit a21ca44633
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
7 changed files with 17 additions and 8 deletions

View file

@ -31,6 +31,10 @@ class HtmlDescriptionFilter
public static function filterFromString(string $html): string public static function filterFromString(string $html): string
{ {
if (empty(trim($html))) {
return '';
}
$doc = new HtmlDocument($html); $doc = new HtmlDocument($html);
$topLevel = [...$doc->getBodyChildren()]; $topLevel = [...$doc->getBodyChildren()];

View file

@ -3,6 +3,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use BookStack\Api\ApiToken; use BookStack\Api\ApiToken;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf; use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page; 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]; $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) { ->each(function ($book) use ($byData) {
$chapters = Chapter::factory()->count(3)->create($byData) $chapters = Chapter::factory()->count(3)->create($byData)
->each(function ($chapter) use ($book, $byData) { ->each(function ($chapter) use ($book, $byData) {
@ -50,7 +51,7 @@ class DummyContentSeeder extends Seeder
$book->pages()->saveMany($pages); $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); $pages = Page::factory()->count(200)->make($byData);
$chapters = Chapter::factory()->count(50)->make($byData); $chapters = Chapter::factory()->count(50)->make($byData);
$largeBook->pages()->saveMany($pages); $largeBook->pages()->saveMany($pages);

View file

@ -52,7 +52,7 @@ class SearchApiTest extends TestCase
public function test_all_endpoint_returns_items_with_preview_html() public function test_all_endpoint_returns_items_with_preview_html()
{ {
$book = $this->entities->book(); $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(); $book->indexForSearch();
$resp = $this->actingAsApiAdmin()->getJson($this->baseEndpoint . '?query=superuniquevalue'); $resp = $this->actingAsApiAdmin()->getJson($this->baseEndpoint . '?query=superuniquevalue');

View file

@ -307,6 +307,8 @@ class BookTest extends TestCase
$resp->assertRedirect($copy->getUrl()); $resp->assertRedirect($copy->getUrl());
$this->assertEquals($book->getDirectChildren()->count(), $copy->getDirectChildren()->count()); $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() public function test_copy_does_not_copy_non_visible_content()

View file

@ -42,6 +42,7 @@ class ConvertTest extends TestCase
$this->assertEquals('Penguins', $newBook->tags->first()->value); $this->assertEquals('Penguins', $newBook->tags->first()->value);
$this->assertEquals($chapter->name, $newBook->name); $this->assertEquals($chapter->name, $newBook->name);
$this->assertEquals($chapter->description, $newBook->description); $this->assertEquals($chapter->description, $newBook->description);
$this->assertEquals($chapter->description_html, $newBook->description_html);
$this->assertActivityExists(ActivityType::BOOK_CREATE_FROM_CHAPTER, $newBook); $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('Ducks', $newShelf->tags->first()->value);
$this->assertEquals($book->name, $newShelf->name); $this->assertEquals($book->name, $newShelf->name);
$this->assertEquals($book->description, $newShelf->description); $this->assertEquals($book->description, $newShelf->description);
$this->assertEquals($book->description_html, $newShelf->description_html);
$this->assertEquals($newShelf->books()->count(), $bookChapterCount + 1); $this->assertEquals($newShelf->books()->count(), $bookChapterCount + 1);
$this->assertEquals($systemBookCount + $bookChapterCount, Book::query()->count()); $this->assertEquals($systemBookCount + $bookChapterCount, Book::query()->count());
$this->assertActivityExists(ActivityType::BOOKSHELF_CREATE_FROM_BOOK, $newShelf); $this->assertActivityExists(ActivityType::BOOKSHELF_CREATE_FROM_BOOK, $newShelf);

View file

@ -102,13 +102,13 @@ class ReferencesTest extends TestCase
foreach ($entities as $entity) { foreach ($entities as $entity) {
$resp = $this->get($entity->getUrl()); $resp = $this->get($entity->getUrl());
$resp->assertSee('Referenced on 1 page'); $resp->assertSee('Referenced by 1 item');
$resp->assertDontSee('Referenced on 1 pages'); $resp->assertDontSee('Referenced by 1 items');
} }
$this->createReference($otherPage, $entities['page']); $this->createReference($otherPage, $entities['page']);
$resp = $this->get($entities['page']->getUrl()); $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() public function test_references_to_visible_on_references_page()

View file

@ -21,7 +21,7 @@ class RegenerateReferencesTest extends TestCase
public function test_action_runs_reference_regen() public function test_action_runs_reference_regen()
{ {
$this->mock(ReferenceStore::class) $this->mock(ReferenceStore::class)
->shouldReceive('updateForAllPages') ->shouldReceive('updateForAll')
->once(); ->once();
$resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references'); $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() public function test_action_failed_shown_as_error_notification()
{ {
$this->mock(ReferenceStore::class) $this->mock(ReferenceStore::class)
->shouldReceive('updateForAllPages') ->shouldReceive('updateForAll')
->andThrow(\Exception::class, 'A badger stopped the task'); ->andThrow(\Exception::class, 'A badger stopped the task');
$resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references'); $resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references');