32 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33 $this->configMock = $this->createMock(\
Magento\Framework\Session\Config\ConfigInterface::class);
34 $this->cookieManagerMock = $this->createMock(\
Magento\Framework\Stdlib\CookieManagerInterface::class);
35 $this->cookieMetadataFactoryMock = $this->getMockBuilder(
36 \
Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class
37 )->disableOriginalConstructor()
40 $resourceMock = $this->getMockForAbstractClass(
47 [
'__wakeup',
'getIdFieldName',
'getConnection',
'beginTransaction',
'delete',
'commit',
'rollBack']
50 $actionValidatorMock = $this->createMock(\
Magento\Framework\Model\ActionValidator\RemoveAction::class);
51 $actionValidatorMock->expects($this->any())->method(
'isAllowed')->will($this->returnValue(
true));
54 \
Magento\Framework\Model\Context::class,
56 'actionValidator' => $actionValidatorMock,
60 $this->session =
$helper->getObject(
61 \
Magento\Persistent\Model\Session::class,
63 'sessionConfig' => $this->configMock,
64 'cookieManager' => $this->cookieManagerMock,
65 'context' => $context,
66 'cookieMetadataFactory' => $this->cookieMetadataFactoryMock,
67 'request' => $this->createMock(\
Magento\Framework\
App\Request\Http::class),
68 'resource' => $resourceMock,
75 $this->cookieManagerMock->expects($this->once())
77 ->with(\
Magento\Persistent\Model\Session::COOKIE_NAME)
78 ->will($this->returnValue(
null));
79 $this->session->loadByCookieKey(
null);
87 $cookiePath =
'some_path';
88 $this->configMock->expects($this->once())->method(
'getCookiePath')->will($this->returnValue($cookiePath));
89 $cookieMetadataMock = $this->getMockBuilder(\
Magento\Framework\Stdlib\Cookie\SensitiveCookieMetadata::class)
90 ->disableOriginalConstructor()
92 $cookieMetadataMock->expects($this->once())
95 ->will($this->returnSelf());
96 $this->cookieMetadataFactoryMock->expects($this->once())
97 ->method(
'createSensitiveCookieMetadata')
98 ->will($this->returnValue($cookieMetadataMock));
99 $this->cookieManagerMock->expects(
104 \
Magento\Persistent\Model\Session::COOKIE_NAME,
107 $this->session->afterDeleteCommit();
112 $cookiePath =
'some_path';
115 $this->session->setKey($key);
116 $cookieMetadataMock = $this->getMockBuilder(\
Magento\Framework\Stdlib\Cookie\PublicCookieMetadata::class)
117 ->disableOriginalConstructor()
119 $cookieMetadataMock->expects($this->once())
122 ->will($this->returnSelf());
123 $cookieMetadataMock->expects($this->once())
124 ->method(
'setDuration')
126 ->will($this->returnSelf());
127 $cookieMetadataMock->expects($this->once())
128 ->method(
'setSecure')
130 ->will($this->returnSelf());
131 $cookieMetadataMock->expects($this->once())
132 ->method(
'setHttpOnly')
134 ->will($this->returnSelf());
135 $this->cookieMetadataFactoryMock->expects($this->once())
136 ->method(
'createPublicCookieMetadata')
137 ->will($this->returnValue($cookieMetadataMock));
138 $this->cookieManagerMock->expects($this->once())
139 ->method(
'setPublicCookie')
141 \
Magento\Persistent\Model\Session::COOKIE_NAME,
145 $this->session->setPersistentCookie($duration, $cookiePath);
159 $cookieDuration = 1000,
160 $cookieValue =
'cookieValue',
161 $cookiePath =
'cookiePath' 163 $cookieMetadataMock = $this->getMockBuilder(\
Magento\Framework\Stdlib\Cookie\PublicCookieMetadata::class)
164 ->disableOriginalConstructor()
166 $cookieMetadataMock->expects($this->exactly($numCalls))
169 ->will($this->returnSelf());
170 $cookieMetadataMock->expects($this->exactly($numCalls))
171 ->method(
'setDuration')
172 ->with($cookieDuration)
173 ->will($this->returnSelf());
174 $cookieMetadataMock->expects($this->exactly($numCalls))
175 ->method(
'setSecure')
177 ->will($this->returnSelf());
178 $cookieMetadataMock->expects($this->exactly($numCalls))
179 ->method(
'setHttpOnly')
181 ->will($this->returnSelf());
182 $this->cookieMetadataFactoryMock->expects($this->exactly($numCalls))
183 ->method(
'createPublicCookieMetadata')
184 ->will($this->returnValue($cookieMetadataMock));
185 $this->cookieManagerMock->expects($this->exactly($numGetCookieCalls))
186 ->method(
'getCookie')
187 ->with(\
Magento\Persistent\Model\Session::COOKIE_NAME)
188 ->will($this->returnValue($cookieValue));
189 $this->cookieManagerMock->expects($this->exactly($numCalls))
190 ->method(
'setPublicCookie')
192 \
Magento\Persistent\Model\Session::COOKIE_NAME,
196 $this->session->renewPersistentCookie($cookieDuration, $cookiePath);
207 'no duration' => [0, 0, null ],
208 'no cookie' => [1, 0, 1000,
null],
testRenewPersistentCookie( $numGetCookieCalls, $numCalls, $cookieDuration=1000, $cookieValue='cookieValue', $cookiePath='cookiePath')
testSetPersistentCookie()
$cookieMetadataFactoryMock
renewPersistentCookieDataProvider()
testLoadByCookieKeyWithNull()