Skip to content

Commit 67b488d

Browse files
Merge pull request #9352 from magento-cia/cia-2.4.8-beta2-develop-bugfix-11102024
Cia 2.4.8 beta2 develop bugfix 11102024
2 parents 2a6cd1c + ccfa040 commit 67b488d

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

app/code/Magento/ImportExport/Controller/Adminhtml/Export/File/Download.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ public function execute()
8181
return $resultRedirect;
8282
}
8383

84-
// phpcs:ignore Magento2.Functions.DiscouragedFunction
85-
$fileName = basename($fileName);
86-
87-
$exportDirectory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_IMPORT_EXPORT);
84+
$exportDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
8885

8986
try {
90-
$fileExist = $exportDirectory->isExist('export/' . $fileName);
87+
$fileName = $exportDirectory->getDriver()->getRealPathSafety(DIRECTORY_SEPARATOR . $fileName);
88+
$fileExist = $exportDirectory->isExist('export' . $fileName);
9189
} catch (Throwable $e) {
9290
$fileExist = false;
9391
}
@@ -99,7 +97,7 @@ public function execute()
9997
}
10098

10199
try {
102-
$path = 'export/' . $fileName;
100+
$path = 'export' . $fileName;
103101
$directory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_IMPORT_EXPORT);
104102
if ($directory->isFile($path)) {
105103
return $this->fileFactory->create(

app/code/Magento/ImportExport/Test/Unit/Controller/Adminhtml/Export/File/DownloadTest.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use Magento\ImportExport\Controller\Adminhtml\Export\File\Download;
2121
use PHPUnit\Framework\MockObject\MockObject;
2222
use PHPUnit\Framework\TestCase;
23+
use Magento\Framework\Filesystem\Directory\WriteInterface;
24+
use Magento\Framework\Filesystem\DriverInterface;
2325

2426
/**
2527
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -76,6 +78,11 @@ class DownloadTest extends TestCase
7678
*/
7779
private $directoryMock;
7880

81+
/**
82+
* @var WriteInterface|MockObject
83+
*/
84+
private $exportDirectoryMock;
85+
7986
/**
8087
* Set up
8188
*/
@@ -89,6 +96,10 @@ protected function setUp(): void
8996
->disableOriginalConstructor()
9097
->getMock();
9198

99+
$this->exportDirectoryMock = $this->getMockBuilder(WriteInterface::class)
100+
->disableOriginalConstructor()
101+
->getMockForAbstractClass();
102+
92103
$this->directoryMock = $this->getMockBuilder(ReadInterface::class)
93104
->disableOriginalConstructor()
94105
->getMockForAbstractClass();
@@ -135,6 +146,10 @@ protected function setUp(): void
135146
->method('getDirectoryRead')
136147
->willReturn($this->directoryMock);
137148

149+
$this->fileSystemMock->expects($this->any())
150+
->method('getDirectoryWrite')
151+
->willReturn($this->exportDirectoryMock);
152+
138153
$this->objectManagerHelper = new ObjectManagerHelper($this);
139154
$this->downloadControllerMock = $this->objectManagerHelper->getObject(
140155
Download::class,
@@ -154,7 +169,18 @@ public function testExecuteSuccess()
154169
$this->requestMock->method('getParam')
155170
->with('filename')
156171
->willReturn('sampleFile.csv');
157-
$this->directoryMock->expects($this->once())->method('isExist')->willReturn(true);
172+
173+
$driverMock = $this->getMockBuilder(DriverInterface::class)
174+
->disableOriginalConstructor()
175+
->getMock();
176+
177+
$driverMock->expects($this->once())->method('getRealPathSafety')->willReturn('sampleFile.csv');
178+
179+
$this->exportDirectoryMock->expects($this->any())
180+
->method('getDriver')
181+
->willReturn($driverMock);
182+
183+
$this->exportDirectoryMock->expects($this->once())->method('isExist')->willReturn(true);
158184
$this->directoryMock->expects($this->once())->method('isFile')->willReturn(true);
159185
$this->fileFactoryMock->expects($this->once())->method('create');
160186

@@ -170,8 +196,18 @@ public function testExecuteFileDoesntExists()
170196
->with('filename')
171197
->willReturn('sampleFile');
172198

199+
$driverMock = $this->getMockBuilder(DriverInterface::class)
200+
->disableOriginalConstructor()
201+
->getMock();
202+
203+
$driverMock->expects($this->once())->method('getRealPathSafety')->willReturn('sampleFile');
204+
205+
$this->exportDirectoryMock->expects($this->any())
206+
->method('getDriver')
207+
->willReturn($driverMock);
208+
209+
$this->exportDirectoryMock->expects($this->once())->method('isExist')->willReturn(true);
173210
$this->directoryMock->expects($this->once())->method('isFile')->willReturn(false);
174-
$this->directoryMock->expects($this->once())->method('isExist')->willReturn(true);
175211
$this->messageManagerMock->expects($this->once())->method('addErrorMessage');
176212

177213
$this->downloadControllerMock->execute();

0 commit comments

Comments
 (0)