measure_test.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 dirname( __FILE__ ) . '/../helper/pdf_mocked_driver.php';
  28. /**
  29. * Test suite for class.
  30. *
  31. * @package Document
  32. * @subpackage Tests
  33. */
  34. class ezcDocumentPcssMeasureTests extends ezcTestCase
  35. {
  36. public static function suite()
  37. {
  38. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  39. }
  40. public static function getUnitConversions()
  41. {
  42. return array(
  43. array( '10', 'mm', 10 ),
  44. array( '10mm', 'mm', 10 ),
  45. array( 10, 'mm', 10 ),
  46. array( .1, 'mm', .1 ),
  47. array( '.1in', 'mm', 2.54 ),
  48. array( '10pt', 'mm', 3.53 ),
  49. array( '10px', 'mm', 3.53 ),
  50. array( '10px', 'px', 10 ),
  51. array( '10px', 'pt', 10 ),
  52. array( '10pt', 'px', 10 ),
  53. array( '10', 'pt', 28.35 ),
  54. array( '10', 'px', 28.35 ),
  55. array( '10', 'in', .39 ),
  56. array( '-2.3pt', 'mm', -.81 ),
  57. array( '+2.3pt', 'mm', .81 ),
  58. );
  59. }
  60. /**
  61. * @dataProvider getUnitConversions
  62. */
  63. public function testValueConversion( $input, $unit, $expected )
  64. {
  65. $measure = new ezcDocumentPcssMeasure( $input );
  66. $this->assertEquals(
  67. $expected,
  68. $measure->get( $unit ),
  69. "Converting $input to $unit lead to unexpected result.",
  70. .1
  71. );
  72. }
  73. public function testUnparsableValue()
  74. {
  75. try {
  76. ezcDocumentPcssMeasure::create( '10 mm' )->get();
  77. $this->fail( 'Expected ezcDocumentParserException.' );
  78. }
  79. catch ( ezcDocumentParserException $e )
  80. { /* Expected */ }
  81. }
  82. public function testUnhandledUnit1()
  83. {
  84. $driver = new ezcTestDocumentPdfMockDriver();
  85. try {
  86. ezcDocumentPcssMeasure::create( '10foo' )->get();
  87. $this->fail( 'Expected ezcDocumentParserException.' );
  88. }
  89. catch ( ezcDocumentParserException $e )
  90. { /* Expected */ }
  91. }
  92. public function testUnhandledUnit2()
  93. {
  94. $driver = new ezcTestDocumentPdfMockDriver();
  95. try {
  96. ezcDocumentPcssMeasure::create( '10mm' )->get( 'foo' );
  97. $this->fail( 'Expected ezcDocumentParserException.' );
  98. }
  99. catch ( ezcDocumentParserException $e )
  100. { /* Expected */ }
  101. }
  102. }
  103. ?>