HtmlTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Tests\CrossVersionCompatibility\HtmlTestCase;
  14. /**
  15. * Class HtmlTest
  16. */
  17. class HtmlTest extends HtmlTestCase
  18. {
  19. /**
  20. * mock of prepareTxt method
  21. *
  22. * @param $txt
  23. * @param bool $spaces
  24. * @return mixed
  25. */
  26. public function mockPrepareTxt($txt, $spaces = true)
  27. {
  28. return $txt;
  29. }
  30. /**
  31. * Test the prepareHtml method
  32. */
  33. public function testPrepareHtml()
  34. {
  35. $result = $this->object->prepareHtml('Hello [[date_y]]-[[date_m]]-[[date_d]] World');
  36. $this->assertSame('Hello '.date('Y-m-d').' World', $result);
  37. $result = $this->object->prepareHtml('Hello [[date_h]]:[[date_i]]:[[date_s]] World');
  38. $this->assertSame('Hello '.date('H:i:s').' World', $result);
  39. $html = '
  40. <html>
  41. <head>
  42. <style type="text">.my-class { color: red; }</style>
  43. <link type="text/css" href="my-style.css"/>
  44. </head>
  45. <body class="my-class"><p>Hello World</p></body>
  46. </html>';
  47. $expected='<style type="text">.my-class { color: red; }</style>'.
  48. '<link type="text/css" href="my-style.css"/>'.
  49. '<page class="my-class"><p>Hello World</p></page>';
  50. $result = $this->object->prepareHtml($html);
  51. $this->assertSame($expected, $result);
  52. }
  53. }