Skip to content

Commit 9896a09

Browse files
authored
Merge pull request #6743 from magento-tsg/MC-41675
[Arrows] MC-41675: [2.3.7] Could not load file to Customer attribute type file
2 parents 3d91853 + 00a2900 commit 9896a09

File tree

3 files changed

+26
-45
lines changed

3 files changed

+26
-45
lines changed

app/code/Magento/Customer/Model/Metadata/Form/File.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Exception\LocalizedException;
1515
use Magento\Framework\File\UploaderFactory;
1616
use Magento\Framework\Filesystem;
17+
use Magento\Framework\Filesystem\Io\File as FileIo;
1718

1819
/**
1920
* Processes files that are save for customer.
@@ -62,6 +63,11 @@ class File extends AbstractData
6263
*/
6364
protected $fileProcessorFactory;
6465

66+
/**
67+
* @var FileIo
68+
*/
69+
private $fileIo;
70+
6571
/**
6672
* Constructor
6773
*
@@ -77,6 +83,7 @@ class File extends AbstractData
7783
* @param Filesystem $fileSystem
7884
* @param UploaderFactory $uploaderFactory
7985
* @param \Magento\Customer\Model\FileProcessorFactory|null $fileProcessorFactory
86+
* @param FileIo|null $fileIo
8087
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8188
*/
8289
public function __construct(
@@ -91,7 +98,8 @@ public function __construct(
9198
\Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $fileValidator,
9299
Filesystem $fileSystem,
93100
UploaderFactory $uploaderFactory,
94-
\Magento\Customer\Model\FileProcessorFactory $fileProcessorFactory = null
101+
\Magento\Customer\Model\FileProcessorFactory $fileProcessorFactory = null,
102+
FileIo $fileIo = null
95103
) {
96104
parent::__construct($localeDate, $logger, $attribute, $localeResolver, $value, $entityTypeCode, $isAjax);
97105
$this->urlEncoder = $urlEncoder;
@@ -101,6 +109,8 @@ public function __construct(
101109
$this->fileProcessorFactory = $fileProcessorFactory ?: ObjectManager::getInstance()
102110
->get(\Magento\Customer\Model\FileProcessorFactory::class);
103111
$this->fileProcessor = $this->fileProcessorFactory->create(['entityTypeCode' => $this->_entityTypeCode]);
112+
$this->fileIo = $fileIo ?: ObjectManager::getInstance()
113+
->get(FileIo::class);
104114
}
105115

106116
/**
@@ -176,7 +186,7 @@ protected function _validateByRules($value)
176186
{
177187
$label = $value['name'];
178188
$rules = $this->getAttribute()->getValidationRules();
179-
$extension = $this->fileProcessor->getStat($value['name'])['extension'];
189+
$extension = $this->fileIo->getPathInfo($value['name'])['extension'];
180190
$fileExtensions = ArrayObjectSearch::getArrayElementByName(
181191
$rules,
182192
'file_extensions'
@@ -230,7 +240,7 @@ protected function _isUploadedFile($filename)
230240
}
231241

232242
// This case is required for file uploader UI component
233-
$temporaryFile = FileProcessor::TMP_DIR . '/' . $this->fileProcessor->getStat($filename)['basename'];
243+
$temporaryFile = FileProcessor::TMP_DIR . '/' . $this->fileIo->getPathInfo($filename)['basename'];
234244
if ($this->fileProcessor->isExist($temporaryFile)) {
235245
return true;
236246
}

app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/FileTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\File\UploaderFactory;
1919
use Magento\Framework\Filesystem;
2020
use Magento\Framework\Filesystem\Directory\WriteInterface;
21+
use Magento\Framework\Filesystem\Io\File as FileIo;
2122
use Magento\Framework\Url\EncoderInterface;
2223
use Magento\MediaStorage\Model\File\Validator\NotProtectedExtension;
2324
use PHPUnit\Framework\MockObject\MockObject;
@@ -64,6 +65,14 @@ class FileTest extends AbstractFormTestCase
6465
*/
6566
private $fileProcessorFactoryMock;
6667

68+
/**
69+
* @var FileIo|MockObject
70+
*/
71+
private $fileIoMock;
72+
73+
/**
74+
* @inheritDoc
75+
*/
6776
protected function setUp(): void
6877
{
6978
parent::setUp();
@@ -90,6 +99,7 @@ protected function setUp(): void
9099
$this->fileProcessorFactoryMock->expects($this->any())
91100
->method('create')
92101
->willReturn($this->fileProcessorMock);
102+
$this->fileIoMock = $this->createMock(FileIo::class);
93103
}
94104

95105
/**
@@ -297,8 +307,9 @@ public function testValidateValueToUpload($expected, $value, $parameters = [])
297307
$parameters['valid']
298308
);
299309

300-
$this->fileProcessorMock->expects($this->any())
301-
->method('getStat')
310+
$this->fileIoMock->expects($this->any())
311+
->method('getPathInfo')
312+
->with($value['name'])
302313
->willReturn([
303314
'extension' => $value['extension'],
304315
'basename' => $value['basename']

app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/ImageTest.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,6 @@ public function testValidateIsNotValidFile()
201201
->method('getStoreLabel')
202202
->willReturn('File Input Field Label');
203203

204-
$this->fileProcessorMock->expects($this->once())
205-
->method('getStat')
206-
->with($value['tmp_name'])
207-
->willReturn([
208-
'extension' => 'txt',
209-
'basename' => 'tmp_file.txt',
210-
]);
211-
212204
$this->fileProcessorMock->expects($this->once())
213205
->method('isExist')
214206
->with(FileProcessor::TMP_DIR . '/' . $value['tmp_name'])
@@ -238,14 +230,6 @@ public function testValidate()
238230
->method('getStoreLabel')
239231
->willReturn('File Input Field Label');
240232

241-
$this->fileProcessorMock->expects($this->once())
242-
->method('getStat')
243-
->with($value['tmp_name'])
244-
->willReturn([
245-
'extension' => 'gif',
246-
'basename' => 'logo.gif',
247-
]);
248-
249233
$this->fileProcessorMock->expects($this->once())
250234
->method('isExist')
251235
->with(FileProcessor::TMP_DIR . '/' . $value['name'])
@@ -299,14 +283,6 @@ public function testValidateMaxFileSize()
299283
->method('getValidationRules')
300284
->willReturn([$validationRuleMock]);
301285

302-
$this->fileProcessorMock->expects($this->once())
303-
->method('getStat')
304-
->with($value['tmp_name'])
305-
->willReturn([
306-
'extension' => 'gif',
307-
'basename' => 'logo.gif',
308-
]);
309-
310286
$this->fileProcessorMock->expects($this->once())
311287
->method('isExist')
312288
->with(FileProcessor::TMP_DIR . '/' . $value['name'])
@@ -359,14 +335,6 @@ public function testValidateMaxImageWidth()
359335
->method('getValidationRules')
360336
->willReturn([$validationRuleMock]);
361337

362-
$this->fileProcessorMock->expects($this->once())
363-
->method('getStat')
364-
->with($value['tmp_name'])
365-
->willReturn([
366-
'extension' => 'gif',
367-
'basename' => 'logo.gif',
368-
]);
369-
370338
$this->fileProcessorMock->expects($this->once())
371339
->method('isExist')
372340
->with(FileProcessor::TMP_DIR . '/' . $value['name'])
@@ -419,14 +387,6 @@ public function testValidateMaxImageHeight()
419387
->method('getValidationRules')
420388
->willReturn([$validationRuleMock]);
421389

422-
$this->fileProcessorMock->expects($this->once())
423-
->method('getStat')
424-
->with($value['tmp_name'])
425-
->willReturn([
426-
'extension' => 'gif',
427-
'basename' => 'logo.gif',
428-
]);
429-
430390
$this->fileProcessorMock->expects($this->once())
431391
->method('isExist')
432392
->with(FileProcessor::TMP_DIR . '/' . $value['name'])

0 commit comments

Comments
 (0)