'ACME Corp']); expect(PdfMetadata::forDocument('Invoice', 'INV-000042', $company))->toBe([ 'Title' => 'Invoice INV-000042', 'Subject' => 'Invoice', 'Author' => 'ACME Corp', 'Creator' => config('app.name', 'InvoiceShelf'), ]); }); test('missing pieces are left out rather than written as empty strings', function () { $metadata = PdfMetadata::forDocument('Invoice', null, null); expect($metadata)->not->toHaveKey('Author') ->and($metadata['Title'])->toBe('Invoice'); }); test('the gotenberg request carries the metadata', function () { config(['pdf.connections.gotenberg.host' => 'http://gotenberg.example.com:3000']); $body = (string) (new GotenbergPdfDriver)->buildRequest( 'app.pdf.partials.fonts', ['Title' => 'Invoice INV-000042', 'Author' => 'ACME Corp'] )->getBody(); expect($body)->toContain('metadata') ->and($body)->toContain('Invoice INV-000042') ->and($body)->toContain('ACME Corp'); }); /** * dompdf reads Title from the element during render(), after any * addInfo() call, so metadata set through the API alone is silently overwritten * by whatever the template happened to put there -- and the two drivers end up * disagreeing about what the file is called. */ test('dompdf writes the metadata title into the markup so it is not overwritten', function () { $method = new ReflectionMethod(DompdfDriver::class, 'withDocumentTitle'); $result = $method->invoke( new DompdfDriver, '<html><head><title>whatever the template said', 'Invoice INV-000042' ); expect($result)->toContain('Invoice INV-000042') ->and($result)->not->toContain('whatever the template said'); }); test('a document with no title element gets one', function () { $method = new ReflectionMethod(DompdfDriver::class, 'withDocumentTitle'); $result = $method->invoke(new DompdfDriver, '', 'Invoice 42'); expect($result)->toContain('Invoice 42'); }); test('a title is escaped rather than injected as markup', function () { $method = new ReflectionMethod(DompdfDriver::class, 'withDocumentTitle'); $result = $method->invoke( new DompdfDriver, 'x', 'Invoice ' ); expect($result)->not->toContain('