ArrayTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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-2010 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. * PHPUnit Test Case
  48. */
  49. require_once 'PHPUnit/Framework/TestCase.php';
  50. /**
  51. * @category Zend
  52. * @package Zend_Pdf
  53. * @subpackage UnitTests
  54. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  55. * @license http://framework.zend.com/license/new-bsd New BSD License
  56. * @group Zend_Pdf
  57. */
  58. class Zend_Pdf_Element_ArrayTest extends PHPUnit_Framework_TestCase
  59. {
  60. public function testPDFArray1()
  61. {
  62. $arrayObj = new Zend_Pdf_Element_Array();
  63. $this->assertTrue($arrayObj instanceof Zend_Pdf_Element_Array);
  64. }
  65. public function testPDFArray2()
  66. {
  67. $srcArray = array();
  68. $srcArray[] = new Zend_Pdf_Element_Boolean(false);
  69. $srcArray[] = new Zend_Pdf_Element_Numeric(100.426);
  70. $srcArray[] = new Zend_Pdf_Element_Name('MyName');
  71. $srcArray[] = new Zend_Pdf_Element_String('some text');
  72. $srcArray[] = new Zend_Pdf_Element_String_Binary('some text');
  73. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  74. $this->assertTrue($arrayObj instanceof Zend_Pdf_Element_Array);
  75. }
  76. public function testPDFArrayBadInput1()
  77. {
  78. try {
  79. $arrayObj = new Zend_Pdf_Element_Array(346);
  80. } catch (Zend_Pdf_Exception $e) {
  81. $this->assertRegExp('/must be an array/i', $e->getMessage());
  82. return;
  83. }
  84. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  85. }
  86. public function testPDFArrayBadInput2()
  87. {
  88. try {
  89. $srcArray = array();
  90. $srcArray[] = new Zend_Pdf_Element_Boolean(false);
  91. $srcArray[] = new Zend_Pdf_Element_Numeric(100.426);
  92. $srcArray[] = new Zend_Pdf_Element_Name('MyName');
  93. $srcArray[] = new Zend_Pdf_Element_String('some text');
  94. $srcArray[] = new Zend_Pdf_Element_String_Binary('some text');
  95. $srcArray[] = 24;
  96. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  97. } catch (Zend_Pdf_Exception $e) {
  98. $this->assertRegExp('/must be Zend_Pdf_Element/i', $e->getMessage());
  99. return;
  100. }
  101. $this->fail('No exception thrown.');
  102. }
  103. public function testGetType()
  104. {
  105. $arrayObj = new Zend_Pdf_Element_Array();
  106. $this->assertEquals($arrayObj->getType(), Zend_Pdf_Element::TYPE_ARRAY);
  107. }
  108. public function testToString()
  109. {
  110. $srcArray = array();
  111. $srcArray[] = new Zend_Pdf_Element_Boolean(false);
  112. $srcArray[] = new Zend_Pdf_Element_Numeric(100.426);
  113. $srcArray[] = new Zend_Pdf_Element_Name('MyName');
  114. $srcArray[] = new Zend_Pdf_Element_String('some text');
  115. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  116. $this->assertEquals($arrayObj->toString(), '[false 100.426 /MyName (some text) ]');
  117. }
  118. /**
  119. * @todo Zend_Pdf_Element_Array::add() does not exist
  120. */
  121. /*
  122. public function testAdd()
  123. {
  124. $arrayObj = new Zend_Pdf_Element_Array($srcArray);
  125. $arrayObj->add(new Zend_Pdf_Element_Boolean(false));
  126. $arrayObj->add(new Zend_Pdf_Element_Numeric(100.426));
  127. $arrayObj->add(new Zend_Pdf_Element_Name('MyName'));
  128. $arrayObj->add(new Zend_Pdf_Element_String('some text'));
  129. $this->assertEquals($arrayObj->toString(), '[false 100.426 /MyName (some text) ]' );
  130. }
  131. //*/
  132. /**
  133. * @todo Zend_Pdf_Element_Array::add() does not exist
  134. */
  135. /*
  136. public function testAddBadArgument()
  137. {
  138. try {
  139. $arrayObj = new ZPdfPDFArray();
  140. $arrayObj->add(100.426);
  141. } catch (Zend_Pdf_Exception $e) {
  142. $this->assertRegExp('/must be Zend_Pdf_Element/i', $e->getMessage());
  143. return;
  144. }
  145. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  146. }
  147. //*/
  148. }