NamedDestinationsTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 */
  23. require_once 'Zend/Pdf.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Pdf
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Pdf
  31. */
  32. class Zend_Pdf_NamedDestinationsTest extends PHPUnit_Framework_TestCase
  33. {
  34. public function setUp()
  35. {
  36. date_default_timezone_set('GMT');
  37. }
  38. public function testProcessing()
  39. {
  40. $pdf = new Zend_Pdf();
  41. $page1 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
  42. $page2 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
  43. $page3 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); // not actually included into pages array
  44. $pdf->pages[] = $page1;
  45. $pdf->pages[] = $page2;
  46. $this->assertTrue(count($pdf->getNamedDestinations()) == 0);
  47. require_once 'Zend/Pdf/Destination/Fit.php';
  48. $destination1 = Zend_Pdf_Destination_Fit::create($page1);
  49. $destination2 = Zend_Pdf_Destination_Fit::create($page2);
  50. $action1 = Zend_Pdf_Action_GoTo::create($destination1);
  51. $pdf->setNamedDestination('GoToPage1', $action1);
  52. $this->assertTrue($pdf->getNamedDestination('GoToPage1') === $action1);
  53. $this->assertTrue($pdf->getNamedDestination('GoToPage9') === null);
  54. $pdf->setNamedDestination('Page2', $destination2);
  55. $this->assertTrue($pdf->getNamedDestination('Page2') === $destination2);
  56. $this->assertTrue($pdf->getNamedDestination('Page9') === null);
  57. $pdf->setNamedDestination('Page1', $destination1);
  58. $pdf->setNamedDestination('Page1_1', Zend_Pdf_Destination_Fit::create(1));
  59. $pdf->setNamedDestination('Page9_1', Zend_Pdf_Destination_Fit::create(9)); // will be egnored
  60. $action3 = Zend_Pdf_Action_GoTo::create(Zend_Pdf_Destination_Fit::create($page3));
  61. $pdf->setNamedDestination('GoToPage3', $action3);
  62. $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);
  63. }
  64. }