16
16
use Magento \Framework \Stdlib \Cookie \PublicCookieMetadata ;
17
17
use Magento \Framework \Stdlib \CookieManagerInterface ;
18
18
use Magento \Framework \Translate \InlineInterface ;
19
+ use Magento \Framework \Session \Config \ConfigInterface ;
19
20
use Magento \Framework \View \Element \Message \InterpretationStrategyInterface ;
20
21
use Magento \Theme \Controller \Result \MessagePlugin ;
21
22
use PHPUnit \Framework \MockObject \MockObject ;
@@ -47,6 +48,11 @@ class MessagePluginTest extends TestCase
47
48
/** @var InlineInterface|MockObject */
48
49
private $ inlineTranslateMock ;
49
50
51
+ /**
52
+ * @var ConfigInterface|MockObject
53
+ */
54
+ protected $ sessionConfigMock ;
55
+
50
56
protected function setUp (): void
51
57
{
52
58
$ this ->cookieManagerMock = $ this ->getMockBuilder (CookieManagerInterface::class)
@@ -62,14 +68,17 @@ protected function setUp(): void
62
68
->getMock ();
63
69
$ this ->inlineTranslateMock = $ this ->getMockBuilder (InlineInterface::class)
64
70
->getMockForAbstractClass ();
71
+ $ this ->sessionConfigMock = $ this ->getMockBuilder (ConfigInterface::class)
72
+ ->getMockForAbstractClass ();
65
73
66
74
$ this ->model = new MessagePlugin (
67
75
$ this ->cookieManagerMock ,
68
76
$ this ->cookieMetadataFactoryMock ,
69
77
$ this ->managerMock ,
70
78
$ this ->interpretationStrategyMock ,
71
79
$ this ->serializerMock ,
72
- $ this ->inlineTranslateMock
80
+ $ this ->inlineTranslateMock ,
81
+ $ this ->sessionConfigMock
73
82
);
74
83
}
75
84
@@ -549,4 +558,49 @@ function ($data) {
549
558
550
559
$ this ->assertEquals ($ resultMock , $ this ->model ->afterRenderResult ($ resultMock , $ resultMock ));
551
560
}
561
+
562
+ public function testSetCookieWithCookiePath ()
563
+ {
564
+ /** @var Redirect|MockObject $resultMock */
565
+ $ resultMock = $ this ->getMockBuilder (Redirect::class)
566
+ ->disableOriginalConstructor ()
567
+ ->getMock ();
568
+
569
+ /** @var PublicCookieMetadata|MockObject $cookieMetadataMock */
570
+ $ cookieMetadataMock = $ this ->getMockBuilder (PublicCookieMetadata::class)
571
+ ->disableOriginalConstructor ()
572
+ ->getMock ();
573
+
574
+ $ this ->cookieMetadataFactoryMock ->expects ($ this ->once ())
575
+ ->method ('createPublicCookieMetadata ' )
576
+ ->willReturn ($ cookieMetadataMock );
577
+
578
+ /** @var MessageInterface|MockObject $messageMock */
579
+ $ messageMock = $ this ->getMockBuilder (MessageInterface::class)
580
+ ->getMock ();
581
+
582
+ /** @var Collection|MockObject $collectionMock */
583
+ $ collectionMock = $ this ->getMockBuilder (Collection::class)
584
+ ->disableOriginalConstructor ()
585
+ ->getMock ();
586
+ $ collectionMock ->expects ($ this ->once ())
587
+ ->method ('getItems ' )
588
+ ->willReturn ([$ messageMock ]);
589
+
590
+ $ this ->managerMock ->expects ($ this ->once ())
591
+ ->method ('getMessages ' )
592
+ ->with (true , null )
593
+ ->willReturn ($ collectionMock );
594
+
595
+ /* Test that getCookiePath is called during cookie setup */
596
+ $ this ->sessionConfigMock ->expects ($ this ->once ())
597
+ ->method ('getCookiePath ' )
598
+ ->willReturn ('/pub ' );
599
+ $ cookieMetadataMock ->expects ($ this ->once ())
600
+ ->method ('setPath ' )
601
+ ->with ('/pub ' )
602
+ ->willReturn ($ cookieMetadataMock );
603
+
604
+ $ this ->model ->afterRenderResult ($ resultMock , $ resultMock );
605
+ }
552
606
}
0 commit comments