NamedDestinationsTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @package Zend_Pdf
  4. * @subpackage UnitTests
  5. */
  6. /** Zend_Pdf */
  7. require_once 'Zend/Pdf.php';
  8. /** PHPUnit Test Case */
  9. require_once 'PHPUnit/Framework/TestCase.php';
  10. /**
  11. * @package Zend_Pdf
  12. * @subpackage UnitTests
  13. */
  14. class Zend_Pdf_NamedDestinationsTest extends PHPUnit_Framework_TestCase
  15. {
  16. public function setUp()
  17. {
  18. date_default_timezone_set('GMT');
  19. }
  20. public function testProcessing()
  21. {
  22. $pdf = new Zend_Pdf();
  23. $page1 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
  24. $page2 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
  25. $page3 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); // not actually included into pages array
  26. $pdf->pages[] = $page1;
  27. $pdf->pages[] = $page2;
  28. $this->assertTrue(count($pdf->getNamedDestinations()) == 0);
  29. require_once 'Zend/Pdf/Destination/Fit.php';
  30. $destination1 = Zend_Pdf_Destination_Fit::create($page1);
  31. $destination2 = Zend_Pdf_Destination_Fit::create($page2);
  32. $action1 = Zend_Pdf_Action_GoTo::create($destination1);
  33. $pdf->setNamedDestination('GoToPage1', $action1);
  34. $this->assertTrue($pdf->getNamedDestination('GoToPage1') === $action1);
  35. $this->assertTrue($pdf->getNamedDestination('GoToPage9') === null);
  36. $pdf->setNamedDestination('Page2', $destination2);
  37. $this->assertTrue($pdf->getNamedDestination('Page2') === $destination2);
  38. $this->assertTrue($pdf->getNamedDestination('Page9') === null);
  39. $pdf->setNamedDestination('Page1', $destination1);
  40. $pdf->setNamedDestination('Page1_1', Zend_Pdf_Destination_Fit::create(1));
  41. $pdf->setNamedDestination('Page9_1', Zend_Pdf_Destination_Fit::create(9)); // will be egnored
  42. $action3 = Zend_Pdf_Action_GoTo::create(Zend_Pdf_Destination_Fit::create($page3));
  43. $pdf->setNamedDestination('GoToPage3', $action3);
  44. $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);
  45. }
  46. }