driver_tcpdf_tests.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 'driver_tests.php';
  28. // Try to include TCPDF class from external/tcpdf.
  29. // @TODO: Maybe also search the include path...
  30. if ( file_exists( $path = dirname( __FILE__ ) . '/../external/tcpdf-4.8/tcpdf.php' ) )
  31. {
  32. include $path;
  33. }
  34. /**
  35. * Test suite for class.
  36. *
  37. * @package Document
  38. * @subpackage Tests
  39. */
  40. class ezcDocumentPdfDriverTcpdfTests extends ezcDocumentPdfDriverTests
  41. {
  42. /**
  43. * Old error reporting level restored after the test
  44. *
  45. * @var int
  46. */
  47. protected $oldErrorReporting;
  48. /**
  49. * Name of the driver class to test
  50. *
  51. * @var string
  52. */
  53. protected $driverClass = 'ezcDocumentPdfTcpdfDriver';
  54. /**
  55. * Expected font widths for calculateWordWidth tests
  56. *
  57. * @var array
  58. */
  59. protected $expectedWidths = array(
  60. 'testEstimateDefaultWordWidthWithoutPageCreation' => 9.6,
  61. 'testEstimateDefaultWordWidth' => 9.6,
  62. 'testEstimateWordWidthDifferentSize' => 31.9,
  63. 'testEstimateWordWidthDifferentSizeAndUnit' => 11.3,
  64. 'testEstimateBoldWordWidth' => 10.4,
  65. 'testEstimateMonospaceWordWidth' => 36,
  66. 'testFontStyleFallback' => 16.3,
  67. 'testUtf8FontWidth' => 11.8,
  68. 'testCustomFontWidthEstimation' => null,
  69. );
  70. public static function suite()
  71. {
  72. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  73. }
  74. public function setUp()
  75. {
  76. parent::setUp();
  77. // Change error reporting - this is evil, but otherwise TCPDF will
  78. // abort the tests, because it throws lots of E_NOTICE and
  79. // E_DEPRECATED.
  80. $this->oldErrorReporting = error_reporting( E_PARSE | E_ERROR | E_WARNING );
  81. }
  82. public function tearDown()
  83. {
  84. error_reporting( $this->oldErrorReporting );
  85. parent::tearDown();
  86. }
  87. /**
  88. * Get driver to test
  89. *
  90. * @return ezcDocumentPdfDriver
  91. */
  92. protected function getDriver()
  93. {
  94. if ( !class_exists( 'TCPDF' ) )
  95. {
  96. $this->markTestSkipped( 'This test requires the TCPDF class.' );
  97. }
  98. return new ezcDocumentPdfTcpdfDriver();
  99. }
  100. }
  101. ?>