table_column_width_test.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * ezcDocumentPdfDriverHaruTests
  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. /**
  29. * Test suite for class.
  30. *
  31. * @package Document
  32. * @subpackage Tests
  33. */
  34. class ezcDocumentPdfTableColumnWidthCalculatorTests extends ezcTestCase
  35. {
  36. public static function suite()
  37. {
  38. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  39. }
  40. public static function getTableColumnWidths()
  41. {
  42. return array(
  43. array(
  44. 'simple_tables.xml',
  45. '//doc:table[1]',
  46. array( .314, .314, .372 ),
  47. ),
  48. array(
  49. 'simple_tables.xml',
  50. '//doc:table[2]',
  51. array( .317, .317, .366 ),
  52. ),
  53. array(
  54. 'tables_with_list.xml',
  55. '//doc:table[1]',
  56. array( .377, .623 ),
  57. ),
  58. array(
  59. 'stacked_table.xml',
  60. '//doc:table[1]',
  61. array( .236, .236, .528 ),
  62. ),
  63. array(
  64. 'irregular_tables_1.xml',
  65. '//doc:table[1]',
  66. array( .129, .871 ),
  67. ),
  68. array(
  69. 'irregular_tables_2.xml',
  70. '//doc:table[1]',
  71. array( .5, .5 ),
  72. ),
  73. );
  74. }
  75. /**
  76. * @dataProvider getTableColumnWidths
  77. */
  78. public function testTableColumnWidthEstimation( $file, $query, $expectation )
  79. {
  80. $doc = new DOMDocument();
  81. $doc->load( dirname( __FILE__ ) . '/../files/pdf/' . $file );
  82. $xpath = new DOMXPath( $doc );
  83. $xpath->registerNamespace( 'doc', 'http://docbook.org/ns/docbook' );
  84. $table = $xpath->query( $query )->item( 0 );
  85. $calculator = new ezcDocumentPdfDefaultTableColumnWidthCalculator();
  86. $this->assertEquals(
  87. $expectation,
  88. $calculator->estimateWidths( $table ),
  89. 'Wrong table width estimations',
  90. .001
  91. );
  92. }
  93. }
  94. ?>