/foody.blogtamsudev.vn/vendor/bestmomo/filemanager/public/filemanager/connectors/php/inc/wideimage/test/tests/ImageTest.php

https://gitlab.com/ntphuc/BackendFeedy · PHP · 190 lines · 131 code · 28 blank · 31 comment · 2 complexity · 9509dc8361350ea59d7a089cc29d0fdc MD5 · raw file

  1. <?php
  2. /**
  3. This file is part of WideImage.
  4. WideImage is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. WideImage is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with WideImage; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. * @package Tests
  16. **/
  17. /**
  18. * @package Tests
  19. */
  20. class WideImage_Operation_CustomOp
  21. {
  22. static public $args = null;
  23. function execute()
  24. {
  25. self::$args = func_get_args();
  26. return self::$args[0]->copy();
  27. }
  28. }
  29. /**
  30. * @package Tests
  31. */
  32. class ImageForOutput extends WideImage_TrueColorImage
  33. {
  34. public $headers = array();
  35. function writeHeader($name, $data)
  36. {
  37. $this->headers[$name] = $data;
  38. }
  39. }
  40. /**
  41. * @package Tests
  42. */
  43. class TestableImage extends WideImage_TrueColorImage
  44. {
  45. public $headers = array();
  46. function __destruct()
  47. {
  48. }
  49. function writeHeader($name, $data)
  50. {
  51. $this->headers[$name] = $data;
  52. }
  53. }
  54. /**
  55. * @package Tests
  56. */
  57. class WideImage_Image_Test extends WideImage_TestCase
  58. {
  59. function testFactories()
  60. {
  61. $this->assertTrue(WideImage::createTrueColorImage(100, 100) instanceof WideImage_TrueColorImage);
  62. $this->assertTrue(WideImage::createPaletteImage(100, 100) instanceof WideImage_PaletteImage);
  63. }
  64. function testDestructorUponUnset()
  65. {
  66. $img = $this->getMock('WideImage_TrueColorImage', array(), array(imagecreatetruecolor(10, 10)));
  67. $img->expectOnce('destroy');
  68. unset($img);
  69. $img = null;
  70. for ($i = 0; $i++; $i < 1000);
  71. }
  72. function testDestructorUponNull()
  73. {
  74. $img = $this->getMock('WideImage_TrueColorImage', array(), array(imagecreatetruecolor(10, 10)));
  75. $img->expectOnce('destroy');
  76. $img = null;
  77. for ($i = 0; $i++; $i < 1000);
  78. }
  79. function testAutoDestruct()
  80. {
  81. $img = WideImage_TrueColorImage::create(10, 10);
  82. $handle = $img->getHandle();
  83. unset($img);
  84. $this->assertFalse(WideImage::isValidImageHandle($handle));
  85. }
  86. function testAutoDestructWithRelease()
  87. {
  88. $img = WideImage_TrueColorImage::create(10, 10);
  89. $handle = $img->getHandle();
  90. $img->releaseHandle();
  91. unset($img);
  92. $this->assertTrue(WideImage::isValidImageHandle($handle));
  93. imagedestroy($handle);
  94. }
  95. function testCustomOpMagic()
  96. {
  97. $img = WideImage_TrueColorImage::create(10, 10);
  98. $result = $img->customOp(123, 'abc');
  99. $this->assertTrue($result instanceof WideImage_Image);
  100. $this->assertSame(WideImage_Operation_CustomOp::$args[0], $img);
  101. $this->assertSame(WideImage_Operation_CustomOp::$args[1], 123);
  102. $this->assertSame(WideImage_Operation_CustomOp::$args[2], 'abc');
  103. }
  104. function testCustomOpCaseInsensitive()
  105. {
  106. $img = WideImage_TrueColorImage::create(10, 10);
  107. $result = $img->CUSTomOP(123, 'abc');
  108. $this->assertTrue($result instanceof WideImage_Image);
  109. $this->assertSame(WideImage_Operation_CustomOp::$args[0], $img);
  110. $this->assertSame(WideImage_Operation_CustomOp::$args[1], 123);
  111. $this->assertSame(WideImage_Operation_CustomOp::$args[2], 'abc');
  112. }
  113. function testInternalOpCaseInsensitive()
  114. {
  115. $img = WideImage_TrueColorImage::create(10, 10);
  116. $result = $img->AUTOcrop();
  117. $this->assertTrue($result instanceof WideImage_Image);
  118. }
  119. function testOutput()
  120. {
  121. $tmp = WideImage::load(IMG_PATH . 'fgnl.jpg');
  122. $img = new ImageForOutput($tmp->getHandle());
  123. ob_start();
  124. $img->output('png');
  125. $data = ob_get_clean();
  126. $this->assertEquals(array('Content-length' => strlen($data), 'Content-type' => 'image/png'), $img->headers);
  127. }
  128. function testCanvasInstance()
  129. {
  130. $img = WideImage::load(IMG_PATH . 'fgnl.jpg');
  131. $canvas1 = $img->getCanvas();
  132. $this->assertTrue($canvas1 instanceof WideImage_Canvas);
  133. $canvas2 = $img->getCanvas();
  134. $this->assertTrue($canvas1 === $canvas2);
  135. }
  136. function testSerializeTrueColorImage()
  137. {
  138. $img = WideImage::load(IMG_PATH . 'fgnl.jpg');
  139. $img2 = unserialize(serialize($img));
  140. $this->assertEquals(get_class($img2), get_class($img));
  141. $this->assertTrue($img2->isTrueColor());
  142. $this->assertTrue($img2->isValid());
  143. $this->assertFalse($img2->isTransparent());
  144. $this->assertEquals($img->getWidth(), $img2->getWidth());
  145. $this->assertEquals($img->getHeight(), $img2->getHeight());
  146. }
  147. function testSerializePaletteImage()
  148. {
  149. $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
  150. $img2 = unserialize(serialize($img));
  151. $this->assertEquals(get_class($img2), get_class($img));
  152. $this->assertFalse($img2->isTrueColor());
  153. $this->assertTrue($img2->isValid());
  154. $this->assertTrue($img2->isTransparent());
  155. $this->assertEquals($img->getWidth(), $img2->getWidth());
  156. $this->assertEquals($img->getHeight(), $img2->getHeight());
  157. }
  158. }