WriteHtmlTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class WriteHtmlTests extends PHPUnit_Framework_TestCase
  3. {
  4. private $mpdf;
  5. public function setup()
  6. {
  7. parent::setup();
  8. $this->mpdf = new mPDF();
  9. }
  10. /**
  11. * Verify what types of variables are accepted to $mpdf->WriteHTML()
  12. *
  13. * @dataProvider providerCastType
  14. *
  15. * @param boolean $exception Whether we expect an exception or not
  16. * @param mixed $html The variable to test
  17. */
  18. public function testCastType($exception, $html)
  19. {
  20. $thrown = '';
  21. try {
  22. $this->mpdf->WriteHTML($html);
  23. } catch (MpdfException $e) {
  24. $thrown = $e->getMessage();
  25. }
  26. if ($exception) {
  27. $this->assertEquals('WriteHTML() requires $html be an integer, float, string, boolean or an object with the __toString() magic method.', $thrown);
  28. } else {
  29. $this->assertEquals('', $thrown);
  30. }
  31. }
  32. /**
  33. * @return array
  34. */
  35. public function providerCastType()
  36. {
  37. return array(
  38. array(false, 'This is my string'),
  39. array(false, 20),
  40. array(false, 125.52),
  41. array(false, false),
  42. array(true, array('item', 'item2')),
  43. array(true, new WriteHtmlClass()),
  44. array(false, new WriteHtmlStringClass()),
  45. array(true, null),
  46. array(false, ''),
  47. );
  48. }
  49. }
  50. class WriteHtmlClass
  51. {
  52. }
  53. class WriteHtmlStringClass
  54. {
  55. public function __toString()
  56. {
  57. return 'special';
  58. }
  59. }