Include example table html

This commit is contained in:
Benjamin Beganović 2020-07-14 15:13:46 +02:00
parent b774a07e30
commit 141d82b925
3 changed files with 67 additions and 5 deletions

2
.gitignore vendored
View File

@ -27,4 +27,4 @@ local_version.txt
storage/migrations storage/migrations
nbproject nbproject
.php_cs.cache .php_cs.cache

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\PdfMaker; namespace Tests\Feature\PdfMaker;
use Spatie\Browsershot\Browsershot;
use Tests\TestCase; use Tests\TestCase;
class PdfMakerTest extends TestCase class PdfMakerTest extends TestCase
@ -171,7 +172,7 @@ class PdfMakerTest extends TestCase
$output1 = $maker1->getCompiledHTML(); $output1 = $maker1->getCompiledHTML();
$this->assertStringContainsString('<div id="header">This is $title</div>', $output1); $this->assertStringContainsString('<div id="header">$title</div>', $output1);
$maker2 = new PdfMaker([ $maker2 = new PdfMaker([
'template' => [ 'template' => [
@ -188,7 +189,7 @@ class PdfMakerTest extends TestCase
$output2 = $maker2->getCompiledHTML(); $output2 = $maker2->getCompiledHTML();
$this->assertStringContainsString('<div id="header" hidden="true">This is $title</div>', $output2); $this->assertStringContainsString('<div id="header" hidden="true">$title</div>', $output2);
$this->assertNotSame($output1, $output2); $this->assertNotSame($output1, $output2);
} }
@ -249,4 +250,62 @@ class PdfMakerTest extends TestCase
$this->assertEquals('span', $after[1]); $this->assertEquals('span', $after[1]);
} }
public function testGeneratingPdf()
{
$state = [
'template' => [
'header' => [
'id' => 'header',
'properties' => ['class' => 'text-white bg-blue-600 p-2'],
],
'product-table' => [
'id' => 'product-table',
'properties' => ['class' => 'table-auto'],
'elements' => [
['element' => 'thead', 'content' => '', 'elements' => [
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'th', 'content' => 'Title', 'properties' => ['class' => 'px-4 py-2']],
['element' => 'th', 'content' => 'Author', 'properties' => ['class' => 'px-4 py-2']],
['element' => 'th', 'content' => 'Views', 'properties' => ['class' => 'px-4 py-2']],
]]
]],
['element' => 'tbody', 'content' => '', 'elements' => [
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'td', 'content' => 'An amazing guy', 'properties' => ['class' => 'border px-4 py-2']],
['element' => 'td', 'content' => 'David Bomba', 'properties' => ['class' => 'border px-4 py-2']],
['element' => 'td', 'content' => '1M', 'properties' => ['class' => 'border px-4 py-2']],
]],
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'td', 'content' => 'Flutter master', 'properties' => ['class' => 'border px-4 py-2']],
['element' => 'td', 'content' => 'Hillel Coren', 'properties' => ['class' => 'border px-4 py-2']],
['element' => 'td', 'content' => '1M', 'properties' => ['class' => 'border px-4 py-2']],
]],
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'td', 'content' => 'Bosssssssss', 'properties' => ['class' => 'border px-4 py-2']],
['element' => 'td', 'content' => 'Shalom Stark', 'properties' => ['class' => 'border px-4 py-2']],
['element' => 'td', 'content' => '1M', 'properties' => ['class' => 'border px-4 py-2']],
]],
['element' => 'tr', 'content' => '', 'order' => 4, 'elements' => [
['element' => 'td', 'content' => 'Three amazing guys', 'properties' => ['class' => 'border px-4 py-2', 'colspan' => '100%']],
]],
]],
],
]
],
'variables' =>[
'$title' => 'Invoice Ninja',
]
];
$maker = new PdfMaker($state);
$maker
->design(Business::class)
->build();
info($maker->getCompiledHTML());
$this->assertTrue(true);
}
} }

View File

@ -1,4 +1,7 @@
<!-- Business --> <!-- Business -->
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet"> <link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<div id="header">This is $title</div>
<table id="product-table"></table> <body class="m-10">
<div id="header">$title</div>
<table id="product-table"></table>
</body>