Skip to content

Commit b7e085f

Browse files
authored
Merge pull request #8335 from magento-l3/PR06022023_2.4.7-beta1-develop
[L3] 2.4.7-beta1-develop
2 parents c0d47f1 + 6bc82de commit b7e085f

File tree

16 files changed

+224
-67
lines changed

16 files changed

+224
-67
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
*/
77
namespace Magento\Backup\Controller\Adminhtml\Index;
88

9+
use Magento\Framework\App\Action\HttpGetActionInterface;
910
use Magento\Framework\App\Filesystem\DirectoryList;
1011

11-
class Download extends \Magento\Backup\Controller\Adminhtml\Index
12+
class Download extends \Magento\Backup\Controller\Adminhtml\Index implements HttpGetActionInterface
1213
{
1314
/**
1415
* @var \Magento\Framework\Controller\Result\RawFactory
@@ -66,17 +67,12 @@ public function execute()
6667

6768
$fileName = $this->_objectManager->get(\Magento\Backup\Helper\Data::class)->generateBackupDownloadName($backup);
6869

69-
$this->_fileFactory->create(
70+
return $this->_fileFactory->create(
7071
$fileName,
71-
null,
72+
['type' => 'filename', 'value' => $backup->getPath() . DIRECTORY_SEPARATOR . $backup->getFileName()],
7273
DirectoryList::VAR_DIR,
7374
'application/octet-stream',
7475
$backup->getSize()
7576
);
76-
77-
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
78-
$resultRaw = $this->resultRawFactory->create();
79-
$resultRaw->setContents($backup->output());
80-
return $resultRaw;
8177
}
8278
}

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: 4 additions & 7 deletions
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
@@ -47,6 +48,7 @@ public function __construct(
4748
*/
4849
public function execute()
4950
{
51+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
5052
$fileName = basename($this->getRequest()->getParam('filename'));
5153

5254
/** @var \Magento\ImportExport\Helper\Report $reportHelper */
@@ -59,17 +61,12 @@ public function execute()
5961
return $resultRedirect;
6062
}
6163

62-
$this->fileFactory->create(
64+
return $this->fileFactory->create(
6365
$fileName,
64-
null,
66+
['type' => 'filename', 'value' => Import::IMPORT_HISTORY_DIR . $fileName],
6567
DirectoryList::VAR_IMPORT_EXPORT,
6668
'application/octet-stream',
6769
$reportHelper->getReportSize($fileName)
6870
);
69-
70-
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
71-
$resultRaw = $this->resultRawFactory->create();
72-
$resultRaw->setContents($reportHelper->getReportOutput($fileName));
73-
return $resultRaw;
7471
}
7572
}

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/PageCache/Model/App/FrontController/BuiltinPlugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\PageCache\Model\App\FrontController;
77

8+
use Magento\Framework\App\PageCache\NotCacheableInterface;
89
use Magento\Framework\App\Response\Http as ResponseHttp;
910

1011
/**
@@ -73,7 +74,7 @@ public function aroundDispatch(
7374
$result = $this->kernel->load();
7475
if ($result === false) {
7576
$result = $proceed($request);
76-
if ($result instanceof ResponseHttp) {
77+
if ($result instanceof ResponseHttp && !$result instanceof NotCacheableInterface) {
7778
$this->addDebugHeaders($result);
7879
$this->kernel->process($result);
7980
}

app/code/Magento/PageCache/Test/Unit/Model/App/FrontController/BuiltinPluginTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Laminas\Http\Header\GenericHeader;
1212
use Magento\Framework\App\FrontControllerInterface;
1313
use Magento\Framework\App\PageCache\Kernel;
14+
use Magento\Framework\App\PageCache\NotCacheableInterface;
1415
use Magento\Framework\App\PageCache\Version;
1516
use Magento\Framework\App\RequestInterface;
1617
use Magento\Framework\App\Response\Http;
@@ -243,6 +244,41 @@ public function testAroundDispatchDisabled($state): void
243244
);
244245
}
245246

247+
/**
248+
* @return void
249+
*/
250+
public function testAroundNotCacheableResponse(): void
251+
{
252+
$this->configMock
253+
->expects($this->once())
254+
->method('getType')
255+
->willReturn(Config::BUILT_IN);
256+
$this->configMock->expects($this->once())
257+
->method('isEnabled')
258+
->willReturn(true);
259+
$this->versionMock
260+
->expects($this->once())
261+
->method('process');
262+
$this->kernelMock->expects($this->once())
263+
->method('load')
264+
->willReturn(false);
265+
$this->stateMock->expects($this->never())
266+
->method('getMode');
267+
$this->kernelMock->expects($this->never())
268+
->method('process');
269+
$this->responseMock->expects($this->never())
270+
->method('setHeader');
271+
$notCacheableResponse = $this->createMock(NotCacheableInterface::class);
272+
$this->assertSame(
273+
$notCacheableResponse,
274+
$this->plugin->aroundDispatch(
275+
$this->frontControllerMock,
276+
fn () => $notCacheableResponse,
277+
$this->requestMock
278+
)
279+
);
280+
}
281+
246282
/**
247283
* @return array
248284
*/

app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class DownloadCustomOption extends \Magento\Framework\App\Action\Action implemen
2929
/**
3030
* @var \Magento\Framework\Unserialize\Unserialize
3131
* @deprecated 101.0.0
32+
* @deprecated No longer used
33+
* @see $serializer
3234
*/
3335
protected $unserialize;
3436

@@ -106,7 +108,7 @@ public function execute()
106108
if ($this->getRequest()->getParam('key') != $info['secret_key']) {
107109
return $resultForward->forward('noroute');
108110
}
109-
$this->download->downloadFile($info);
111+
return $this->download->createResponse($info);
110112
} catch (\Exception $e) {
111113
return $resultForward->forward('noroute');
112114
}

app/code/Magento/Sales/Model/Download.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,22 @@ public function __construct(
6767
* @param array $info
6868
* @return void
6969
* @throws \Exception
70+
* @deprecated No longer recommended
71+
* @see createResponse()
7072
*/
7173
public function downloadFile($info)
74+
{
75+
$this->createResponse($info);
76+
}
77+
78+
/**
79+
* Returns a file response
80+
*
81+
* @param array $info
82+
* @return \Magento\Framework\App\ResponseInterface
83+
* @throws \Exception
84+
*/
85+
public function createResponse($info)
7286
{
7387
$relativePath = $info['order_path'];
7488
if (!$this->_isCanProcessed($relativePath)) {
@@ -80,7 +94,7 @@ public function downloadFile($info)
8094
);
8195
}
8296
}
83-
$this->_fileFactory->create(
97+
return $this->_fileFactory->create(
8498
$info['title'],
8599
['value' => $this->_rootDir->getRelativePath($relativePath), 'type' => 'filename'],
86100
$this->rootDirBasePath,

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
/**

app/code/Magento/Wishlist/Controller/Index/DownloadCustomOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function execute()
9797
$secretKey = $this->getRequest()->getParam('key');
9898

9999
if ($secretKey == $info['secret_key']) {
100-
$this->_fileResponseFactory->create(
100+
return $this->_fileResponseFactory->create(
101101
$info['title'],
102102
['value' => $info['quote_path'], 'type' => 'filename'],
103103
DirectoryList::MEDIA,

0 commit comments

Comments
 (0)