+ $page = $this->entities->page();
+ $zipResp = $this->asEditor()->get($page->getUrl("/export/zip"));
+ $zip = $this->extractZipResponse($zipResp);
+
+ $pageData = $zip->data['page'];
+ $this->assertEquals([
+ 'id' => $page->id,
+ 'name' => $page->name,
+ 'html' => (new PageContent($page))->render(),
+ 'priority' => $page->priority,
+ 'attachments' => [],
+ 'images' => [],
+ 'tags' => [],
+ ], $pageData);
+ }
+
+ public function test_page_export_with_markdown()
+ {
+ $page = $this->entities->page();
+ $markdown = "# My page\n\nwritten in markdown for export\n";
+ $page->markdown = $markdown;
+ $page->save();
+
+ $zipResp = $this->asEditor()->get($page->getUrl("/export/zip"));
+ $zip = $this->extractZipResponse($zipResp);
+
+ $pageData = $zip->data['page'];
+ $this->assertEquals($markdown, $pageData['markdown']);
+ $this->assertNotEmpty($pageData['html']);
+ }
+
+ public function test_page_export_with_tags()
+ {
+ $page = $this->entities->page();
+ $page->tags()->saveMany([
+ new Tag(['name' => 'Exporty', 'value' => 'Content', 'order' => 1]),
+ new Tag(['name' => 'Another', 'value' => '', 'order' => 2]),
+ ]);
+
+ $zipResp = $this->asEditor()->get($page->getUrl("/export/zip"));
+ $zip = $this->extractZipResponse($zipResp);
+
+ $pageData = $zip->data['page'];
+ $this->assertEquals([
+ [
+ 'name' => 'Exporty',
+ 'value' => 'Content',
+ 'order' => 1,
+ ],
+ [
+ 'name' => 'Another',
+ 'value' => '',
+ 'order' => 2,
+ ]
+ ], $pageData['tags']);
+ }
+
+ public function test_page_export_with_images()
+ {
+ $this->asEditor();
+ $page = $this->entities->page();
+ $result = $this->files->uploadGalleryImageToPage($this, $page);
+ $displayThumb = $result['response']->thumbs->gallery ?? '';
+ $page->html = '<p><img src="' . $displayThumb . '" alt="My image"></p>';
+ $page->save();
+ $image = Image::findOrFail($result['response']->id);
+
+ $zipResp = $this->asEditor()->get($page->getUrl("/export/zip"));
+ $zip = $this->extractZipResponse($zipResp);
+ $pageData = $zip->data['page'];
+
+ $this->assertCount(1, $pageData['images']);
+ $imageData = $pageData['images'][0];
+ $this->assertEquals($image->id, $imageData['id']);
+ $this->assertEquals($image->name, $imageData['name']);
+ $this->assertEquals('gallery', $imageData['type']);
+ $this->assertNotEmpty($imageData['file']);
+
+ $filePath = $zip->extractPath("files/{$imageData['file']}");
+ $this->assertFileExists($filePath);
+ $this->assertEquals(file_get_contents(public_path($image->path)), file_get_contents($filePath));
+
+ $this->assertEquals('<p><img src="[[bsexport:image:' . $imageData['id'] . ']]" alt="My image"></p>', $pageData['html']);
+ }
+
+ public function test_page_export_file_attachments()
+ {
+ $contents = 'My great attachment content!';
+
+ $page = $this->entities->page();
+ $this->asAdmin();
+ $attachment = $this->files->uploadAttachmentDataToPage($this, $page, 'PageAttachmentExport.txt', $contents, 'text/plain');
+
+ $zipResp = $this->get($page->getUrl("/export/zip"));
+ $zip = $this->extractZipResponse($zipResp);
+
+ $pageData = $zip->data['page'];
+ $this->assertCount(1, $pageData['attachments']);
+
+ $attachmentData = $pageData['attachments'][0];
+ $this->assertEquals('PageAttachmentExport.txt', $attachmentData['name']);
+ $this->assertEquals($attachment->id, $attachmentData['id']);
+ $this->assertEquals(1, $attachmentData['order']);
+ $this->assertArrayNotHasKey('link', $attachmentData);
+ $this->assertNotEmpty($attachmentData['file']);
+
+ $fileRef = $attachmentData['file'];
+ $filePath = $zip->extractPath("/files/$fileRef");
+ $this->assertFileExists($filePath);
+ $this->assertEquals($contents, file_get_contents($filePath));
+ }
+
+ public function test_page_export_link_attachments()
+ {
+ $page = $this->entities->page();
+ $this->asEditor();
+ $attachment = Attachment::factory()->create([
+ 'name' => 'My link attachment for export',
+ 'path' => 'https://example.com/cats',
+ 'external' => true,
+ 'uploaded_to' => $page->id,
+ 'order' => 1,
+ ]);
+
+ $zipResp = $this->get($page->getUrl("/export/zip"));
+ $zip = $this->extractZipResponse($zipResp);
+
+ $pageData = $zip->data['page'];
+ $this->assertCount(1, $pageData['attachments']);
+
+ $attachmentData = $pageData['attachments'][0];
+ $this->assertEquals('My link attachment for export', $attachmentData['name']);
+ $this->assertEquals($attachment->id, $attachmentData['id']);
+ $this->assertEquals(1, $attachmentData['order']);
+ $this->assertEquals('https://example.com/cats', $attachmentData['link']);
+ $this->assertArrayNotHasKey('file', $attachmentData);