Skip to content

Commit 6fd2f89

Browse files
committed
better examples and tests
1 parent fbbfc79 commit 6fd2f89

3 files changed

Lines changed: 36 additions & 60 deletions

File tree

Tests/ExamplesTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ protected function launchExample($example)
6262

6363
// test
6464
$this->assertNotEmpty($result);
65+
$this->assertStringStartsWith('%PDF-1.7', $result);
6566
}
6667

6768
/**
@@ -174,6 +175,16 @@ public function testExample08()
174175
$this->launchExample('example08');
175176
}
176177

178+
/**
179+
* test: example09
180+
*
181+
* @return void
182+
*/
183+
public function testExample09()
184+
{
185+
$this->launchExample('example09');
186+
}
187+
177188
/**
178189
* test: example10
179190
*

examples/example09.php

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,70 +15,21 @@
1515
use Spipu\Html2Pdf\Exception\Html2PdfException;
1616
use Spipu\Html2Pdf\Exception\ExceptionFormatter;
1717

18-
$name = 'spipu';
19-
$generate = false;
2018

21-
if (isset($_GET['nom'])) {
22-
$generate = true;
23-
$name = $_GET['nom'];
24-
$name = preg_replace('/[^a-zA-Z0-9]/isU', '', $name);
25-
$name = substr($name, 0, 26);
26-
} else if (!isset($_SERVER['REQUEST_URI'])) {
27-
$generate = true;
28-
}
19+
try {
20+
$name = 'spipu';
2921

30-
if ($generate) {
3122
ob_start();
32-
} else {
33-
?>
34-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
35-
<html>
36-
<head>
37-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
38-
<title>Exemple d'auto génération de PDF</title>
39-
</head>
40-
<body>
41-
<?php
42-
}
43-
?>
44-
<br>
45-
Ceci est un exemple de génération de PDF via un bouton :)<br>
46-
<br>
47-
<img src="http://html2pdf-dev.lxd/res/example09.png.php?px=5&amp;py=20" alt="image_php" ><br>
48-
<br>
49-
<?php
50-
if ($generate) {
51-
?>
52-
Bonjour <b><?php echo $name; ?></b>, ton nom peut s'écrire : <br>
53-
<barcode type="C39" value="<?php echo strtoupper($name); ?>" style="color: #770000" ></barcode><hr>
54-
<br>
55-
<?php
56-
}
57-
?>
58-
<br>
59-
<?php
60-
if ($generate) {
23+
include dirname(__FILE__).'/res/example09.php';
6124
$content = ob_get_clean();
6225

63-
try {
64-
$html2pdf = new Html2Pdf('P', 'A4', 'fr');
65-
$html2pdf->getSecurityService()->addAllowedHost('html2pdf-dev.lxd');
66-
$html2pdf->writeHTML($content);
67-
$html2pdf->output('example09.pdf');
68-
exit;
69-
} catch (Html2PdfException $e) {
70-
$html2pdf->clean();
26+
$html2pdf = new Html2Pdf('P', 'A4', 'fr');
27+
$html2pdf->getSecurityService()->addAllowedHost('html2pdf-dev.lxd');
28+
$html2pdf->writeHTML($content);
29+
$html2pdf->output('example09.pdf');
30+
} catch (Html2PdfException $e) {
31+
$html2pdf->clean();
7132

72-
$formatter = new ExceptionFormatter($e);
73-
echo $formatter->getHtmlMessage();
74-
exit;
75-
}
33+
$formatter = new ExceptionFormatter($e);
34+
echo $formatter->getHtmlMessage();
7635
}
77-
?>
78-
<form method="get" action="">
79-
<input type="hidden" name="make_pdf" value="">
80-
Ton nom : <input type="text" name="nom" value=""> -
81-
<input type="submit" value="Generer le PDF" >
82-
</form>
83-
</body>
84-
</html>

examples/res/example09.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
$name = preg_replace('/[^a-zA-Z0-9]/isU', '', (string) $name);
3+
$name = substr($name, 0, 26);
4+
?>
5+
<page>
6+
<br>
7+
Ceci est un exemple de génération de PDF :)<br>
8+
<br>
9+
<img src="http://html2pdf-dev.lxd/res/example09.png.php?px=5&amp;py=20" alt="image_php" ><br>
10+
<br>
11+
Bonjour <b><?php echo $name; ?></b>, ton nom peut s'écrire : <br>
12+
<barcode type="C39" value="<?php echo strtoupper($name); ?>" style="color: #770000" ></barcode><hr>
13+
<br>
14+
</page>

0 commit comments

Comments
 (0)