@@ -73,6 +73,21 @@ class LoginTest extends \PHPUnit_Framework_TestCase
7373 */
7474 protected $ redirectMock ;
7575
76+ /**
77+ * @var \Magento\Framework\Stdlib\CookieManagerInterface| \PHPUnit_Framework_MockObject_MockObject
78+ */
79+ private $ cookieManager ;
80+
81+ /**
82+ * @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory| \PHPUnit_Framework_MockObject_MockObject
83+ */
84+ private $ cookieMetadataFactory ;
85+
86+ /**
87+ * @var \Magento\Framework\Stdlib\Cookie\CookieMetadata| \PHPUnit_Framework_MockObject_MockObject
88+ */
89+ private $ cookieMetadata ;
90+
7691 protected function setUp ()
7792 {
7893 $ this ->request = $ this ->getMockBuilder ('Magento\Framework\App\Request\Http ' )
@@ -105,14 +120,13 @@ protected function setUp()
105120 '' ,
106121 false
107122 );
108- $ this ->customerAccountManagementMock =
109- $ this ->getMock (
110- '\Magento\Customer\Model\AccountManagement ' ,
111- ['authenticate ' ],
112- [],
113- '' ,
114- false
115- );
123+ $ this ->customerAccountManagementMock = $ this ->getMock (
124+ '\Magento\Customer\Model\AccountManagement ' ,
125+ ['authenticate ' ],
126+ [],
127+ '' ,
128+ false
129+ );
116130
117131 $ this ->jsonHelperMock = $ this ->getMock (
118132 '\Magento\Framework\Json\Helper\Data ' ,
@@ -130,6 +144,16 @@ protected function setUp()
130144 ->setMethods (['create ' ])
131145 ->getMock ();
132146
147+ $ this ->cookieManager = $ this ->getMockBuilder (\Magento \Framework \Stdlib \CookieManagerInterface::class)
148+ ->setMethods (['getCookie ' , 'deleteCookie ' ])
149+ ->getMockForAbstractClass ();
150+ $ this ->cookieMetadataFactory = $ this ->getMockBuilder (\Magento \Framework \Stdlib \Cookie \CookieMetadataFactory::class)
151+ ->disableOriginalConstructor ()
152+ ->getMock ();
153+ $ this ->cookieMetadata = $ this ->getMockBuilder (\Magento \Framework \Stdlib \Cookie \CookieMetadata::class)
154+ ->disableOriginalConstructor ()
155+ ->getMock ();
156+
133157 $ this ->resultRaw = $ this ->getMockBuilder ('Magento\Framework\Controller\Result\Raw ' )
134158 ->disableOriginalConstructor ()
135159 ->getMock ();
@@ -158,6 +182,8 @@ protected function setUp()
158182 'resultJsonFactory ' => $ this ->resultJsonFactory ,
159183 'objectManager ' => $ this ->objectManager ,
160184 'customerAccountManagement ' => $ this ->customerAccountManagementMock ,
185+ 'cookieManager ' => $ this ->cookieManager ,
186+ 'cookieMetadataFactory ' => $ this ->cookieMetadataFactory
161187 ]
162188 );
163189 }
@@ -209,6 +235,22 @@ public function testLogin()
209235 $ this ->object ->setAccountRedirect ($ redirectMock );
210236 $ redirectMock ->expects ($ this ->once ())->method ('getRedirectCookie ' )->willReturn ('some_url1 ' );
211237
238+ $ this ->cookieManager ->expects ($ this ->once ())
239+ ->method ('getCookie ' )
240+ ->with ('mage-cache-sessid ' )
241+ ->willReturn (true );
242+ $ this ->cookieMetadataFactory ->expects ($ this ->once ())
243+ ->method ('createCookieMetadata ' )
244+ ->willReturn ($ this ->cookieMetadata );
245+ $ this ->cookieMetadata ->expects ($ this ->once ())
246+ ->method ('setPath ' )
247+ ->with ('/ ' )
248+ ->willReturnSelf ();
249+ $ this ->cookieManager ->expects ($ this ->once ())
250+ ->method ('deleteCookie ' )
251+ ->with ('mage-cache-sessid ' , $ this ->cookieMetadata )
252+ ->willReturnSelf ();
253+
212254 $ scopeConfigMock = $ this ->getMock (\Magento \Framework \App \Config \ScopeConfigInterface::class);
213255 $ this ->object ->setScopeConfig ($ scopeConfigMock );
214256 $ scopeConfigMock ->expects ($ this ->once ())->method ('getValue ' )
0 commit comments