2
0

ObjectTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. /** Zend_Pdf_Element_Object */
  23. require_once 'Zend/Pdf/Element/Object.php';
  24. /** Zend_Pdf_Element_Numeric */
  25. require_once 'Zend/Pdf/Element/Numeric.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Pdf
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Pdf
  33. */
  34. class Zend_Pdf_Element_ObjectTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function testPDFObject()
  37. {
  38. $intObj = new Zend_Pdf_Element_Numeric(100);
  39. $obj = new Zend_Pdf_Element_Object($intObj, 1, 0, new Zend_Pdf_ElementFactory(1));
  40. $this->assertTrue($obj instanceof Zend_Pdf_Element_Object);
  41. }
  42. public function testPDFObjectBadObjectType1()
  43. {
  44. $intObj = new Zend_Pdf_Element_Numeric(100);
  45. $obj1 = new Zend_Pdf_Element_Object($intObj, 1, 0, new Zend_Pdf_ElementFactory(1));
  46. try {
  47. $obj2 = new Zend_Pdf_Element_Object($obj1, 1, 0, new Zend_Pdf_ElementFactory(1));
  48. } catch (Zend_Pdf_Exception $e) {
  49. $this->assertRegExp('/must not be an instance of Zend_Pdf_Element_Object/i', $e->getMessage());
  50. return;
  51. }
  52. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  53. }
  54. public function testPDFObjectBadGenNumber1()
  55. {
  56. try {
  57. $intObj = new Zend_Pdf_Element_Numeric(100);
  58. $obj = new Zend_Pdf_Element_Object($intObj, 1, -1, new Zend_Pdf_ElementFactory(1));
  59. } catch (Zend_Pdf_Exception $e) {
  60. $this->assertRegExp('/non-negative integer/i', $e->getMessage());
  61. return;
  62. }
  63. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  64. }
  65. public function testPDFObjectBadGenNumber2()
  66. {
  67. try {
  68. $intObj = new Zend_Pdf_Element_Numeric(100);
  69. $obj = new Zend_Pdf_Element_Object($intObj, 1, 1.2, new Zend_Pdf_ElementFactory(1));
  70. } catch (Zend_Pdf_Exception $e) {
  71. $this->assertRegExp('/non-negative integer/i', $e->getMessage());
  72. return;
  73. }
  74. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  75. }
  76. public function testPDFObjectBadObjectNumber1()
  77. {
  78. try {
  79. $intObj = new Zend_Pdf_Element_Numeric(100);
  80. $obj = new Zend_Pdf_Element_Object($intObj, 0, 0, new Zend_Pdf_ElementFactory(1));
  81. } catch (Zend_Pdf_Exception $e) {
  82. $this->assertRegExp('/positive integer/i', $e->getMessage());
  83. return;
  84. }
  85. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  86. }
  87. public function testPDFObjectBadObjectNumber2()
  88. {
  89. try {
  90. $intObj = new Zend_Pdf_Element_Numeric(100);
  91. $obj = new Zend_Pdf_Element_Object($intObj, -1, 0, new Zend_Pdf_ElementFactory(1));
  92. } catch (Zend_Pdf_Exception $e) {
  93. $this->assertRegExp('/positive integer/i', $e->getMessage());
  94. return;
  95. }
  96. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  97. }
  98. public function testPDFObjectBadObjectNumber3()
  99. {
  100. try {
  101. $intObj = new Zend_Pdf_Element_Numeric(100);
  102. $obj = new Zend_Pdf_Element_Object($intObj, 1.2, 0, new Zend_Pdf_ElementFactory(1));
  103. } catch (Zend_Pdf_Exception $e) {
  104. $this->assertRegExp('/positive integer/i', $e->getMessage());
  105. return;
  106. }
  107. $this->fail('Expected Zend_Pdf_Exception to be thrown');
  108. }
  109. public function testGetType()
  110. {
  111. $intObj = new Zend_Pdf_Element_Numeric(100);
  112. $obj = new Zend_Pdf_Element_Object($intObj, 1, 0, new Zend_Pdf_ElementFactory(1));
  113. $this->assertEquals($obj->getType(), $intObj->getType());
  114. }
  115. public function testToString()
  116. {
  117. $intObj = new Zend_Pdf_Element_Numeric(100);
  118. $obj = new Zend_Pdf_Element_Object($intObj, 55, 3, new Zend_Pdf_ElementFactory(1));
  119. $this->assertEquals($obj->toString(), '55 3 R');
  120. }
  121. public function testDump()
  122. {
  123. $factory = new Zend_Pdf_ElementFactory(1);
  124. $intObj = new Zend_Pdf_Element_Numeric(100);
  125. $obj = new Zend_Pdf_Element_Object($intObj, 55, 3, $factory);
  126. $this->assertEquals($obj->dump($factory), "55 3 obj \n100\nendobj\n");
  127. }
  128. }