Skip to content

Commit 44dc316

Browse files
committed
ACP2E-2015: Customizable Option Image link is broken
1 parent fbfe0a9 commit 44dc316

File tree

5 files changed

+45
-30
lines changed

5 files changed

+45
-30
lines changed

app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function execute()
6969

7070
return $this->_fileFactory->create(
7171
$fileName,
72-
$backup->output(),
72+
['type' => 'filename', 'value' => $backup->getPath() . DIRECTORY_SEPARATOR . $backup->getFileName()],
7373
DirectoryList::VAR_DIR,
7474
'application/octet-stream',
7575
$backup->getSize()

app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function setUp(): void
115115
->getMock();
116116
$this->backupModelMock = $this->getMockBuilder(Backup::class)
117117
->disableOriginalConstructor()
118-
->setMethods(['getTime', 'exists', 'getSize', 'output'])
118+
->setMethods(['getTime', 'exists', 'getSize', 'output', 'getPath', 'getFileName'])
119119
->getMock();
120120
$this->dataHelperMock = $this->getMockBuilder(Data::class)
121121
->disableOriginalConstructor()
@@ -169,8 +169,13 @@ public function testExecuteBackupFound()
169169
$type = 'db';
170170
$filename = 'filename';
171171
$size = 10;
172-
$output = 'test';
173-
172+
$path = 'testpath';
173+
$this->backupModelMock->expects($this->atLeastOnce())
174+
->method('getPath')
175+
->willReturn($path);
176+
$this->backupModelMock->expects($this->atLeastOnce())
177+
->method('getFileName')
178+
->willReturn($filename);
174179
$this->backupModelMock->expects($this->atLeastOnce())
175180
->method('getTime')
176181
->willReturn($time);
@@ -180,9 +185,6 @@ public function testExecuteBackupFound()
180185
$this->backupModelMock->expects($this->atLeastOnce())
181186
->method('getSize')
182187
->willReturn($size);
183-
$this->backupModelMock->expects($this->atLeastOnce())
184-
->method('output')
185-
->willReturn($output);
186188
$this->requestMock->expects($this->any())
187189
->method('getParam')
188190
->willReturnMap(
@@ -206,20 +208,14 @@ public function testExecuteBackupFound()
206208
$this->fileFactoryMock->expects($this->once())
207209
->method('create')->with(
208210
$filename,
209-
null,
211+
['type' => 'filename', 'value' => $path . '/' . $filename],
210212
DirectoryList::VAR_DIR,
211213
'application/octet-stream',
212214
$size
213215
)
214216
->willReturn($this->responseMock);
215-
$this->resultRawMock->expects($this->once())
216-
->method('setContents')
217-
->with($output);
218-
$this->resultRawFactoryMock->expects($this->once())
219-
->method('create')
220-
->willReturn($this->resultRawMock);
221217

222-
$this->assertSame($this->resultRawMock, $this->downloadController->execute());
218+
$this->assertSame($this->responseMock, $this->downloadController->execute());
223219
}
224220

225221
/**

app/code/Magento/ImportExport/Controller/Adminhtml/History/Download.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\App\Action\HttpGetActionInterface;
99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\ImportExport\Model\Import;
1011

1112
/**
1213
* Download history controller
@@ -62,7 +63,7 @@ public function execute()
6263

6364
return $this->fileFactory->create(
6465
$fileName,
65-
$reportHelper->getReportOutput($fileName),
66+
['type' => 'filename', 'value' => Import::IMPORT_HISTORY_DIR . $fileName],
6667
DirectoryList::VAR_IMPORT_EXPORT,
6768
'application/octet-stream',
6869
$reportHelper->getReportSize($fileName)

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99

1010
use Magento\Backend\App\Action\Context;
1111
use Magento\Backend\Model\View\Result\Redirect;
12+
use Magento\Framework\App\Filesystem\DirectoryList;
1213
use Magento\Framework\App\Request\Http;
1314
use Magento\Framework\App\Response\Http\FileFactory;
15+
use Magento\Framework\App\ResponseInterface;
1416
use Magento\Framework\Controller\Result\Raw;
1517
use Magento\Framework\Controller\Result\RawFactory;
1618
use Magento\Framework\Controller\Result\RedirectFactory;
1719
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1820
use Magento\ImportExport\Controller\Adminhtml\History\Download;
1921
use Magento\ImportExport\Helper\Report;
22+
use Magento\ImportExport\Model\Import;
2023
use PHPUnit\Framework\MockObject\MockObject;
2124
use PHPUnit\Framework\TestCase;
2225

@@ -155,8 +158,20 @@ public function testExecute($requestFilename, $processedFilename)
155158
$this->reportHelper->method('importFileExists')
156159
->with($processedFilename)
157160
->willReturn(true);
158-
$this->resultRaw->expects($this->once())->method('setContents');
159-
$this->downloadController->execute();
161+
162+
$responseMock = $this->getMockBuilder(ResponseInterface::class)
163+
->getMock();
164+
$this->fileFactory->expects($this->once())
165+
->method('create')
166+
->with(
167+
$processedFilename,
168+
['type' => 'filename', 'value' =>Import::IMPORT_HISTORY_DIR . $processedFilename],
169+
DirectoryList::VAR_IMPORT_EXPORT,
170+
'application/octet-stream',
171+
1
172+
)
173+
->willReturn($responseMock);
174+
$this->assertSame($responseMock, $this->downloadController->execute());
160175
}
161176

162177
/**

app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Backend\App\Action\Context;
1111
use Magento\Framework\App\Request\Http;
12+
use Magento\Framework\App\ResponseInterface;
1213
use Magento\Framework\Controller\Result\Forward;
1314
use Magento\Framework\Controller\Result\ForwardFactory;
1415
use Magento\Framework\Serialize\Serializer\Json;
@@ -24,32 +25,32 @@ class DownloadCustomOptionTest extends TestCase
2425
/**
2526
* Option ID Test Value
2627
*/
27-
const OPTION_ID = '123456';
28+
public const OPTION_ID = '123456';
2829

2930
/**
3031
* Option Code Test Value
3132
*/
32-
const OPTION_CODE = 'option_123456';
33+
public const OPTION_CODE = 'option_123456';
3334

3435
/**
3536
* Option Product ID Value
3637
*/
37-
const OPTION_PRODUCT_ID = 'option_test_product_id';
38+
public const OPTION_PRODUCT_ID = 'option_test_product_id';
3839

3940
/**
4041
* Option Type Value
4142
*/
42-
const OPTION_TYPE = 'file';
43+
public const OPTION_TYPE = 'file';
4344

4445
/**
4546
* Option Value Test Value
4647
*/
47-
const OPTION_VALUE = 'option_test_value';
48+
public const OPTION_VALUE = 'option_test_value';
4849

4950
/**
5051
* Option Value Test Value
5152
*/
52-
const SECRET_KEY = 'secret_key';
53+
public const SECRET_KEY = 'secret_key';
5354

5455
/**
5556
* @var \Magento\Quote\Model\Quote\Item\Option|MockObject
@@ -95,7 +96,7 @@ protected function setUp(): void
9596

9697
$this->downloadMock = $this->getMockBuilder(Download::class)
9798
->disableOriginalConstructor()
98-
->setMethods(['downloadFile'])
99+
->setMethods(['createResponse'])
99100
->getMock();
100101

101102
$this->serializerMock = $this->getMockBuilder(Json::class)
@@ -199,7 +200,8 @@ public function testExecute($itemOptionValues, $productOptionValues, $noRouteOcc
199200
->willReturn($productOptionValues[self::OPTION_TYPE]);
200201
}
201202
if ($noRouteOccurs) {
202-
$this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturn(true);
203+
$result = $this->resultForwardMock;
204+
$this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturnSelf();
203205
} else {
204206
$unserializeResult = [self::SECRET_KEY => self::SECRET_KEY];
205207

@@ -208,14 +210,15 @@ public function testExecute($itemOptionValues, $productOptionValues, $noRouteOcc
208210
->with($itemOptionValues[self::OPTION_VALUE])
209211
->willReturn($unserializeResult);
210212

213+
$result = $this->getMockBuilder(ResponseInterface::class)
214+
->getMock();
211215
$this->downloadMock->expects($this->once())
212-
->method('downloadFile')
216+
->method('createResponse')
213217
->with($unserializeResult)
214-
->willReturn(true);
218+
->willReturn($result);
215219

216-
$this->objectMock->expects($this->once())->method('endExecute')->willReturn(true);
217220
}
218-
$this->objectMock->execute();
221+
$this->assertSame($result, $this->objectMock->execute());
219222
}
220223

221224
/**

0 commit comments

Comments
 (0)