Skip to content

Commit 8715221

Browse files
author
Patrick McLain
committed
Update Ajax LoginTest
1 parent 661f8fa commit 8715221

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

app/code/Magento/Customer/Test/Unit/Controller/Ajax/LoginTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
protected $cookieManager;
80+
81+
/**
82+
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory| \PHPUnit_Framework_MockObject_MockObject
83+
*/
84+
protected $cookieMetadataFactory;
85+
86+
/**
87+
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadata| \PHPUnit_Framework_MockObject_MockObject
88+
*/
89+
protected $cookieMetadata;
90+
7691
protected function setUp()
7792
{
7893
$this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
@@ -100,6 +115,16 @@ protected function setUp()
100115
->setMethods(['create'])
101116
->getMock();
102117

118+
$this->cookieManager = $this->getMockBuilder(\Magento\Framework\Stdlib\CookieManagerInterface::class)
119+
->setMethods(['getCookie', 'deleteCookie'])
120+
->getMockForAbstractClass();
121+
$this->cookieMetadataFactory = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class)
122+
->disableOriginalConstructor()
123+
->getMock();
124+
$this->cookieMetadata = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadata::class)
125+
->disableOriginalConstructor()
126+
->getMock();
127+
103128
$this->resultRaw = $this->getMockBuilder(\Magento\Framework\Controller\Result\Raw::class)
104129
->disableOriginalConstructor()
105130
->getMock();
@@ -128,6 +153,8 @@ protected function setUp()
128153
'resultJsonFactory' => $this->resultJsonFactory,
129154
'objectManager' => $this->objectManager,
130155
'customerAccountManagement' => $this->customerAccountManagementMock,
156+
'cookieManager' => $this->cookieManager,
157+
'cookieMetadataFactory' => $this->cookieMetadataFactory
131158
]
132159
);
133160
}
@@ -179,6 +206,22 @@ public function testLogin()
179206
$this->object->setAccountRedirect($redirectMock);
180207
$redirectMock->expects($this->once())->method('getRedirectCookie')->willReturn('some_url1');
181208

209+
$this->cookieManager->expects($this->once())
210+
->method('getCookie')
211+
->with('mage-cache-sessid')
212+
->willReturn(true);
213+
$this->cookieMetadataFactory->expects($this->once())
214+
->method('createCookieMetadata')
215+
->willReturn($this->cookieMetadata);
216+
$this->cookieMetadata->expects($this->once())
217+
->method('setPath')
218+
->with('/')
219+
->willReturnSelf();
220+
$this->cookieManager->expects($this->once())
221+
->method('deleteCookie')
222+
->with('mage-cache-sessid', $this->cookieMetadata)
223+
->willReturnSelf();
224+
182225
$scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
183226
$this->object->setScopeConfig($scopeConfigMock);
184227
$scopeConfigMock->expects($this->once())->method('getValue')

0 commit comments

Comments
 (0)