Skip to content

Commit a21ca44

Browse files
committed
Input WYSIWYG: Fixed existing tests, fixed empty description handling
1 parent 7fd6d5b commit a21ca44

File tree

7 files changed

+17
-8
lines changed

7 files changed

+17
-8
lines changed

app/Util/HtmlDescriptionFilter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class HtmlDescriptionFilter
3131

3232
public static function filterFromString(string $html): string
3333
{
34+
if (empty(trim($html))) {
35+
return '';
36+
}
37+
3438
$doc = new HtmlDocument($html);
3539

3640
$topLevel = [...$doc->getBodyChildren()];

database/seeders/DummyContentSeeder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Database\Seeders;
44

55
use BookStack\Api\ApiToken;
6+
use BookStack\Entities\Models\Book;
67
use BookStack\Entities\Models\Bookshelf;
78
use BookStack\Entities\Models\Chapter;
89
use BookStack\Entities\Models\Page;
@@ -38,7 +39,7 @@ public function run()
3839

3940
$byData = ['created_by' => $editorUser->id, 'updated_by' => $editorUser->id, 'owned_by' => $editorUser->id];
4041

41-
\BookStack\Entities\Models\Book::factory()->count(5)->create($byData)
42+
Book::factory()->count(5)->create($byData)
4243
->each(function ($book) use ($byData) {
4344
$chapters = Chapter::factory()->count(3)->create($byData)
4445
->each(function ($chapter) use ($book, $byData) {
@@ -50,7 +51,7 @@ public function run()
5051
$book->pages()->saveMany($pages);
5152
});
5253

53-
$largeBook = \BookStack\Entities\Models\Book::factory()->create(array_merge($byData, ['name' => 'Large book' . Str::random(10)]));
54+
$largeBook = Book::factory()->create(array_merge($byData, ['name' => 'Large book' . Str::random(10)]));
5455
$pages = Page::factory()->count(200)->make($byData);
5556
$chapters = Chapter::factory()->count(50)->make($byData);
5657
$largeBook->pages()->saveMany($pages);

tests/Api/SearchApiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function test_all_endpoint_returns_entity_url()
5252
public function test_all_endpoint_returns_items_with_preview_html()
5353
{
5454
$book = $this->entities->book();
55-
$book->update(['name' => 'name with superuniquevalue within', 'description' => 'Description with superuniquevalue within']);
55+
$book->forceFill(['name' => 'name with superuniquevalue within', 'description' => 'Description with superuniquevalue within'])->save();
5656
$book->indexForSearch();
5757

5858
$resp = $this->actingAsApiAdmin()->getJson($this->baseEndpoint . '?query=superuniquevalue');

tests/Entity/BookTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ public function test_copy()
307307

308308
$resp->assertRedirect($copy->getUrl());
309309
$this->assertEquals($book->getDirectChildren()->count(), $copy->getDirectChildren()->count());
310+
311+
$this->get($copy->getUrl())->assertSee($book->description_html, false);
310312
}
311313

312314
public function test_copy_does_not_copy_non_visible_content()

tests/Entity/ConvertTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function test_convert_chapter_to_book()
4242
$this->assertEquals('Penguins', $newBook->tags->first()->value);
4343
$this->assertEquals($chapter->name, $newBook->name);
4444
$this->assertEquals($chapter->description, $newBook->description);
45+
$this->assertEquals($chapter->description_html, $newBook->description_html);
4546

4647
$this->assertActivityExists(ActivityType::BOOK_CREATE_FROM_CHAPTER, $newBook);
4748
}
@@ -105,6 +106,7 @@ public function test_book_convert_to_shelf()
105106
$this->assertEquals('Ducks', $newShelf->tags->first()->value);
106107
$this->assertEquals($book->name, $newShelf->name);
107108
$this->assertEquals($book->description, $newShelf->description);
109+
$this->assertEquals($book->description_html, $newShelf->description_html);
108110
$this->assertEquals($newShelf->books()->count(), $bookChapterCount + 1);
109111
$this->assertEquals($systemBookCount + $bookChapterCount, Book::query()->count());
110112
$this->assertActivityExists(ActivityType::BOOKSHELF_CREATE_FROM_BOOK, $newShelf);

tests/References/ReferencesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ public function test_references_to_count_visible_on_entity_show_view()
102102

103103
foreach ($entities as $entity) {
104104
$resp = $this->get($entity->getUrl());
105-
$resp->assertSee('Referenced on 1 page');
106-
$resp->assertDontSee('Referenced on 1 pages');
105+
$resp->assertSee('Referenced by 1 item');
106+
$resp->assertDontSee('Referenced by 1 items');
107107
}
108108

109109
$this->createReference($otherPage, $entities['page']);
110110
$resp = $this->get($entities['page']->getUrl());
111-
$resp->assertSee('Referenced on 2 pages');
111+
$resp->assertSee('Referenced by 2 items');
112112
}
113113

114114
public function test_references_to_visible_on_references_page()

tests/Settings/RegenerateReferencesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function test_option_visible_on_maintenance_page()
2121
public function test_action_runs_reference_regen()
2222
{
2323
$this->mock(ReferenceStore::class)
24-
->shouldReceive('updateForAllPages')
24+
->shouldReceive('updateForAll')
2525
->once();
2626

2727
$resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references');
@@ -45,7 +45,7 @@ public function test_settings_manage_permission_required()
4545
public function test_action_failed_shown_as_error_notification()
4646
{
4747
$this->mock(ReferenceStore::class)
48-
->shouldReceive('updateForAllPages')
48+
->shouldReceive('updateForAll')
4949
->andThrow(\Exception::class, 'A badger stopped the task');
5050

5151
$resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references');

0 commit comments

Comments
 (0)