7
7
8
8
namespace Magento \PageCache \Test \Unit \Model \App \Response ;
9
9
10
+ use Magento \Framework \App \Http \Context ;
10
11
use Magento \Framework \App \Response \Http as HttpResponse ;
12
+ use Magento \Framework \App \Request \Http as HttpRequest ;
11
13
use Magento \MediaStorage \Model \File \Storage \Response as FileResponse ;
12
14
use Magento \PageCache \Model \App \Response \HttpPlugin ;
13
15
use PHPUnit \Framework \MockObject \MockObject ;
@@ -23,13 +25,28 @@ class HttpPluginTest extends TestCase
23
25
*/
24
26
private $ httpPlugin ;
25
27
28
+ /**
29
+ * @var Context|MockObject
30
+ */
31
+ private $ context ;
32
+
33
+ /**
34
+ * @var HttpRequest|MockObject
35
+ */
36
+ private $ request ;
37
+
26
38
/**
27
39
* @inheritdoc
28
40
*/
29
41
protected function setUp (): void
30
42
{
31
43
parent ::setUp ();
32
- $ this ->httpPlugin = new HttpPlugin ();
44
+ $ this ->context = $ this ->createMock (Context::class);
45
+ $ this ->request = $ this ->createMock (HttpRequest::class);
46
+ $ this ->httpPlugin = new HttpPlugin (
47
+ $ this ->context ,
48
+ $ this ->request
49
+ );
33
50
}
34
51
35
52
/**
@@ -62,4 +79,17 @@ public function beforeSendResponseDataProvider(): array
62
79
'file_response_headers_sent ' => [FileResponse::class, true , 0 ],
63
80
];
64
81
}
82
+
83
+ public function testBeforeSendResponseVaryMismatch ()
84
+ {
85
+ /** @var HttpResponse|MockObject $responseMock */
86
+ $ this ->context ->expects ($ this ->any ())->method ('getVaryString ' )->willReturn ('currentVary ' );
87
+ $ this ->request ->expects ($ this ->any ())->method ('get ' )->willReturn ('varyCookie ' );
88
+ /** @var HttpResponse|MockObject $responseMock */
89
+ $ responseMock = $ this ->createMock (HttpResponse::class);
90
+ $ responseMock ->expects ($ this ->once ())->method ('setNoCacheHeaders ' );
91
+ $ responseMock ->expects ($ this ->once ())->method ('sendVary ' );
92
+
93
+ $ this ->httpPlugin ->beforeSendResponse ($ responseMock );
94
+ }
65
95
}
0 commit comments