ZIP Exports: Prevent book child page drafts from being included
Some checks are pending
analyse-php / build (push) Waiting to run
lint-php / build (push) Waiting to run
test-migrations / build (8.1) (push) Waiting to run
test-migrations / build (8.2) (push) Waiting to run
test-migrations / build (8.3) (push) Waiting to run
test-migrations / build (8.4) (push) Waiting to run
test-php / build (8.1) (push) Waiting to run
test-php / build (8.2) (push) Waiting to run
test-php / build (8.3) (push) Waiting to run
test-php / build (8.4) (push) Waiting to run

Added test to cover
This commit is contained in:
Dan Brown 2024-12-22 12:43:26 +00:00
parent 01825ddb93
commit c84d999456
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 31 additions and 2 deletions

View File

@ -70,7 +70,7 @@ class ZipExportBook extends ZipExportModel
foreach ($children as $child) {
if ($child instanceof Chapter) {
$chapters[] = $child;
} else if ($child instanceof Page) {
} else if ($child instanceof Page && !$child->draft) {
$pages[] = $child;
}
}

View File

@ -198,7 +198,7 @@ class ZipExportTest extends TestCase
public function test_book_export()
{
$book = $this->entities->book();
$book = $this->entities->bookHasChaptersAndPages();
$book->tags()->saveMany(Tag::factory()->count(2)->make());
$zipResp = $this->asEditor()->get($book->getUrl("/export/zip"));
@ -251,6 +251,35 @@ class ZipExportTest extends TestCase
$this->assertCount($chapter->pages()->count(), $chapterData['pages']);
}
public function test_draft_pages_are_not_included()
{
$editor = $this->users->editor();
$entities = $this->entities->createChainBelongingToUser($editor);
$book = $entities['book'];
$page = $entities['page'];
$chapter = $entities['chapter'];
$book->tags()->saveMany(Tag::factory()->count(2)->make());
$page->created_by = $editor->id;
$page->draft = true;
$page->save();
$zipResp = $this->actingAs($editor)->get($book->getUrl("/export/zip"));
$zip = $this->extractZipResponse($zipResp);
$this->assertCount(0, $zip->data['book']['chapters'][0]['pages'] ?? ['cat']);
$zipResp = $this->actingAs($editor)->get($chapter->getUrl("/export/zip"));
$zip = $this->extractZipResponse($zipResp);
$this->assertCount(0, $zip->data['chapter']['pages'] ?? ['cat']);
$page->chapter_id = 0;
$page->save();
$zipResp = $this->actingAs($editor)->get($book->getUrl("/export/zip"));
$zip = $this->extractZipResponse($zipResp);
$this->assertCount(0, $zip->data['book']['pages'] ?? ['cat']);
}
public function test_cross_reference_links_are_converted()
{