ArrayTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Pdf
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Zend_Pdf_Element_Array
  24. */
  25. require_once 'Zend/Pdf/Element/Array.php';
  26. /**
  27. * Zend_Pdf_Element_Boolean
  28. */
  29. require_once 'Zend/Pdf/Element/Boolean.php';
  30. /**
  31. * Zend_Pdf_Element_Numeric
  32. */
  33. require_once 'Zend/Pdf/Element/Numeric.php';
  34. /**
  35. * Zend_Pdf_Element_Name
  36. */
  37. require_once 'Zend/Pdf/Element/Name.php';
  38. /**
  39. * Zend_Pdf_Element_String
  40. */
  41. require_once 'Zend/Pdf/Element/String.php';
  42. /**
  43. * Zend_Pdf_Element_String_Binary
  44. */
  45. require_once 'Zend/Pdf/Element/String/Binary.php';
  46. /**
  47. * @category Zend
  48. * @package Zend_Pdf
  49. * @subpackage UnitTests
  50. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  51. * @license http://framework.zend.com/license/new-bsd New BSD License
  52. * @group Zend_Pdf
  53. */
  54. class Zend_Pdf_Element_ArrayTest extends PHPUnit_Framework_TestCase
  55. {
  56. public function testPDFArray1()
  57. {
  58. $arrayObj = new Zend_Pdf_Element_Array();
  59. $this->assertTrue($arrayObj instanceof Zend_Pdf_Element_Array);
  60. }
  61. public function testPDFArray2()
  62. {
  63. $srcArray = array();
  64. $srcArray[] = new Zend_Pdf_Element_Boolean(false);
  65. $srcArray[] = new Zend_Pdf_Element_Numeric(100.426);
  66. $srcArray[] = new Zend_Pdf_Element_Name('MyName');
  67. $srcArray[] = new Zend_Pdf_Element_String('some text');
  68. $srcArray[] = new Zend_Pdf_Element_String_Binary('some text');
  69. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  70. $this->assertTrue($arrayObj instanceof Zend_Pdf_Element_Array);
  71. }
  72. public function testPDFArrayBadInput1()
  73. {
  74. try {
  75. $arrayObj = new Zend_Pdf_Element_Array(346);
  76. } catch (Zend_Pdf_Exception $e) {
  77. $this->assertRegExp('/must be an array/i', $e->getMessage());
  78. return;
  79. }
  80. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  81. }
  82. public function testPDFArrayBadInput2()
  83. {
  84. try {
  85. $srcArray = array();
  86. $srcArray[] = new Zend_Pdf_Element_Boolean(false);
  87. $srcArray[] = new Zend_Pdf_Element_Numeric(100.426);
  88. $srcArray[] = new Zend_Pdf_Element_Name('MyName');
  89. $srcArray[] = new Zend_Pdf_Element_String('some text');
  90. $srcArray[] = new Zend_Pdf_Element_String_Binary('some text');
  91. $srcArray[] = 24;
  92. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  93. } catch (Zend_Pdf_Exception $e) {
  94. $this->assertRegExp('/must be Zend_Pdf_Element/i', $e->getMessage());
  95. return;
  96. }
  97. $this->fail('No exception thrown.');
  98. }
  99. public function testGetType()
  100. {
  101. $arrayObj = new Zend_Pdf_Element_Array();
  102. $this->assertEquals($arrayObj->getType(), Zend_Pdf_Element::TYPE_ARRAY);
  103. }
  104. public function testToString()
  105. {
  106. $srcArray = array();
  107. $srcArray[] = new Zend_Pdf_Element_Boolean(false);
  108. $srcArray[] = new Zend_Pdf_Element_Numeric(100.426);
  109. $srcArray[] = new Zend_Pdf_Element_Name('MyName');
  110. $srcArray[] = new Zend_Pdf_Element_String('some text');
  111. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  112. $this->assertEquals($arrayObj->toString(), '[false 100.426 /MyName (some text) ]');
  113. }
  114. /**
  115. * @todo Zend_Pdf_Element_Array::add() does not exist
  116. */
  117. /*
  118. public function testAdd()
  119. {
  120. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  121. $arrayObj->add(new Zend_Pdf_Element_Boolean(false));
  122. $arrayObj->add(new Zend_Pdf_Element_Numeric(100.426));
  123. $arrayObj->add(new Zend_Pdf_Element_Name('MyName'));
  124. $arrayObj->add(new Zend_Pdf_Element_String('some text'));
  125. $this->assertEquals($arrayObj->toString(), '[false 100.426 /MyName (some text) ]' );
  126. }
  127. //*/
  128. /**
  129. * @todo Zend_Pdf_Element_Array::add() does not exist
  130. */
  131. /*
  132. public function testAddBadArgument()
  133. {
  134. try {
  135. $arrayObj = new ZPdfPDFArray();
  136. $arrayObj->add(100.426);
  137. } catch (Zend_Pdf_Exception $e) {
  138. $this->assertRegExp('/must be Zend_Pdf_Element/i', $e->getMessage());
  139. return;
  140. }
  141. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  142. }
  143. //*/
  144. }