ObjectTest.php 5.0 KB

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