NamedDestinationsTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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-2009 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 */
  23. require_once 'Zend/Pdf.php';
  24. /** PHPUnit Test Case */
  25. require_once 'PHPUnit/Framework/TestCase.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Pdf
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2009 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_NamedDestinationsTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function setUp()
  37. {
  38. date_default_timezone_set('GMT');
  39. }
  40. public function testProcessing()
  41. {
  42. $pdf = new Zend_Pdf();
  43. $page1 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
  44. $page2 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
  45. $page3 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); // not actually included into pages array
  46. $pdf->pages[] = $page1;
  47. $pdf->pages[] = $page2;
  48. $this->assertTrue(count($pdf->getNamedDestinations()) == 0);
  49. require_once 'Zend/Pdf/Destination/Fit.php';
  50. $destination1 = Zend_Pdf_Destination_Fit::create($page1);
  51. $destination2 = Zend_Pdf_Destination_Fit::create($page2);
  52. $action1 = Zend_Pdf_Action_GoTo::create($destination1);
  53. $pdf->setNamedDestination('GoToPage1', $action1);
  54. $this->assertTrue($pdf->getNamedDestination('GoToPage1') === $action1);
  55. $this->assertTrue($pdf->getNamedDestination('GoToPage9') === null);
  56. $pdf->setNamedDestination('Page2', $destination2);
  57. $this->assertTrue($pdf->getNamedDestination('Page2') === $destination2);
  58. $this->assertTrue($pdf->getNamedDestination('Page9') === null);
  59. $pdf->setNamedDestination('Page1', $destination1);
  60. $pdf->setNamedDestination('Page1_1', Zend_Pdf_Destination_Fit::create(1));
  61. $pdf->setNamedDestination('Page9_1', Zend_Pdf_Destination_Fit::create(9)); // will be egnored
  62. $action3 = Zend_Pdf_Action_GoTo::create(Zend_Pdf_Destination_Fit::create($page3));
  63. $pdf->setNamedDestination('GoToPage3', $action3);
  64. $this->assertTrue(strpos($pdf->render(), '[(GoToPage1) <</Type /Action /S /GoTo /D [3 0 R /Fit ] >> (Page1) [3 0 R /Fit ] (Page1_1) [1 /Fit ] (Page2) [4 0 R /Fit ] ]') !== false);
  65. }
  66. }