Skip to content

Commit f4c9d2b

Browse files
committed
Exports: Fixed scope of pages in chapter MD export
Added tests to cover children of all MD exports
1 parent 60a3b0c commit f4c9d2b

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

app/Exports/ExportFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public function chapterToMarkdown(Chapter $chapter): string
323323
$text .= $description . "\n\n";
324324
}
325325

326-
foreach ($chapter->pages as $page) {
326+
foreach ($chapter->getVisiblePages() as $page) {
327327
$text .= $this->pageToMarkdown($page) . "\n\n";
328328
}
329329

tests/Exports/MarkdownExportTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ public function test_chapter_markdown_export()
5656
$resp->assertSee('My **chapter** description');
5757
}
5858

59+
public function test_chapter_markdown_export_pages_are_permission_controlled()
60+
{
61+
$chapter = $this->entities->chapterHasPages();
62+
$page = $chapter->pages()->first();
63+
$page->name = 'MyPageWhichShouldNotBeFound';
64+
$page->save();
65+
$this->permissions->disableEntityInheritedPermissions($page);
66+
67+
$resp = $this->asEditor()->get($chapter->getUrl('/export/markdown'));
68+
69+
$resp->assertSee('# ' . $chapter->name);
70+
$resp->assertDontSee('MyPageWhichShouldNotBeFound');
71+
}
72+
5973
public function test_book_markdown_export()
6074
{
6175
$book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
@@ -76,6 +90,38 @@ public function test_book_markdown_export()
7690
$resp->assertSee('My **chapter** description');
7791
}
7892

93+
public function test_book_markdown_export_chapters_are_permission_controlled()
94+
{
95+
$book = $this->entities->bookHasChaptersAndPages();
96+
$chapter = $book->chapters()->first();
97+
$page = $chapter->pages()->first();
98+
$page->name = 'MyPageWhichShouldNotBeFound';
99+
$page->save();
100+
$chapter->name = 'MyChapterWhichShouldNotBeFound';
101+
$chapter->save();
102+
$this->permissions->disableEntityInheritedPermissions($chapter);
103+
104+
$resp = $this->asEditor()->get($book->getUrl('/export/markdown'));
105+
106+
$resp->assertSee('# ' . $book->name);
107+
$resp->assertDontSee('MyChapterWhichShouldNotBeFound');
108+
$resp->assertDontSee('MyPageWhichShouldNotBeFound');
109+
}
110+
111+
public function test_book_markdown_export_direct_pages_are_permission_controlled()
112+
{
113+
$book = $this->entities->bookHasChaptersAndPages();
114+
$page = $book->directPages()->first();
115+
$page->name = 'MyPageWhichShouldNotBeFound';
116+
$page->save();
117+
$this->permissions->disableEntityInheritedPermissions($page);
118+
119+
$resp = $this->asEditor()->get($book->getUrl('/export/markdown'));
120+
121+
$resp->assertSee('# ' . $book->name);
122+
$resp->assertDontSee('MyPageWhichShouldNotBeFound');
123+
}
124+
79125
public function test_book_markdown_export_concats_immediate_pages_with_newlines()
80126
{
81127
/** @var Book $book */

0 commit comments

Comments
 (0)