/** * @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()); }
public function testSetPersistentCookie() { $cookiePath = 'some_path'; $duration = 1000; $key = 'sessionKey'; $this->session->setKey($key); $cookieMetadataMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata')->disableOriginalConstructor()->getMock(); $cookieMetadataMock->expects($this->once())->method('setPath')->with($cookiePath)->will($this->returnSelf()); $cookieMetadataMock->expects($this->once())->method('setDuration')->with($duration)->will($this->returnSelf()); $cookieMetadataMock->expects($this->once())->method('setHttpOnly')->with(true)->will($this->returnSelf()); $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->will($this->returnValue($cookieMetadataMock)); $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with(\Magento\Persistent\Model\Session::COOKIE_NAME, $key, $cookieMetadataMock); $this->session->setPersistentCookie($duration, $cookiePath); }