2
0

ArrayTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * @package Zend_Pdf
  4. * @subpackage UnitTests
  5. */
  6. /**
  7. * Zend_Pdf_Element_Array
  8. */
  9. require_once 'Zend/Pdf/Element/Array.php';
  10. /**
  11. * Zend_Pdf_Element_Boolean
  12. */
  13. require_once 'Zend/Pdf/Element/Boolean.php';
  14. /**
  15. * Zend_Pdf_Element_Numeric
  16. */
  17. require_once 'Zend/Pdf/Element/Numeric.php';
  18. /**
  19. * Zend_Pdf_Element_Name
  20. */
  21. require_once 'Zend/Pdf/Element/Name.php';
  22. /**
  23. * Zend_Pdf_Element_String
  24. */
  25. require_once 'Zend/Pdf/Element/String.php';
  26. /**
  27. * Zend_Pdf_Element_String_Binary
  28. */
  29. require_once 'Zend/Pdf/Element/String/Binary.php';
  30. /**
  31. * PHPUnit Test Case
  32. */
  33. require_once 'PHPUnit/Framework/TestCase.php';
  34. /**
  35. * @package Zend_Pdf
  36. * @subpackage UnitTests
  37. */
  38. class Zend_Pdf_Element_ArrayTest extends PHPUnit_Framework_TestCase
  39. {
  40. public function testPDFArray1()
  41. {
  42. $arrayObj = new Zend_Pdf_Element_Array();
  43. $this->assertTrue($arrayObj instanceof Zend_Pdf_Element_Array);
  44. }
  45. public function testPDFArray2()
  46. {
  47. $srcArray = array();
  48. $srcArray[] = new Zend_Pdf_Element_Boolean(false);
  49. $srcArray[] = new Zend_Pdf_Element_Numeric(100.426);
  50. $srcArray[] = new Zend_Pdf_Element_Name('MyName');
  51. $srcArray[] = new Zend_Pdf_Element_String('some text');
  52. $srcArray[] = new Zend_Pdf_Element_String_Binary('some text');
  53. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  54. $this->assertTrue($arrayObj instanceof Zend_Pdf_Element_Array);
  55. }
  56. public function testPDFArrayBadInput1()
  57. {
  58. try {
  59. $arrayObj = new Zend_Pdf_Element_Array(346);
  60. } catch (Zend_Pdf_Exception $e) {
  61. $this->assertRegExp('/must be an array/i', $e->getMessage());
  62. return;
  63. }
  64. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  65. }
  66. public function testPDFArrayBadInput2()
  67. {
  68. try {
  69. $srcArray = array();
  70. $srcArray[] = new Zend_Pdf_Element_Boolean(false);
  71. $srcArray[] = new Zend_Pdf_Element_Numeric(100.426);
  72. $srcArray[] = new Zend_Pdf_Element_Name('MyName');
  73. $srcArray[] = new Zend_Pdf_Element_String('some text');
  74. $srcArray[] = new Zend_Pdf_Element_String_Binary('some text');
  75. $srcArray[] = 24;
  76. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  77. } catch (Zend_Pdf_Exception $e) {
  78. $this->assertRegExp('/must be Zend_Pdf_Element/i', $e->getMessage());
  79. return;
  80. }
  81. $this->fail('No exception thrown.');
  82. }
  83. public function testGetType()
  84. {
  85. $arrayObj = new Zend_Pdf_Element_Array();
  86. $this->assertEquals($arrayObj->getType(), Zend_Pdf_Element::TYPE_ARRAY);
  87. }
  88. public function testToString()
  89. {
  90. $srcArray = array();
  91. $srcArray[] = new Zend_Pdf_Element_Boolean(false);
  92. $srcArray[] = new Zend_Pdf_Element_Numeric(100.426);
  93. $srcArray[] = new Zend_Pdf_Element_Name('MyName');
  94. $srcArray[] = new Zend_Pdf_Element_String('some text');
  95. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  96. $this->assertEquals($arrayObj->toString(), '[false 100.426 /MyName (some text) ]');
  97. }
  98. /**
  99. * @todo Zend_Pdf_Element_Array::add() does not exist
  100. */
  101. /*
  102. public function testAdd()
  103. {
  104. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  105. $arrayObj->add(new Zend_Pdf_Element_Boolean(false));
  106. $arrayObj->add(new Zend_Pdf_Element_Numeric(100.426));
  107. $arrayObj->add(new Zend_Pdf_Element_Name('MyName'));
  108. $arrayObj->add(new Zend_Pdf_Element_String('some text'));
  109. $this->assertEquals($arrayObj->toString(), '[false 100.426 /MyName (some text) ]' );
  110. }
  111. //*/
  112. /**
  113. * @todo Zend_Pdf_Element_Array::add() does not exist
  114. */
  115. /*
  116. public function testAddBadArgument()
  117. {
  118. try {
  119. $arrayObj = new ZPdfPDFArray();
  120. $arrayObj->add(100.426);
  121. } catch (Zend_Pdf_Exception $e) {
  122. $this->assertRegExp('/must be Zend_Pdf_Element/i', $e->getMessage());
  123. return;
  124. }
  125. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  126. }
  127. //*/
  128. }