77
88namespace Magento \PageCache \Test \Unit \Model \App \Response ;
99
10+ use Magento \Framework \App \Http \Context ;
1011use Magento \Framework \App \Response \Http as HttpResponse ;
12+ use Magento \Framework \App \Request \Http as HttpRequest ;
1113use Magento \MediaStorage \Model \File \Storage \Response as FileResponse ;
1214use Magento \PageCache \Model \App \Response \HttpPlugin ;
1315use PHPUnit \Framework \MockObject \MockObject ;
@@ -23,13 +25,28 @@ class HttpPluginTest extends TestCase
2325 */
2426 private $ httpPlugin ;
2527
28+ /**
29+ * @var Context|MockObject
30+ */
31+ private $ context ;
32+
33+ /**
34+ * @var HttpRequest|MockObject
35+ */
36+ private $ request ;
37+
2638 /**
2739 * @inheritdoc
2840 */
2941 protected function setUp (): void
3042 {
3143 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+ );
3350 }
3451
3552 /**
@@ -62,4 +79,17 @@ public function beforeSendResponseDataProvider(): array
6279 'file_response_headers_sent ' => [FileResponse::class, true , 0 ],
6380 ];
6481 }
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+ }
6595}
0 commit comments