image_handler.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 ezcDocumentPdfImageHandlerTests 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 testImageHandler()
  44. {
  45. $image = ezcDocumentPdfImage::createFromFile( dirname( __FILE__ ) . '/../files/pdf/images/logo-white.png' );
  46. $this->assertSame(
  47. 'image/png',
  48. $image->getMimeType()
  49. );
  50. $this->assertEquals(
  51. array( new ezcDocumentPcssMeasure( '113px' ), new ezcDocumentPcssMeasure( '57px' ) ),
  52. $image->getDimensions()
  53. );
  54. }
  55. public static function provideCanHandleData()
  56. {
  57. return array(
  58. array( 'files/pdf/images/logo-white.eps', false ),
  59. array( 'files/pdf/images/logo-white.pdf', false ),
  60. array( 'files/pdf/images/logo-white.png', true ),
  61. array( 'files/pdf/images/logo-white.svg', false ),
  62. array( 'files/pdf/images/logo-white.jpeg', true ),
  63. );
  64. }
  65. /**
  66. * @dataProvider provideCanHandleData
  67. */
  68. public function testCanHandleImageType( $image, $return )
  69. {
  70. $handler = new ezcDocumentPdfPhpImageHandler();
  71. $this->assertSame( $return, $handler->canHandle( dirname( __FILE__ ) . '/../' . $image ) );
  72. }
  73. public static function provideDimensionData()
  74. {
  75. return array(
  76. array( 'files/pdf/images/logo-white.eps', false ),
  77. array( 'files/pdf/images/logo-white.pdf', false ),
  78. array( 'files/pdf/images/logo-white.png', array( new ezcDocumentPcssMeasure( '113px' ), new ezcDocumentPcssMeasure( '57px' ) ) ),
  79. array( 'files/pdf/images/logo-white.svg', false ),
  80. array( 'files/pdf/images/logo-white.png', array( new ezcDocumentPcssMeasure( '113px' ), new ezcDocumentPcssMeasure( '57px' ) ) ),
  81. );
  82. }
  83. /**
  84. * @dataProvider provideDimensionData
  85. */
  86. public function testImageDimensions( $image, $return )
  87. {
  88. $handler = new ezcDocumentPdfPhpImageHandler();
  89. $this->assertEquals( $return, $handler->getDimensions( dirname( __FILE__ ) . '/../' . $image ) );
  90. }
  91. public static function provideMimeTypeData()
  92. {
  93. return array(
  94. array( 'files/pdf/images/logo-white.eps', false ),
  95. array( 'files/pdf/images/logo-white.pdf', false ),
  96. array( 'files/pdf/images/logo-white.png', 'image/png' ),
  97. array( 'files/pdf/images/logo-white.svg', false ),
  98. array( 'files/pdf/images/logo-white.jpeg', 'image/jpeg' ),
  99. );
  100. }
  101. /**
  102. * @dataProvider provideMimeTypeData
  103. */
  104. public function testImageMimeType( $image, $return )
  105. {
  106. $handler = new ezcDocumentPdfPhpImageHandler();
  107. $this->assertSame( $return, $handler->getMimeType( dirname( __FILE__ ) . '/../' . $image ) );
  108. }
  109. }
  110. ?>