entities->page(); $this->asEditor(); $resp = $this->get($page->getUrl('/export/pdf')); $resp->assertStatus(200); $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.pdf"'); } public function test_book_pdf_export() { $page = $this->entities->page(); $book = $page->book; $this->asEditor(); $resp = $this->get($book->getUrl('/export/pdf')); $resp->assertStatus(200); $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $book->slug . '.pdf"'); } public function test_chapter_pdf_export() { $chapter = $this->entities->chapter(); $this->asEditor(); $resp = $this->get($chapter->getUrl('/export/pdf')); $resp->assertStatus(200); $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.pdf"'); } public function test_page_pdf_export_converts_iframes_to_links() { $page = Page::query()->first()->forceFill([ 'html' => '', ]); $page->save(); $pdfHtml = ''; $mockPdfGenerator = $this->mock(PdfGenerator::class); $mockPdfGenerator->shouldReceive('fromHtml') ->with(\Mockery::capture($pdfHtml)) ->andReturn(''); $mockPdfGenerator->shouldReceive('getActiveEngine')->andReturn(PdfGenerator::ENGINE_DOMPDF); $this->asEditor()->get($page->getUrl('/export/pdf')); $this->assertStringNotContainsString('iframe>', $pdfHtml); $this->assertStringContainsString('

https://www.youtube.com/embed/ShqUjt33uOs

', $pdfHtml); } public function test_page_pdf_export_opens_details_blocks() { $page = $this->entities->page()->forceFill([ 'html' => '
Hello

Content!

', ]); $page->save(); $pdfHtml = ''; $mockPdfGenerator = $this->mock(PdfGenerator::class); $mockPdfGenerator->shouldReceive('fromHtml') ->with(\Mockery::capture($pdfHtml)) ->andReturn(''); $mockPdfGenerator->shouldReceive('getActiveEngine')->andReturn(PdfGenerator::ENGINE_DOMPDF); $this->asEditor()->get($page->getUrl('/export/pdf')); $this->assertStringContainsString('
entities->page(); config()->set('exports.snappy.pdf_binary', '/abc123'); config()->set('app.allow_untrusted_server_fetching', false); $resp = $this->asEditor()->get($page->getUrl('/export/pdf')); $resp->assertStatus(200); // Sucessful response with invalid snappy binary indicates dompdf usage. config()->set('app.allow_untrusted_server_fetching', true); $resp = $this->get($page->getUrl('/export/pdf')); $resp->assertStatus(500); // Bad response indicates wkhtml usage } public function test_pdf_command_option_used_if_set() { $page = $this->entities->page(); $command = 'cp {input_html_path} {output_pdf_path}'; config()->set('exports.pdf_command', $command); $resp = $this->asEditor()->get($page->getUrl('/export/pdf')); $download = $resp->getContent(); $this->assertStringContainsString(e($page->name), $download); $this->assertStringContainsString('set('exports.pdf_command', $command); $this->assertThrows(function () use ($page) { $this->withoutExceptionHandling()->asEditor()->get($page->getUrl('/export/pdf')); }, PdfExportException::class); } public function test_pdf_command_option_errors_if_command_returns_error_status() { $page = $this->entities->page(); $command = 'exit 1'; config()->set('exports.pdf_command', $command); $this->assertThrows(function () use ($page) { $this->withoutExceptionHandling()->asEditor()->get($page->getUrl('/export/pdf')); }, PdfExportException::class); } public function test_pdf_command_timout_option_limits_export_time() { $page = $this->entities->page(); $command = 'php -r \'sleep(4);\''; config()->set('exports.pdf_command', $command); config()->set('exports.pdf_command_timeout', 1); $this->assertThrows(function () use ($page) { $start = time(); $this->withoutExceptionHandling()->asEditor()->get($page->getUrl('/export/pdf')); $this->assertTrue(time() < ($start + 3)); }, PdfExportException::class, "PDF Export via command failed due to timeout at 1 second(s)"); } }