InterfaceTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Image\Adapter;
  7. /**
  8. * @magentoAppIsolation enabled
  9. */
  10. class InterfaceTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * Adapter classes for test
  14. *
  15. * @var array
  16. */
  17. protected $_adapters = [
  18. \Magento\Framework\Image\Adapter\AdapterInterface::ADAPTER_GD2,
  19. \Magento\Framework\Image\Adapter\AdapterInterface::ADAPTER_IM,
  20. ];
  21. /**
  22. * Add adapters to each data provider case
  23. *
  24. * @param array $data
  25. * @return array
  26. */
  27. protected function _prepareData($data)
  28. {
  29. $result = [];
  30. foreach ($this->_adapters as $adapterType) {
  31. foreach ($data as $row) {
  32. $row[] = $adapterType;
  33. $result[] = $row;
  34. }
  35. }
  36. return $result;
  37. }
  38. /**
  39. * Returns fixture image size
  40. *
  41. * @return array
  42. */
  43. protected function _getFixtureImageSize()
  44. {
  45. return [311, 162];
  46. }
  47. /**
  48. * Compare two colors with some epsilon
  49. *
  50. * @param array $colorBefore
  51. * @param array $colorAfter
  52. * @return bool
  53. */
  54. protected function _compareColors($colorBefore, $colorAfter)
  55. {
  56. // get different epsilon for 8 bit (max value = 255) & 16 bit (max value = 65535) images (eps = 5%)
  57. $eps = max($colorAfter) > 255 ? 3500 : 20;
  58. $result = true;
  59. foreach ($colorAfter as $i => $v) {
  60. if (abs($colorBefore[$i] - $v) > $eps) {
  61. $result = false;
  62. break;
  63. }
  64. }
  65. return $result;
  66. }
  67. /**
  68. * Returns fixtures image path by pattern
  69. *
  70. * @param string $pattern
  71. * @return string|null
  72. */
  73. protected function _getFixture($pattern)
  74. {
  75. $dir = dirname(__DIR__) . '/_files/';
  76. $data = glob($dir . $pattern);
  77. if (!empty($data)) {
  78. return $data[0];
  79. }
  80. return null;
  81. }
  82. /**
  83. * Check is format supported.
  84. *
  85. * @param string $image
  86. * @param \Magento\Framework\Image\Adapter\AbstractAdapter $adapter
  87. * @return bool
  88. */
  89. protected function _isFormatSupported($image, $adapter)
  90. {
  91. $data = pathinfo($image);
  92. $supportedTypes = $adapter->getSupportedFormats();
  93. return $image && file_exists($image) && in_array(strtolower($data['extension']), $supportedTypes);
  94. }
  95. /**
  96. * Checks is adapter testable.
  97. * Mark test as skipped if not
  98. *
  99. * @param string $adapterType
  100. * @return \Magento\Framework\Image\Adapter\AdapterInterface
  101. */
  102. protected function _getAdapter($adapterType)
  103. {
  104. try {
  105. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  106. $adapter = $objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create($adapterType);
  107. return $adapter;
  108. } catch (\Exception $e) {
  109. $this->markTestSkipped($e->getMessage());
  110. }
  111. }
  112. /**
  113. * Checks if all dependencies are loaded
  114. * @param string $adapterType
  115. *
  116. * @dataProvider adaptersDataProvider
  117. */
  118. public function testCheckDependencies($adapterType)
  119. {
  120. $this->_getAdapter($adapterType);
  121. }
  122. public function adaptersDataProvider()
  123. {
  124. return [
  125. [\Magento\Framework\Image\Adapter\AdapterInterface::ADAPTER_GD2],
  126. [\Magento\Framework\Image\Adapter\AdapterInterface::ADAPTER_IM]
  127. ];
  128. }
  129. /**
  130. * @param string $image
  131. * @param string $adapterType
  132. *
  133. * @depends testCheckDependencies
  134. * @dataProvider openDataProvider
  135. */
  136. public function testOpen($image, $adapterType)
  137. {
  138. $adapter = $this->_getAdapter($adapterType);
  139. try {
  140. $adapter->open($image);
  141. } catch (\Exception $e) {
  142. $result = $this->_isFormatSupported($image, $adapter);
  143. $this->assertFalse($result);
  144. }
  145. }
  146. public function openDataProvider()
  147. {
  148. return $this->_prepareData(
  149. [
  150. [null],
  151. [$this->_getFixture('image_adapters_test.png')],
  152. [$this->_getFixture('image_adapters_test.tiff')],
  153. [$this->_getFixture('image_adapters_test.bmp')],
  154. ]
  155. );
  156. }
  157. /**
  158. * @param string $adapterType
  159. * @dataProvider adaptersDataProvider
  160. */
  161. public function testGetImage($adapterType)
  162. {
  163. $adapter = $this->_getAdapter($adapterType);
  164. $adapter->open($this->_getFixture('image_adapters_test.png'));
  165. $this->assertNotEmpty($adapter->getImage());
  166. }
  167. /**
  168. * @param string $image
  169. * @param string $adapterType
  170. *
  171. * @dataProvider openDataProvider
  172. * @depends testOpen
  173. */
  174. public function testImageSize($image, $adapterType)
  175. {
  176. $adapter = $this->_getAdapter($adapterType);
  177. try {
  178. $adapter->open($image);
  179. $this->assertEquals(
  180. $this->_getFixtureImageSize(),
  181. [$adapter->getOriginalWidth(), $adapter->getOriginalHeight()]
  182. );
  183. } catch (\Exception $e) {
  184. $result = $this->_isFormatSupported($image, $adapter);
  185. $this->assertFalse($result);
  186. }
  187. }
  188. /**
  189. * @param string $image
  190. * @param array $tempPath (dirName, newName)
  191. * @param string $adapterType
  192. *
  193. * @dataProvider saveDataProvider
  194. * @depends testOpen
  195. */
  196. public function testSave($image, $tempPath, $adapterType)
  197. {
  198. $adapter = $this->_getAdapter($adapterType);
  199. $adapter->open($image);
  200. try {
  201. call_user_func_array([$adapter, 'save'], $tempPath);
  202. $tempPath = join('', $tempPath);
  203. $this->assertFileExists($tempPath);
  204. unlink($tempPath);
  205. } catch (\Exception $e) {
  206. $this->assertFalse(is_dir($tempPath[0]) && is_writable($tempPath[0]));
  207. }
  208. }
  209. public function saveDataProvider()
  210. {
  211. $dir = \Magento\TestFramework\Helper\Bootstrap::getInstance()->getAppTempDir() . '/';
  212. return $this->_prepareData(
  213. [
  214. [$this->_getFixture('image_adapters_test.png'), [$dir . uniqid('test_image_adapter')]],
  215. [$this->_getFixture('image_adapters_test.png'), [$dir, uniqid('test_image_adapter')]],
  216. ]
  217. );
  218. }
  219. /**
  220. * @param string $image
  221. * @param array $dims (width, height)
  222. * @param string $adapterType
  223. *
  224. * @dataProvider resizeDataProvider
  225. * @depends testOpen
  226. */
  227. public function testResize($image, $dims, $adapterType)
  228. {
  229. $adapter = $this->_getAdapter($adapterType);
  230. $adapter->open($image);
  231. try {
  232. $adapter->resize($dims[0], $dims[1]);
  233. $this->assertEquals($dims, [$adapter->getOriginalWidth(), $adapter->getOriginalHeight()]);
  234. } catch (\Exception $e) {
  235. $result = $dims[0] !== null && $dims[0] <= 0 ||
  236. $dims[1] !== null && $dims[1] <= 0 ||
  237. empty(${$dims[0]}) && empty(${$dims[1]});
  238. $this->assertTrue($result);
  239. }
  240. }
  241. public function resizeDataProvider()
  242. {
  243. return $this->_prepareData(
  244. [
  245. [$this->_getFixture('image_adapters_test.png'), [150, 70]],
  246. [$this->_getFixture('image_adapters_test.png'), [null, 70]],
  247. [$this->_getFixture('image_adapters_test.png'), [100, null]],
  248. [$this->_getFixture('image_adapters_test.png'), [null, null]],
  249. [$this->_getFixture('image_adapters_test.png'), [-100, -50]],
  250. ]
  251. );
  252. }
  253. /**
  254. * @param string $image
  255. * @param int $angle
  256. * @param array $pixel
  257. * @param string $adapterType
  258. *
  259. * @dataProvider rotateDataProvider
  260. * @depends testOpen
  261. */
  262. public function testRotate($image, $angle, $pixel, $adapterType)
  263. {
  264. $adapter = $this->_getAdapter($adapterType);
  265. $adapter->open($image);
  266. $size = [$adapter->getOriginalWidth(), $adapter->getOriginalHeight()];
  267. $colorBefore = $adapter->getColorAt($pixel['x'], $pixel['y']);
  268. $adapter->rotate($angle);
  269. $newPixel = $this->_convertCoordinates(
  270. $pixel,
  271. $angle,
  272. $size,
  273. [$adapter->getOriginalWidth(), $adapter->getOriginalHeight()]
  274. );
  275. $colorAfter = $adapter->getColorAt($newPixel['x'], $newPixel['y']);
  276. $result = $this->_compareColors($colorBefore, $colorAfter);
  277. $this->assertTrue($result, join(',', $colorBefore) . ' not equals ' . join(',', $colorAfter));
  278. }
  279. /**
  280. * Get pixel coordinates after rotation
  281. *
  282. * @param array $pixel ('x' => ..., 'y' => ...)
  283. * @param int $angle
  284. * @param array $oldSize (width, height)
  285. * @param array $size (width, height)
  286. * @return array
  287. */
  288. protected function _convertCoordinates($pixel, $angle, $oldSize, $size)
  289. {
  290. $angle = $angle * pi() / 180;
  291. $center = ['x' => $oldSize[0] / 2, 'y' => $oldSize[1] / 2];
  292. $pixel['x'] -= $center['x'];
  293. $pixel['y'] -= $center['y'];
  294. return [
  295. 'x' => round($size[0] / 2 + $pixel['x'] * cos($angle) + $pixel['y'] * sin($angle), 0),
  296. 'y' => round($size[1] / 2 + $pixel['y'] * cos($angle) - $pixel['x'] * sin($angle), 0),
  297. ];
  298. }
  299. public function rotateDataProvider()
  300. {
  301. return $this->_prepareData(
  302. [
  303. [$this->_getFixture('image_adapters_test.png'), 45, ['x' => 157, 'y' => 35]],
  304. [$this->_getFixture('image_adapters_test.png'), 48, ['x' => 157, 'y' => 35]],
  305. [$this->_getFixture('image_adapters_test.png'), 90, ['x' => 250, 'y' => 74]],
  306. [$this->_getFixture('image_adapters_test.png'), 180, ['x' => 250, 'y' => 74]],
  307. ]
  308. );
  309. }
  310. /**
  311. * Test if alpha transparency is correctly handled
  312. *
  313. * @param string $image
  314. * @param string $watermark
  315. * @param int $alphaPercentage
  316. * @param array $comparePoint1
  317. * @param array $comparePoint2
  318. * @param string $adapterType
  319. *
  320. * @dataProvider imageWatermarkWithAlphaTransparencyDataProvider
  321. * @depends testOpen
  322. * @depends testImageSize
  323. */
  324. public function testWatermarkWithAlphaTransparency(
  325. $image,
  326. $watermark,
  327. $alphaPercentage,
  328. $comparePoint1,
  329. $comparePoint2,
  330. $adapterType
  331. ) {
  332. $imageAdapter = $this->_getAdapter($adapterType);
  333. $imageAdapter->open($image);
  334. $watermarkAdapter = $this->_getAdapter($adapterType);
  335. $watermarkAdapter->open($watermark);
  336. list($comparePoint1X, $comparePoint1Y) = $comparePoint1;
  337. list($comparePoint2X, $comparePoint2Y) = $comparePoint2;
  338. $imageAdapter
  339. ->setWatermarkImageOpacity($alphaPercentage)
  340. ->setWatermarkPosition(\Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_TOP_LEFT)
  341. ->watermark($watermark);
  342. $comparePoint1Color = $imageAdapter->getColorAt($comparePoint1X, $comparePoint1Y);
  343. unset($comparePoint1Color['alpha']);
  344. $comparePoint2Color = $imageAdapter->getColorAt($comparePoint2X, $comparePoint2Y);
  345. unset($comparePoint2Color['alpha']);
  346. $result = $this->_compareColors($comparePoint1Color, $comparePoint2Color);
  347. $message = sprintf(
  348. '%s should be different to %s due to alpha transparency',
  349. join(',', $comparePoint1Color),
  350. join(',', $comparePoint2Color)
  351. );
  352. $this->assertFalse($result, $message);
  353. }
  354. public function imageWatermarkWithAlphaTransparencyDataProvider()
  355. {
  356. return $this->_prepareData(
  357. [
  358. // Watermark with alpha channel, 25%
  359. [
  360. $this->_getFixture('watermark_alpha_base_image.jpg'),
  361. $this->_getFixture('watermark_alpha.png'),
  362. 25,
  363. [ 23, 3 ],
  364. [ 23, 30 ]
  365. ],
  366. // Watermark with alpha channel, 50%
  367. [
  368. $this->_getFixture('watermark_alpha_base_image.jpg'),
  369. $this->_getFixture('watermark_alpha.png'),
  370. 50,
  371. [ 23, 3 ],
  372. [ 23, 30 ]
  373. ],
  374. // Watermark with no alpha channel, 50%
  375. [
  376. $this->_getFixture('watermark_alpha_base_image.jpg'),
  377. $this->_getFixture('watermark.png'),
  378. 50,
  379. [ 3, 3 ],
  380. [ 23,3 ]
  381. ],
  382. // Watermark with no alpha channel, 100%
  383. [
  384. $this->_getFixture('watermark_alpha_base_image.jpg'),
  385. $this->_getFixture('watermark.png'),
  386. 100,
  387. [ 3, 3 ],
  388. [ 3, 60 ]
  389. ],
  390. ]
  391. );
  392. }
  393. /**
  394. * Checks if watermark exists on the right position
  395. *
  396. * @param string $image
  397. * @param string $watermark
  398. * @param int $width
  399. * @param int $height
  400. * @param float $opacity
  401. * @param string $position
  402. * @param int $colorX
  403. * @param int $colorY
  404. * @param string $adapterType
  405. *
  406. * @dataProvider imageWatermarkPositionDataProvider
  407. * @depends testOpen
  408. */
  409. public function testWatermarkPosition(
  410. $image,
  411. $watermark,
  412. $width,
  413. $height,
  414. $opacity,
  415. $position,
  416. $colorX,
  417. $colorY,
  418. $adapterType
  419. ) {
  420. $adapter = $this->_getAdapter($adapterType);
  421. $adapter->open($image);
  422. $pixel = $this->_prepareColor(['x' => $colorX, 'y' => $colorY], $position, $adapter);
  423. $colorBefore = $adapter->getColorAt($pixel['x'], $pixel['y']);
  424. $adapter->setWatermarkWidth(
  425. $width
  426. )->setWatermarkHeight(
  427. $height
  428. )->setWatermarkImageOpacity(
  429. $opacity
  430. )->setWatermarkPosition(
  431. $position
  432. )->watermark(
  433. $watermark
  434. );
  435. $colorAfter = $adapter->getColorAt($pixel['x'], $pixel['y']);
  436. $result = $this->_compareColors($colorBefore, $colorAfter);
  437. $message = join(',', $colorBefore) . ' not equals ' . join(',', $colorAfter);
  438. $this->assertFalse($result, $message);
  439. }
  440. public function imageWatermarkPositionDataProvider()
  441. {
  442. return $this->_prepareData(
  443. [
  444. [
  445. $this->_getFixture('image_adapters_test.png'),
  446. $this->_getFixture('watermark.png'),
  447. 50,
  448. 50,
  449. 100,
  450. \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_BOTTOM_RIGHT,
  451. 10,
  452. 10,
  453. ],
  454. [
  455. $this->_getFixture('image_adapters_test.png'),
  456. $this->_getFixture('watermark.png'),
  457. 100,
  458. 70,
  459. 100,
  460. \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_TOP_LEFT,
  461. 10,
  462. 10
  463. ],
  464. [
  465. $this->_getFixture('image_adapters_test.png'),
  466. $this->_getFixture('watermark.png'),
  467. 100,
  468. 70,
  469. 100,
  470. \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_TILE,
  471. 10,
  472. 10
  473. ],
  474. [
  475. $this->_getFixture('image_adapters_test.png'),
  476. $this->_getFixture('watermark.png'),
  477. 100,
  478. 100,
  479. 100,
  480. \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_STRETCH,
  481. 10,
  482. 10
  483. ],
  484. [
  485. $this->_getFixture('image_adapters_test.png'),
  486. $this->_getFixture('watermark.jpg'),
  487. 50,
  488. 50,
  489. 100,
  490. \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_BOTTOM_RIGHT,
  491. 10,
  492. 10
  493. ],
  494. [
  495. $this->_getFixture('image_adapters_test.png'),
  496. $this->_getFixture('watermark.gif'),
  497. 50,
  498. 50,
  499. 100,
  500. \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_BOTTOM_RIGHT,
  501. 10,
  502. 10
  503. ],
  504. ]
  505. );
  506. }
  507. /**
  508. * Sets colorX and colorY coordinates according image width and height
  509. *
  510. * @param array $pixel ('x' => ..., 'y' => ...)
  511. * @param string $position
  512. * @param \Magento\Framework\Image\Adapter\AbstractAdapter $adapter
  513. * @return array
  514. */
  515. protected function _prepareColor($pixel, $position, $adapter)
  516. {
  517. switch ($position) {
  518. case \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_BOTTOM_RIGHT:
  519. $pixel['x'] = $adapter->getOriginalWidth() - 1;
  520. $pixel['y'] = $adapter->getOriginalHeight() - 1;
  521. break;
  522. case \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_BOTTOM_LEFT:
  523. $pixel['x'] = 1;
  524. $pixel['y'] = $adapter->getOriginalHeight() - 1;
  525. break;
  526. case \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_TOP_LEFT:
  527. $pixel['x'] = 1;
  528. $pixel['y'] = 1;
  529. break;
  530. case \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_TOP_RIGHT:
  531. $pixel['x'] = $adapter->getOriginalWidth() - 1;
  532. $pixel['y'] = 1;
  533. break;
  534. case \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_CENTER:
  535. $pixel['x'] = $adapter->getOriginalWidth() / 2;
  536. $pixel['y'] = $adapter->getOriginalHeight() / 2;
  537. break;
  538. case \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_STRETCH:
  539. case \Magento\Framework\Image\Adapter\AbstractAdapter::POSITION_TILE:
  540. $pixel['x'] = round($adapter->getOriginalWidth() / 3);
  541. $pixel['y'] = round($adapter->getOriginalHeight() / 3);
  542. break;
  543. }
  544. return $pixel;
  545. }
  546. /**
  547. * @param string $image
  548. * @param int $left
  549. * @param int $top
  550. * @param int $right
  551. * @param int $bottom
  552. * @param string $adapterType
  553. *
  554. * @dataProvider cropDataProvider
  555. * @depends testOpen
  556. */
  557. public function testCrop($image, $left, $top, $right, $bottom, $adapterType)
  558. {
  559. $adapter = $this->_getAdapter($adapterType);
  560. $adapter->open($image);
  561. $expectedSize = [
  562. $adapter->getOriginalWidth() - $left - $right,
  563. $adapter->getOriginalHeight() - $top - $bottom,
  564. ];
  565. $adapter->crop($top, $left, $right, $bottom);
  566. $newSize = [$adapter->getOriginalWidth(), $adapter->getOriginalHeight()];
  567. $this->assertEquals($expectedSize, $newSize);
  568. }
  569. public function cropDataProvider()
  570. {
  571. return $this->_prepareData(
  572. [
  573. [$this->_getFixture('image_adapters_test.png'), 50, 50, 75, 75],
  574. [$this->_getFixture('image_adapters_test.png'), 20, 50, 35, 35],
  575. [$this->_getFixture('image_adapters_test.png'), 0, 0, 0, 0],
  576. ]
  577. );
  578. }
  579. /**
  580. * @dataProvider createPngFromStringDataProvider
  581. *
  582. * @param array $pixel1
  583. * @param array $expectedColor1
  584. * @param array $pixel2
  585. * @param array $expectedColor2
  586. * @param string $adapterType
  587. */
  588. public function testCreatePngFromString($pixel1, $expectedColor1, $pixel2, $expectedColor2, $adapterType)
  589. {
  590. $adapter = $this->_getAdapter($adapterType);
  591. /** @var \Magento\Framework\Filesystem\Directory\ReadFactory readFactory */
  592. $readFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  593. \Magento\Framework\Filesystem\Directory\ReadFactory::class
  594. );
  595. $reader = $readFactory->create(BP);
  596. $path = $reader->getAbsolutePath('lib/internal/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');
  597. $adapter->createPngFromString('T', $path);
  598. $adapter->refreshImageDimensions();
  599. $color1 = $adapter->getColorAt($pixel1['x'], $pixel1['y']);
  600. unset($color1['alpha']);
  601. $this->assertEquals($expectedColor1, $color1);
  602. $color2 = $adapter->getColorAt($pixel2['x'], $pixel2['y']);
  603. unset($color2['alpha']);
  604. $this->assertEquals($expectedColor2, $color2);
  605. }
  606. /**
  607. * We use different points for same cases for different adapters because of different antialiasing behavior
  608. * @link http://php.net/manual/en/function.imageantialias.php
  609. * @return array
  610. */
  611. public function createPngFromStringDataProvider()
  612. {
  613. return [
  614. [
  615. ['x' => 5, 'y' => 8],
  616. 'expectedColor1' => ['red' => 0, 'green' => 0, 'blue' => 0],
  617. ['x' => 0, 'y' => 14],
  618. 'expectedColor2' => ['red' => 255, 'green' => 255, 'blue' => 255],
  619. \Magento\Framework\Image\Adapter\AdapterInterface::ADAPTER_GD2,
  620. ],
  621. [
  622. ['x' => 5, 'y' => 12],
  623. 'expectedColor1' => ['red' => 0, 'green' => 0, 'blue' => 0],
  624. ['x' => 0, 'y' => 20],
  625. 'expectedColor2' => ['red' => 255, 'green' => 255, 'blue' => 255],
  626. \Magento\Framework\Image\Adapter\AdapterInterface::ADAPTER_IM
  627. ],
  628. [
  629. ['x' => 1, 'y' => 14],
  630. 'expectedColor1' => ['red' => 255, 'green' => 255, 'blue' => 255],
  631. ['x' => 5, 'y' => 12],
  632. 'expectedColor2' => ['red' => 0, 'green' => 0, 'blue' => 0],
  633. \Magento\Framework\Image\Adapter\AdapterInterface::ADAPTER_GD2
  634. ],
  635. [
  636. ['x' => 1, 'y' => 20],
  637. 'expectedColor1' => ['red' => 255, 'green' => 255, 'blue' => 255],
  638. ['x' => 5, 'y' => 16],
  639. 'expectedColor2' => ['red' => 0, 'green' => 0, 'blue' => 0],
  640. \Magento\Framework\Image\Adapter\AdapterInterface::ADAPTER_IM
  641. ]
  642. ];
  643. }
  644. public function testValidateUploadFile()
  645. {
  646. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  647. $imageAdapter = $objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
  648. $this->assertTrue($imageAdapter->validateUploadFile($this->_getFixture('magento_thumbnail.jpg')));
  649. }
  650. /**
  651. * @expectedException \InvalidArgumentException
  652. */
  653. public function testValidateUploadFileException()
  654. {
  655. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  656. $imageAdapter = $objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
  657. $imageAdapter->validateUploadFile(__FILE__);
  658. }
  659. }