ExamplesTest.php 5.7 KB

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