Skip to content

Commit c84d999

Browse files
committed
ZIP Exports: Prevent book child page drafts from being included
Added test to cover
1 parent 01825dd commit c84d999

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

app/Exports/ZipExports/Models/ZipExportBook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static function fromModel(Book $model, ZipExportFiles $files): self
7070
foreach ($children as $child) {
7171
if ($child instanceof Chapter) {
7272
$chapters[] = $child;
73-
} else if ($child instanceof Page) {
73+
} else if ($child instanceof Page && !$child->draft) {
7474
$pages[] = $child;
7575
}
7676
}

tests/Exports/ZipExportTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function test_page_export_link_attachments()
198198

199199
public function test_book_export()
200200
{
201-
$book = $this->entities->book();
201+
$book = $this->entities->bookHasChaptersAndPages();
202202
$book->tags()->saveMany(Tag::factory()->count(2)->make());
203203

204204
$zipResp = $this->asEditor()->get($book->getUrl("/export/zip"));
@@ -251,6 +251,35 @@ public function test_chapter_export()
251251
$this->assertCount($chapter->pages()->count(), $chapterData['pages']);
252252
}
253253

254+
public function test_draft_pages_are_not_included()
255+
{
256+
$editor = $this->users->editor();
257+
$entities = $this->entities->createChainBelongingToUser($editor);
258+
$book = $entities['book'];
259+
$page = $entities['page'];
260+
$chapter = $entities['chapter'];
261+
$book->tags()->saveMany(Tag::factory()->count(2)->make());
262+
263+
$page->created_by = $editor->id;
264+
$page->draft = true;
265+
$page->save();
266+
267+
$zipResp = $this->actingAs($editor)->get($book->getUrl("/export/zip"));
268+
$zip = $this->extractZipResponse($zipResp);
269+
$this->assertCount(0, $zip->data['book']['chapters'][0]['pages'] ?? ['cat']);
270+
271+
$zipResp = $this->actingAs($editor)->get($chapter->getUrl("/export/zip"));
272+
$zip = $this->extractZipResponse($zipResp);
273+
$this->assertCount(0, $zip->data['chapter']['pages'] ?? ['cat']);
274+
275+
$page->chapter_id = 0;
276+
$page->save();
277+
278+
$zipResp = $this->actingAs($editor)->get($book->getUrl("/export/zip"));
279+
$zip = $this->extractZipResponse($zipResp);
280+
$this->assertCount(0, $zip->data['book']['pages'] ?? ['cat']);
281+
}
282+
254283

255284
public function test_cross_reference_links_are_converted()
256285
{

0 commit comments

Comments
 (0)