Skip to content

Commit 1e6f8bc

Browse files
committed
MC-16249: [CLOUD] Attachment is not opened on storefront
1 parent 994c47d commit 1e6f8bc

File tree

3 files changed

+56
-67
lines changed

3 files changed

+56
-67
lines changed

app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\PageCache\Model\App\Response;
88

9+
use Magento\Framework\App\PageCache\NotCacheableInterface;
10+
use Magento\Framework\App\Response\Http as HttpResponse;
11+
912
/**
1013
* HTTP response plugin for frontend.
1114
*/
@@ -14,12 +17,12 @@ class HttpPlugin
1417
/**
1518
* Set proper value of X-Magento-Vary cookie.
1619
*
17-
* @param \Magento\Framework\App\Response\Http $subject
20+
* @param HttpResponse $subject
1821
* @return void
1922
*/
20-
public function beforeSendResponse(\Magento\Framework\App\Response\Http $subject)
23+
public function beforeSendResponse(HttpResponse $subject)
2124
{
22-
if ($subject instanceof \Magento\Framework\App\PageCache\NotCacheableInterface || headers_sent()) {
25+
if ($subject instanceof NotCacheableInterface || $subject->headersSent()) {
2326
return;
2427
}
2528

app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php

Lines changed: 50 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,63 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

7-
// @codingStandardsIgnoreStart
8-
namespace Magento\PageCache\Model\App\Response {
9-
$mockPHPFunctions = false;
8+
namespace Magento\PageCache\Test\Unit\Model\App\Response;
109

11-
function headers_sent()
12-
{
13-
global $mockPHPFunctions;
14-
if ($mockPHPFunctions) {
15-
return false;
16-
}
17-
18-
return call_user_func_array('\headers_sent', func_get_args());
19-
}
20-
}
21-
22-
namespace Magento\PageCache\Test\Unit\Model\App\Response {
23-
24-
use Magento\Framework\App\Response\Http;
25-
use Magento\MediaStorage\Model\File\Storage\Response;
26-
use Magento\PageCache\Model\App\Response\HttpPlugin;
10+
use Magento\Framework\App\Response\Http as HttpResponse;
11+
use Magento\MediaStorage\Model\File\Storage\Response as FileResponse;
12+
use Magento\PageCache\Model\App\Response\HttpPlugin;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
2715

28-
// @codingStandardsIgnoreEnd
16+
/**
17+
* Tests \Magento\PageCache\Model\App\Response\HttpPlugin.
18+
*/
19+
class HttpPluginTest extends TestCase
20+
{
21+
/**
22+
* @var HttpPlugin
23+
*/
24+
private $httpPlugin;
2925

30-
class HttpPluginTest extends \PHPUnit\Framework\TestCase
26+
/**
27+
* @inheritdoc
28+
*/
29+
protected function setUp()
3130
{
32-
/**
33-
* @inheritdoc
34-
*/
35-
protected function setUp()
36-
{
37-
global $mockPHPFunctions;
38-
$mockPHPFunctions = true;
39-
}
31+
parent::setUp();
32+
$this->httpPlugin = new HttpPlugin();
33+
}
4034

41-
/**
42-
* @inheritdoc
43-
*/
44-
protected function tearDown()
45-
{
46-
global $mockPHPFunctions;
47-
$mockPHPFunctions = false;
48-
}
35+
/**
36+
* @param string $responseClass
37+
* @param bool $headersSent
38+
* @param int $sendVaryCalled
39+
* @return void
40+
*
41+
* @dataProvider beforeSendResponseDataProvider
42+
*/
43+
public function testBeforeSendResponse(string $responseClass, bool $headersSent, int $sendVaryCalled): void
44+
{
45+
/** @var HttpResponse|MockObject $responseMock */
46+
$responseMock = $this->createMock($responseClass);
47+
$responseMock->expects($this->any())->method('headersSent')->willReturn($headersSent);
48+
$responseMock->expects($this->exactly($sendVaryCalled))->method('sendVary');
4949

50-
/**
51-
* @param string $responseInstanceClass
52-
* @param int $sendVaryCalled
53-
* @return void
54-
*
55-
* @dataProvider beforeSendResponseDataProvider
56-
*/
57-
public function testBeforeSendResponse(string $responseInstanceClass, int $sendVaryCalled): void
58-
{
59-
/** @var Http | \PHPUnit_Framework_MockObject_MockObject $responseMock */
60-
$responseMock = $this->createMock($responseInstanceClass);
61-
$responseMock->expects($this->exactly($sendVaryCalled))
62-
->method('sendVary');
63-
$plugin = new HttpPlugin();
64-
$plugin->beforeSendResponse($responseMock);
65-
}
50+
$this->httpPlugin->beforeSendResponse($responseMock);
51+
}
6652

67-
/**
68-
* @return array
69-
*/
70-
public function beforeSendResponseDataProvider(): array
71-
{
72-
return [
73-
[Http::class, 1],
74-
[Response::class, 0]
75-
];
76-
}
53+
/**
54+
* @return array
55+
*/
56+
public function beforeSendResponseDataProvider(): array
57+
{
58+
return [
59+
'http_response_headers_not_sent' => [HttpResponse::class, false, 1],
60+
'http_response_headers_sent' => [HttpResponse::class, true, 0],
61+
'file_response_headers_not_sent' => [FileResponse::class, false, 0],
62+
'file_response_headers_sent' => [FileResponse::class, true, 0],
63+
];
7764
}
7865
}

dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/blacklist/common.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ dev/tests/api-functional/testsuite/Magento/Customer/Api/AddressRepositoryTest.ph
1414
dev/tests/api-functional/testsuite/Magento/Framework/Model/Entity/HydratorTest.php
1515
dev/tests/api-functional/testsuite/Magento/Integration/Model/AdminTokenServiceTest.php
1616
dev/tests/api-functional/testsuite/Magento/Integration/Model/CustomerTokenServiceTest.php
17-
app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php

0 commit comments

Comments
 (0)