FileNameOkTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Output;
  13. use Spipu\Html2Pdf\Exception\Html2PdfException;
  14. use Spipu\Html2Pdf\Tests\AbstractTest;
  15. /**
  16. * Class FileNameOkTest
  17. */
  18. class FileNameOkTest extends AbstractTest
  19. {
  20. /**
  21. * test: the file extension must be PDF - OK
  22. *
  23. * @return void
  24. */
  25. public function testOk()
  26. {
  27. $object = $this->getObject();
  28. $object->writeHTML('Hello World');
  29. ob_start();
  30. $object->output('test.pdf');
  31. $result = ob_get_clean();
  32. $this->assertContains('PhpUnit Test', $result);
  33. }
  34. /**
  35. * test: the file extension is ignored if output string
  36. *
  37. * @return void
  38. */
  39. public function testIgnore()
  40. {
  41. $object = $this->getObject();
  42. $object->writeHTML('Hello World');
  43. $result = $object->output('test.bad', 'S');
  44. $this->assertContains('PhpUnit Test', $result);
  45. }
  46. /**
  47. * test: the file extension must be PDF - Error
  48. *
  49. * @return void
  50. */
  51. public function testError()
  52. {
  53. $this->expectException(Html2PdfException::class);
  54. $object = $this->getObject();
  55. $object->writeHTML('<p>Hello World</p>');
  56. $object->output('test.bad');
  57. }
  58. }