1616use Magento \Framework \Stdlib \Cookie \PublicCookieMetadata ;
1717use Magento \Framework \Stdlib \CookieManagerInterface ;
1818use Magento \Framework \Translate \InlineInterface ;
19+ use Magento \Framework \Session \Config \ConfigInterface ;
1920use Magento \Framework \View \Element \Message \InterpretationStrategyInterface ;
2021use Magento \Theme \Controller \Result \MessagePlugin ;
2122use PHPUnit \Framework \MockObject \MockObject ;
@@ -47,6 +48,11 @@ class MessagePluginTest extends TestCase
4748 /** @var InlineInterface|MockObject */
4849 private $ inlineTranslateMock ;
4950
51+ /**
52+ * @var ConfigInterface|MockObject
53+ */
54+ protected $ sessionConfigMock ;
55+
5056 protected function setUp (): void
5157 {
5258 $ this ->cookieManagerMock = $ this ->getMockBuilder (CookieManagerInterface::class)
@@ -62,14 +68,17 @@ protected function setUp(): void
6268 ->getMock ();
6369 $ this ->inlineTranslateMock = $ this ->getMockBuilder (InlineInterface::class)
6470 ->getMockForAbstractClass ();
71+ $ this ->sessionConfigMock = $ this ->getMockBuilder (ConfigInterface::class)
72+ ->getMockForAbstractClass ();
6573
6674 $ this ->model = new MessagePlugin (
6775 $ this ->cookieManagerMock ,
6876 $ this ->cookieMetadataFactoryMock ,
6977 $ this ->managerMock ,
7078 $ this ->interpretationStrategyMock ,
7179 $ this ->serializerMock ,
72- $ this ->inlineTranslateMock
80+ $ this ->inlineTranslateMock ,
81+ $ this ->sessionConfigMock
7382 );
7483 }
7584
@@ -549,4 +558,49 @@ function ($data) {
549558
550559 $ this ->assertEquals ($ resultMock , $ this ->model ->afterRenderResult ($ resultMock , $ resultMock ));
551560 }
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+ }
552606}
0 commit comments