/** * After generate Xml * * @param \Magento\Framework\View\LayoutInterface $subject * @param \Magento\Framework\View\LayoutInterface $result * @return \Magento\Framework\View\LayoutInterface */ public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, \Magento\Framework\View\LayoutInterface $result) { if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) { $this->persistentSession->setCustomerId(null); } return $result; }
/** * @covers \Magento\Persistent\Model\Session::_afterDeleteCommit * @covers \Magento\Persistent\Model\Session::removePersistentCookie */ public function testAfterDeleteCommit() { $cookiePath = 'some_path'; $this->_configMock->expects($this->once())->method('getCookiePath')->will($this->returnValue($cookiePath)); $this->_cookieMock->expects($this->once())->method('set')->with(\Magento\Persistent\Model\Session::COOKIE_NAME, $this->anything(), $this->anything(), $cookiePath); $this->_model->delete(); }
/** * Get Session model * * @return \Magento\Persistent\Model\Session */ public function getSession() { if ($this->_sessionModel === null) { $this->_sessionModel = $this->_sessionFactory->create(); $this->_sessionModel->loadByCookieKey(); } return $this->_sessionModel; }
public function testAfterGenerateXmlNoDepersonalize() { /** @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject $subjectMock */ $subjectMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false, true, true, ['isCacheable']); /** @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject $resultMock */ $resultMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false, true, true, []); $this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false); $this->persistentSessionMock->expects($this->never())->method('setCustomerId'); $this->assertEquals($resultMock, $this->plugin->afterGenerateXml($subjectMock, $resultMock)); }
/** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testLoadByCookieKey() { /** @var \Magento\Persistent\Model\Session $preSession */ $preSession = $this->objectManager->get('Magento\\Persistent\\Model\\SessionFactory')->create()->loadByCookieKey(); $this->assertNull($preSession->getCustomerId()); $this->session->setCustomerId(1)->save(); $this->session->setPersistentCookie(1000, '/'); /** @var \Magento\Persistent\Model\Session $postSession */ $postSession = $this->objectManager->get('Magento\\Persistent\\Model\\SessionFactory')->create()->loadByCookieKey(); $this->assertEquals(1, $postSession->getCustomerId()); }
/** * Run test afterGenerateXml method * * @param bool $result * * @dataProvider dataProviderAfterGenerateXml */ public function testAfterGenerateXml($result) { /** @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject $subjectMock */ $subjectMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false, true, true, ['isCacheable']); /** @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject $resultMock */ $resultMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false, true, true, []); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn($result); $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn($result); $this->requestMock->expects($this->any())->method('isAjax')->willReturn(!$result); $subjectMock->expects($this->any())->method('isCacheable')->willReturn($result); if ($result) { $this->persistentSessionMock->expects($this->once())->method('setCustomerId')->with(null); } else { $this->persistentSessionMock->expects($this->never())->method('setCustomerId')->with(null); } $this->assertEquals($resultMock, $this->plugin->afterGenerateXml($subjectMock, $resultMock)); }
/** * @param $numGetCookieCalls * @param $numCalls * @param int $cookieDuration * @param string $cookieValue * @param string $cookiePath * @dataProvider renewPersistentCookieDataProvider */ public function testRenewPersistentCookie($numGetCookieCalls, $numCalls, $cookieDuration = 1000, $cookieValue = 'cookieValue', $cookiePath = 'cookiePath') { $cookieMetadataMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata')->disableOriginalConstructor()->getMock(); $cookieMetadataMock->expects($this->exactly($numCalls))->method('setPath')->with($cookiePath)->will($this->returnSelf()); $cookieMetadataMock->expects($this->exactly($numCalls))->method('setDuration')->with($cookieDuration)->will($this->returnSelf()); $this->cookieMetadataFactoryMock->expects($this->exactly($numCalls))->method('createPublicCookieMetadata')->will($this->returnValue($cookieMetadataMock)); $this->cookieManagerMock->expects($this->exactly($numGetCookieCalls))->method('getCookie')->with(\Magento\Persistent\Model\Session::COOKIE_NAME)->will($this->returnValue($cookieValue)); $this->cookieManagerMock->expects($this->exactly($numCalls))->method('setPublicCookie')->with(\Magento\Persistent\Model\Session::COOKIE_NAME, $cookieValue, $cookieMetadataMock); $this->session->renewPersistentCookie($cookieDuration, $cookiePath); }