Skip to content

Commit 94735ff

Browse files
committed
Merge remote-tracking branch 'arcticfoxes/B2B-2015' into 2.4-develop-pr
2 parents e9c16d7 + d300361 commit 94735ff

File tree

3 files changed

+87
-30
lines changed

3 files changed

+87
-30
lines changed

app/code/Magento/RemoteStorage/Plugin/Image.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function __construct(
8787
*/
8888
public function beforeOpen(AbstractAdapter $subject, $filename): array
8989
{
90-
if ($this->isEnabled) {
90+
if ($this->isEnabled && !empty($filename)) {
9191
$filename = $this->copyFileToTmp($filename);
9292
}
9393
return [$filename];
@@ -182,7 +182,7 @@ public function __destruct()
182182
* @return string
183183
* @throws FileSystemException
184184
*/
185-
private function copyFileToTmp(string $filePath): string
185+
private function copyFileToTmp($filePath): string
186186
{
187187
if ($this->fileExistsInTmp($filePath)) {
188188
return $this->tmpFiles[$filePath];
@@ -192,7 +192,7 @@ private function copyFileToTmp(string $filePath): string
192192
$this->tmpDirectoryWrite->create();
193193
$tmpPath = $this->storeTmpName($filePath);
194194
$content = $this->remoteDirectoryWrite->getDriver()->fileGetContents($filePath);
195-
$filePath = $this->tmpDirectoryWrite->getDriver()->filePutContents($tmpPath, $content)
195+
$filePath = $this->tmpDirectoryWrite->getDriver()->filePutContents($tmpPath, $content) !== false
196196
? $tmpPath
197197
: $filePath;
198198
}

dev/tests/integration/testsuite/Magento/Framework/Image/Adapter/InterfaceTest.php

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
*/
66
namespace Magento\Framework\Image\Adapter;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\Filesystem\Directory\WriteInterface;
10+
811
/**
12+
* @magentoDataFixture Magento/Framework/Image/_files/image_fixture.php
913
* @magentoAppIsolation enabled
1014
*/
1115
class InterfaceTest extends \PHPUnit\Framework\TestCase
@@ -20,6 +24,19 @@ class InterfaceTest extends \PHPUnit\Framework\TestCase
2024
\Magento\Framework\Image\Adapter\AdapterInterface::ADAPTER_IM,
2125
];
2226

27+
/**
28+
* @var \Magento\Framework\ObjectManagerInterface
29+
*/
30+
private $objectManager;
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
protected function setUp(): void
36+
{
37+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
38+
}
39+
2340
/**
2441
* Add adapters to each data provider case
2542
*
@@ -79,14 +96,14 @@ protected function _compareColors($colorBefore, $colorAfter)
7996
*/
8097
protected function _getFixture($pattern)
8198
{
82-
$dir = dirname(__DIR__) . '/_files/';
83-
$data = glob($dir . $pattern);
84-
85-
if (!empty($data)) {
86-
return $data[0];
99+
if (!$pattern) {
100+
return null;
87101
}
88-
89-
return null;
102+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
103+
/** @var $rootDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
104+
$rootDirectory = $objectManager->get(\Magento\Framework\Filesystem\Directory\TargetDirectory::class)
105+
->getDirectoryWrite(DirectoryList::TMP);
106+
return $rootDirectory->getAbsolutePath('image/test/' . $pattern);
90107
}
91108

92109
/**
@@ -114,8 +131,7 @@ protected function _getAdapter($adapterType)
114131
{
115132
$adapter = null;
116133
try {
117-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
118-
$adapter = $objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create($adapterType);
134+
$adapter = $this->objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create($adapterType);
119135
} catch (\Exception $e) {
120136
$this->markTestSkipped($e->getMessage());
121137
}
@@ -206,29 +222,36 @@ public function testImageSize($image, $adapterType)
206222

207223
/**
208224
* @param string $image
209-
* @param array $tempPath (dirName, newName)
225+
* @param array $tmpDir (dirName, newName)
210226
* @param string $adapterType
211227
*
228+
* @throws \Magento\Framework\Exception\FileSystemException
229+
*
212230
* @dataProvider saveDataProvider
213231
* @depends testOpen
214232
*/
215-
public function testSave($image, $tempPath, $adapterType)
233+
public function testSave($image, $tmpDir, $adapterType)
216234
{
217235
$adapter = $this->_getAdapter($adapterType);
218236
$adapter->open($image);
219-
try {
220-
call_user_func_array([$adapter, 'save'], $tempPath);
221-
$tempPath = join('', $tempPath);
222-
$this->assertFileExists($tempPath);
223-
unlink($tempPath);
224-
} catch (\Exception $e) {
225-
$this->assertFalse(is_dir($tempPath[0]) && is_writable($tempPath[0]));
226-
}
237+
238+
/** @var $rootDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
239+
$rootDirectory = $this->objectManager->get(\Magento\Framework\Filesystem\Directory\TargetDirectory::class)
240+
->getDirectoryWrite(DirectoryList::TMP);
241+
242+
call_user_func_array([$adapter, 'save'], $tmpDir);
243+
$tmpDir = join('', $tmpDir);
244+
$this->assertTrue($rootDirectory->isExist($tmpDir));
245+
$rootDirectory->delete($tmpDir);
227246
}
228247

229248
public function saveDataProvider()
230249
{
231-
$dir = \Magento\TestFramework\Helper\Bootstrap::getInstance()->getAppTempDir() . '/';
250+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
251+
/** @var $rootDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
252+
$rootDirectory = $objectManager->get(\Magento\Framework\Filesystem\Directory\TargetDirectory::class)
253+
->getDirectoryWrite(DirectoryList::TMP);
254+
$dir = $rootDirectory->getAbsolutePath('image/');
232255
return $this->_prepareData(
233256
[
234257
[$this->_getFixture('image_adapters_test.png'), [$dir . uniqid('test_image_adapter')]],
@@ -640,9 +663,7 @@ public function testCreatePngFromString($pixel1, $expectedColor1, $pixel2, $expe
640663
$adapter = $this->_getAdapter($adapterType);
641664

642665
/** @var \Magento\Framework\Filesystem\Directory\ReadFactory readFactory */
643-
$readFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
644-
\Magento\Framework\Filesystem\Directory\ReadFactory::class
645-
);
666+
$readFactory = $this->objectManager->get(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
646667
$reader = $readFactory->create(BP);
647668
$path = $reader->getAbsolutePath('lib/internal/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');
648669
$adapter->createPngFromString('T', $path);
@@ -698,8 +719,7 @@ public function createPngFromStringDataProvider()
698719

699720
public function testValidateUploadFile()
700721
{
701-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
702-
$imageAdapter = $objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
722+
$imageAdapter = $this->objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
703723
$this->assertTrue($imageAdapter->validateUploadFile($this->_getFixture('magento_thumbnail.jpg')));
704724
}
705725

@@ -713,8 +733,7 @@ public function testValidateUploadFileException($fileName, $expectedErrorMsg, $u
713733
{
714734
$this->expectException(\InvalidArgumentException::class);
715735

716-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
717-
$imageAdapter = $objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
736+
$imageAdapter = $this->objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
718737
$filePath = $useFixture ? $this->_getFixture($fileName) : $fileName;
719738

720739
try {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
11+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
12+
$targetDirectory = $objectManager->get(\Magento\Framework\Filesystem\Directory\TargetDirectory::class);
13+
/** @var $rootDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
14+
$rootDirectory = $targetDirectory->getDirectoryWrite(DirectoryList::TMP);
15+
16+
$filesToCopy = [
17+
'empty.png',
18+
'image_adapters_test.png',
19+
'magento_thumbnail.jpg',
20+
'notanimage.txt',
21+
'watermark.gif',
22+
'watermark.jpg',
23+
'watermark.png',
24+
'watermark_alpha.png',
25+
'watermark_alpha_base_image.jpg',
26+
];
27+
28+
foreach ($filesToCopy as $fileName) {
29+
$subDir = 'image/test/';
30+
$filePath = $subDir . $fileName;
31+
if (!$rootDirectory->isExist($filePath)) {
32+
$rootDirectory->create($subDir);
33+
$rootDirectory->getDriver()->filePutContents(
34+
$rootDirectory->getAbsolutePath($filePath),
35+
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . $fileName)
36+
);
37+
}
38+
}

0 commit comments

Comments
 (0)