mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-05-04 18:08:46 +03:00
Exports: Added testing coverage for DOMPDF font usage
This commit is contained in:
@@ -68,7 +68,6 @@ class PdfGenerator
|
||||
$fontMetrics->setFontFamily($fontFamily, $fonts);
|
||||
}
|
||||
|
||||
// dd($userFontfamilies, $fontMetrics->getFontFamilies());
|
||||
$domPdf->loadHTML($this->convertEntities($html));
|
||||
$domPdf->render();
|
||||
|
||||
|
||||
@@ -79,6 +79,39 @@ class PdfExportTest extends TestCase
|
||||
$this->assertStringContainsString('<details open="open"', $pdfHtml);
|
||||
}
|
||||
|
||||
public function test_custom_fonts_loaded_for_dom_pdf_when_used()
|
||||
{
|
||||
// Set up custom font usage
|
||||
$page = $this->entities->page()->forceFill([
|
||||
'html' => '<p><strong>Bold</strong>text</p>',
|
||||
]);
|
||||
$page->save();
|
||||
$this->setSettings([
|
||||
'app-custom-head' => '<style>* { font-family: "meow words"}</style>'
|
||||
]);
|
||||
$normalFont = $this->files->testFilePath('fonts/Cardiff.ttf');
|
||||
$normalFontTarget = storage_path('fonts/dompdf/MeowWords.ttf');
|
||||
$boldFont = $this->files->testFilePath('fonts/Cardiff-Bold.ttf');
|
||||
$boldFontTarget = storage_path('fonts/dompdf/MeowWords-Bold.ttf');
|
||||
copy($normalFont, $normalFontTarget);
|
||||
copy($boldFont, $boldFontTarget);
|
||||
|
||||
$resp = $this->asEditor()->get($page->getUrl('/export/pdf'));
|
||||
$resp->assertStatus(200);
|
||||
|
||||
// Existance of UFM files indicates the metrics have been generated
|
||||
$this->assertFileExists(storage_path('fonts/dompdf/MeowWords.ufm'));
|
||||
$this->assertFileExists(storage_path('fonts/dompdf/MeowWords-Bold.ufm'));
|
||||
// Existence of cache json files indicates the fonts have been used
|
||||
$this->assertFileExists(storage_path('fonts/dompdf/cache/MeowWords.ufm.json'));
|
||||
$this->assertFileExists(storage_path('fonts/dompdf/cache/MeowWords-Bold.ufm.json'));
|
||||
|
||||
$filesToCleanUp = [...glob(storage_path('fonts/dompdf/Meow*')), ...glob(storage_path('fonts/dompdf/cache/Meow*'))];
|
||||
foreach ($filesToCleanUp as $file) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_wkhtmltopdf_only_used_when_allow_untrusted_is_true()
|
||||
{
|
||||
$page = $this->entities->page();
|
||||
|
||||
BIN
tests/test-data/fonts/Cardiff-Bold.ttf
Normal file
BIN
tests/test-data/fonts/Cardiff-Bold.ttf
Normal file
Binary file not shown.
BIN
tests/test-data/fonts/Cardiff.ttf
Normal file
BIN
tests/test-data/fonts/Cardiff.ttf
Normal file
Binary file not shown.
2
tests/test-data/fonts/attribution.txt
Normal file
2
tests/test-data/fonts/attribution.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
Font files by Roger White, in public domain.
|
||||
https://web.archive.org/web/20110609213636/http://www.rogersfonts.org.uk/
|
||||
Reference in New Issue
Block a user