ParsingTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\Parsing;
  13. use Spipu\Html2Pdf\Exception\HtmlParsingException;
  14. use Spipu\Html2Pdf\Tests\AbstractTest;
  15. /**
  16. * Class ParsingTest
  17. */
  18. class ParsingTest extends AbstractTest
  19. {
  20. /**
  21. * test: The tag is unknown
  22. *
  23. * @return void
  24. */
  25. public function testUnknownTag()
  26. {
  27. $this->expectException(HtmlParsingException::class);
  28. $object = $this->getObject();
  29. $object->writeHTML('<bad_tag>Hello World</bad_tag>');
  30. $object->output('test.pdf', 'S');
  31. }
  32. /**
  33. * test: Too many tag closures found
  34. *
  35. * @return void
  36. */
  37. public function testTooManyClosuresFound()
  38. {
  39. $this->expectException(HtmlParsingException::class);
  40. $object = $this->getObject();
  41. $object->writeHTML('<i><u>Hello</u></i></b>');
  42. $object->output('test.pdf', 'S');
  43. }
  44. /**
  45. * test: Tags are closed in a wrong order
  46. *
  47. * @return void
  48. */
  49. public function testWrongClosedOrder()
  50. {
  51. $this->expectException(HtmlParsingException::class);
  52. $object = $this->getObject();
  53. $object->writeHTML('<b><u><i>Hello</u></i></b>');
  54. $object->output('test.pdf', 'S');
  55. }
  56. /**
  57. * test: The following tag has not been closed
  58. *
  59. * @return void
  60. */
  61. public function testNotClosed()
  62. {
  63. $this->expectException(HtmlParsingException::class);
  64. $object = $this->getObject();
  65. $object->writeHTML('<b><i>Hello</i>');
  66. $object->output('test.pdf', 'S');
  67. }
  68. /**
  69. * test: The following tags have not been closed
  70. *
  71. * @return void
  72. */
  73. public function testNotClosedMore()
  74. {
  75. $this->expectException(HtmlParsingException::class);
  76. $object = $this->getObject();
  77. $object->writeHTML('<b><u><i>Hello</i>');
  78. $object->output('test.pdf', 'S');
  79. }
  80. /**
  81. * test: The HTML tag code provided is invalid
  82. *
  83. * @return void
  84. */
  85. public function testInvalidCode()
  86. {
  87. $this->expectException(HtmlParsingException::class);
  88. $object = $this->getObject();
  89. $object->writeHTML('<az1-r_h>Hello</az1-r_h>');
  90. $object->output('test.pdf', 'S');
  91. }
  92. }