source: trunk/client/inc/hpdf5/spipu/html2pdf/src/Tests/ExamplesTest.php@ 407

Last change on this file since 407 was 347, checked in by roby, 3 years ago

Aggiornamento per compatibilità con php7.4

File size: 5.7 KB
Line 
1<?php
2/**
3 * Html2Pdf Library - Tests
4 *
5 * HTML => PDF converter
6 * distributed under the OSL-3.0 License
7 *
8 * @package Html2pdf
9 * @author Laurent MINGUET <webmaster@html2pdf.fr>
10 * @copyright 2017 Laurent MINGUET
11 */
12
13namespace Spipu\Html2Pdf\Tests;
14
15/**
16 * Class ExamplesTest
17 */
18class ExamplesTest extends \PHPUnit_Framework_TestCase
19{
20 /**
21 * Launch a example
22 *
23 * @param string $example code of the example
24 *
25 * @return void
26 * @throws \Exception
27 */
28 protected function launchExample($example)
29 {
30 $filename = dirname(dirname(dirname(__FILE__))).'/examples/'.$example.'.php';
31 if (!is_file($filename)) {
32 throw new \Exception('The filename of the example ['.$example.'] does not exist!');
33 }
34 $folder = dirname($filename);
35
36 // get the content of the file
37 $content = file_get_contents($filename);
38
39 // keep only the example
40 $parts = explode('try {', $content);
41 $parts = explode('} catch', $parts[1]);
42 $content = $parts[0];
43
44 // replace the good path
45 $content = str_replace('dirname(__FILE__)', "'$folder'", $content);
46
47 // add the class to use
48 $content = 'use Spipu\Html2Pdf\Html2Pdf; '.$content;
49
50 // get the output
51 $regexp = '/\$html2pdf->output\(([^\)]*)\);/';
52 $replace = 'return $html2pdf->output(\'test.pdf\', \'S\');';
53 $content = preg_replace($regexp, $replace, $content);
54
55 // execute
56 $currentDir = getcwd();
57 chdir($folder);
58 $result = eval($content);
59 chdir($currentDir);
60
61 // test
62 $this->assertNotEmpty($result);
63 }
64
65 /**
66 * test: about
67 *
68 * @return void
69 */
70 public function testAbout()
71 {
72 $this->launchExample('about');
73 }
74
75 /**
76 * test: bookmark
77 *
78 * @return void
79 */
80 public function testBookmark()
81 {
82 $this->launchExample('bookmark');
83 }
84
85 /**
86 * test: bookmark
87 *
88 * @return void
89 */
90 public function testBalloon()
91 {
92 $this->launchExample('balloon');
93 }
94
95 /**
96 * test: example01
97 *
98 * @return void
99 */
100 public function testExample01()
101 {
102 $this->launchExample('example01');
103 }
104
105 /**
106 * test: example02
107 *
108 * @return void
109 */
110 public function testExample02()
111 {
112 $this->launchExample('example02');
113 }
114
115 /**
116 * test: example03
117 *
118 * @return void
119 */
120 public function testExample03()
121 {
122 $this->launchExample('example03');
123 }
124
125 /**
126 * test: example04
127 *
128 * @return void
129 */
130 public function testExample04()
131 {
132 $this->launchExample('example04');
133 }
134
135 /**
136 * test: example05
137 *
138 * @return void
139 */
140 public function testExample05()
141 {
142 $this->launchExample('example05');
143 }
144
145 /**
146 * test: example06
147 *
148 * @return void
149 */
150 public function testExample06()
151 {
152 $this->launchExample('example06');
153 }
154
155 /**
156 * test: example07
157 *
158 * @return void
159 */
160 public function testExample07()
161 {
162 $this->launchExample('example07');
163 }
164
165 /**
166 * test: example08
167 *
168 * @return void
169 */
170 public function testExample08()
171 {
172 $this->launchExample('example08');
173 }
174
175 /**
176 * test: example10
177 *
178 * @return void
179 */
180 public function testExample10()
181 {
182 $this->launchExample('example10');
183 }
184
185 /**
186 * test: example11
187 *
188 * @return void
189 */
190 public function testExample11()
191 {
192 $this->launchExample('example11');
193 }
194
195 /**
196 * test: example12
197 *
198 * @return void
199 */
200 public function testExample12()
201 {
202 $this->launchExample('example12');
203 }
204
205 /**
206 * test: example13
207 *
208 * @return void
209 */
210 public function testExample13()
211 {
212 $this->launchExample('example13');
213 }
214
215 /**
216 * test: example14
217 *
218 * @return void
219 */
220 public function testExample14()
221 {
222 $this->launchExample('example14');
223 }
224
225 /**
226 * test: example15
227 *
228 * @return void
229 */
230 public function testExample15()
231 {
232 $this->launchExample('example15');
233 }
234
235 /**
236 * test: forms
237 *
238 * @return void
239 */
240 public function testForms()
241 {
242 $this->launchExample('forms');
243 }
244
245 /**
246 * test: groups
247 *
248 * @return void
249 */
250 public function testGroups()
251 {
252 $this->launchExample('groups');
253 }
254
255 /**
256 * test: qrcode
257 *
258 * @return void
259 */
260 public function testQrcode()
261 {
262 $this->launchExample('qrcode');
263 }
264
265 /**
266 * test: radius
267 *
268 * @return void
269 */
270 public function testRadius()
271 {
272 $this->launchExample('radius');
273 }
274
275 /**
276 * test: regle
277 *
278 * @return void
279 */
280 public function testMeasure()
281 {
282 $this->launchExample('measure');
283 }
284
285 /**
286 * test: svg
287 *
288 * @return void
289 */
290 public function testSvg()
291 {
292 $this->launchExample('svg');
293 }
294
295 /**
296 * test: svg_tiger
297 *
298 * @return void
299 */
300 public function testSvgTiger()
301 {
302 $this->launchExample('svg_tiger');
303 }
304
305 /**
306 * test: svg_tree
307 *
308 * @return void
309 */
310 public function testSvgTree()
311 {
312 $this->launchExample('svg_tree');
313 }
314
315 /**
316 * test: ticket
317 *
318 * @return void
319 */
320 public function testTicket()
321 {
322 $this->launchExample('ticket');
323 }
324
325 /**
326 * test: utf8
327 *
328 * @return void
329 */
330 public function testUtf8()
331 {
332 $this->launchExample('utf8');
333 }
334}
Note: See TracBrowser for help on using the repository browser.