tests.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * ezcDocumentPdfDriverTcpdfTests
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Document
  23. * @version //autogen//
  24. * @subpackage Tests
  25. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  26. */
  27. require_once 'base.php';
  28. /**
  29. * Test suite for class.
  30. *
  31. * @package Document
  32. * @subpackage Tests
  33. */
  34. class ezcDocumentPdfTests extends ezcDocumentPdfTestCase
  35. {
  36. public static function suite()
  37. {
  38. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  39. }
  40. public function testRenderUnknownElements()
  41. {
  42. $docbook = new ezcDocumentDocbook();
  43. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/unknown.xml' );
  44. try {
  45. $pdfDoc = new ezcDocumentPdf( new ezcDocumentPdfOptions( array(
  46. 'driver' => new ezcDocumentPdfSvgDriver(),
  47. ) ) );
  48. $pdfDoc->createFromDocbook( $docbook );
  49. $this->fail( 'Expected ezcDocumentVisitException.' );
  50. }
  51. catch ( ezcDocumentVisitException $e )
  52. { /* Expected */ }
  53. }
  54. public function testRenderUnknownElementsSilence()
  55. {
  56. $docbook = new ezcDocumentDocbook();
  57. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/unknown.xml' );
  58. $pdfDoc = new ezcDocumentPdf( new ezcDocumentPdfOptions( array(
  59. 'driver' => new ezcDocumentPdfSvgDriver(),
  60. 'errorReporting' => E_PARSE,
  61. ) ) );
  62. $pdfDoc->createFromDocbook( $docbook );
  63. $errors = $pdfDoc->getErrors();
  64. $this->assertEquals( 2, count( $errors ) );
  65. $this->assertEquals(
  66. 'Visitor error: Notice: \'Unknown and unhandled element: http://example.org/unknown:article.\' in line 0 at position 0.',
  67. end( $errors )->getMessage()
  68. );
  69. }
  70. public function testRenderDefault()
  71. {
  72. $docbook = new ezcDocumentDocbook();
  73. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/long_text.xml' );
  74. $pdfDoc = new ezcDocumentPdf( new ezcDocumentPdfOptions( array(
  75. 'driver' => new ezcDocumentPdfSvgDriver(),
  76. ) ) );
  77. $pdfDoc->createFromDocbook( $docbook );
  78. $pdf = (string) $pdfDoc;
  79. file_put_contents(
  80. $this->tempDir . ( $fileName = __CLASS__ . '_' . __FUNCTION__ . '.svg' ),
  81. $pdf
  82. );
  83. $this->assertXmlFileEqualsXmlFile(
  84. $this->basePath . 'renderer/' . $fileName,
  85. $this->tempDir . $fileName
  86. );
  87. }
  88. public function testRenderCustomStyle()
  89. {
  90. $docbook = new ezcDocumentDocbook();
  91. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/long_text.xml' );
  92. $pdfDoc = new ezcDocumentPdf( new ezcDocumentPdfOptions( array(
  93. 'driver' => new ezcDocumentPdfSvgDriver(),
  94. ) ) );
  95. $pdfDoc->loadStyles( dirname( __FILE__ ) . '/../files/pdf/custom.css' );
  96. $pdfDoc->createFromDocbook( $docbook );
  97. $pdf = (string) $pdfDoc;
  98. file_put_contents(
  99. $this->tempDir . ( $fileName = __CLASS__ . '_' . __FUNCTION__ . '.svg' ),
  100. $pdf
  101. );
  102. $this->assertXmlFileEqualsXmlFile(
  103. $this->basePath . 'renderer/' . $fileName,
  104. $this->tempDir . $fileName
  105. );
  106. }
  107. public function testRenderCustomStyleAndAdditionalPdfParts()
  108. {
  109. $docbook = new ezcDocumentDocbook();
  110. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/long_text.xml' );
  111. $pdfDoc = new ezcDocumentPdf( new ezcDocumentPdfOptions( array(
  112. 'driver' => new ezcDocumentPdfSvgDriver(),
  113. ) ) );
  114. $pdfDoc->loadStyles( dirname( __FILE__ ) . '/../files/pdf/custom.css' );
  115. $pdfDoc->registerPdfPart( new ezcDocumentPdfHeaderPdfPart() );
  116. $pdfDoc->createFromDocbook( $docbook );
  117. $pdf = (string) $pdfDoc;
  118. file_put_contents(
  119. $this->tempDir . ( $fileName = __CLASS__ . '_' . __FUNCTION__ . '.svg' ),
  120. $pdf
  121. );
  122. $this->assertXmlFileEqualsXmlFile(
  123. $this->basePath . 'renderer/' . $fileName,
  124. $this->tempDir . $fileName
  125. );
  126. }
  127. }
  128. ?>