renderer_main_tests.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 ezcDocumentPdfMainRendererTests extends ezcDocumentPdfTestCase
  35. {
  36. protected $document;
  37. protected $xpath;
  38. protected $styles;
  39. public static function suite()
  40. {
  41. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  42. }
  43. public function testRenderUnknownElements()
  44. {
  45. $docbook = new ezcDocumentDocbook();
  46. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/unknown.xml' );
  47. try {
  48. $renderer = new ezcDocumentPdfMainRenderer(
  49. new ezcDocumentPdfSvgDriver(),
  50. new ezcDocumentPcssStyleInferencer()
  51. );
  52. $pdf = $renderer->render(
  53. $docbook,
  54. new ezcDocumentPdfDefaultHyphenator()
  55. );
  56. $this->fail( 'Expected ezcDocumentVisitException.' );
  57. }
  58. catch ( ezcDocumentVisitException $e )
  59. { /* Expected */ }
  60. }
  61. public function testRenderUnknownElementsSilence()
  62. {
  63. $docbook = new ezcDocumentDocbook();
  64. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/unknown.xml' );
  65. $options = new ezcDocumentPdfOptions();
  66. $options->errorReporting = E_PARSE;
  67. $renderer = new ezcDocumentPdfMainRenderer(
  68. new ezcDocumentPdfSvgDriver(),
  69. new ezcDocumentPcssStyleInferencer(),
  70. $options
  71. );
  72. $pdf = $renderer->render(
  73. $docbook,
  74. new ezcDocumentPdfDefaultHyphenator()
  75. );
  76. $errors = $renderer->getErrors();
  77. $this->assertEquals( 1, count( $errors ) );
  78. $this->assertEquals(
  79. 'Visitor error: Notice: \'Unknown and unhandled element: http://example.org/unknown:article.\' in line 0 at position 0.',
  80. reset( $errors )->getMessage()
  81. );
  82. }
  83. public function testRenderMainSinglePage()
  84. {
  85. $this->renderFullDocument(
  86. dirname( __FILE__ ) . '/../files/pdf/long_text.xml',
  87. __CLASS__ . '_' . __FUNCTION__ . '.svg',
  88. array()
  89. );
  90. }
  91. public function testRenderMainSinglePageNotNamespaced()
  92. {
  93. $this->renderFullDocument(
  94. dirname( __FILE__ ) . '/../files/pdf/paragraph_nons.xml',
  95. __CLASS__ . '_' . __FUNCTION__ . '.svg',
  96. array()
  97. );
  98. }
  99. public function testRenderMainMulticolumnLayout()
  100. {
  101. $this->renderFullDocument(
  102. dirname( __FILE__ ) . '/../files/pdf/long_text.xml',
  103. __CLASS__ . '_' . __FUNCTION__ . '.svg',
  104. array(
  105. new ezcDocumentPcssLayoutDirective(
  106. array( 'article' ),
  107. array(
  108. 'text-columns' => '3',
  109. 'line-height' => '1',
  110. )
  111. ),
  112. )
  113. );
  114. }
  115. public function testRenderLongTextParagraphConflict()
  116. {
  117. $this->renderFullDocument(
  118. dirname( __FILE__ ) . '/../files/pdf/test_long_wrapping.xml',
  119. __CLASS__ . '_' . __FUNCTION__ . '.svg',
  120. array()
  121. );
  122. }
  123. public function testRenderLongTextWithInternalLinks()
  124. {
  125. if ( !ezcBaseFeatures::hasExtensionSupport( 'haru' ) )
  126. {
  127. $this->markTestSkipped( 'This test requires pecl/haru installed.' );
  128. }
  129. $docbook = new ezcDocumentDocbook();
  130. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/internal_links.xml' );
  131. $style = new ezcDocumentPcssStyleInferencer();
  132. $style->appendStyleDirectives( array(
  133. new ezcDocumentPcssLayoutDirective(
  134. array( 'page' ),
  135. array(
  136. 'page-size' => 'A6',
  137. )
  138. ),
  139. ) );
  140. $renderer = new ezcDocumentPdfMainRenderer(
  141. new ezcDocumentPdfHaruDriver(),
  142. $style
  143. );
  144. $pdf = $renderer->render(
  145. $docbook,
  146. new ezcDocumentPdfDefaultHyphenator()
  147. );
  148. $this->assertPdfDocumentsSimilar( $pdf, __CLASS__ . '_' . __FUNCTION__ );
  149. }
  150. public function testRenderUnavailableCustomFont()
  151. {
  152. $docbook = new ezcDocumentDocbook();
  153. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/wrapping.xml' );
  154. $style = new ezcDocumentPcssStyleInferencer();
  155. $style->appendStyleDirectives( array(
  156. new ezcDocumentPcssLayoutDirective(
  157. array( 'article' ),
  158. array(
  159. 'font-family' => 'my-font',
  160. )
  161. ),
  162. ) );
  163. $renderer = new ezcDocumentPdfMainRenderer(
  164. new ezcDocumentPdfSvgDriver(),
  165. $style
  166. );
  167. $pdf = $renderer->render(
  168. $docbook,
  169. new ezcDocumentPdfDefaultHyphenator()
  170. );
  171. $this->assertPdfDocumentsSimilar( $pdf, __CLASS__ . '_' . __FUNCTION__ );
  172. }
  173. public function testRenderCustomFont()
  174. {
  175. $docbook = new ezcDocumentDocbook();
  176. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/wrapping.xml' );
  177. $style = new ezcDocumentPcssStyleInferencer();
  178. $style->appendStyleDirectives( array(
  179. new ezcDocumentPcssLayoutDirective(
  180. array( 'article' ),
  181. array(
  182. 'font-family' => 'my-font',
  183. )
  184. ),
  185. new ezcDocumentPcssDeclarationDirective(
  186. '@font-face',
  187. array(
  188. 'font-family' => 'my-font',
  189. 'src' => 'url( ' . dirname( __FILE__ ) . '/../files/fonts/font.ttf )',
  190. )
  191. ),
  192. ) );
  193. $renderer = new ezcDocumentPdfMainRenderer(
  194. new ezcDocumentPdfSvgDriver(),
  195. $style
  196. );
  197. $pdf = $renderer->render(
  198. $docbook,
  199. new ezcDocumentPdfDefaultHyphenator()
  200. );
  201. $this->assertPdfDocumentsSimilar( $pdf, __CLASS__ . '_' . __FUNCTION__ );
  202. }
  203. }
  204. ?>