/** * @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(); }
/** * @dataProvider processProvider * @param bool $isPost */ public function testProcess($isPost) { $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost)); if ($isPost) { $this->cookieMock->expects($this->once())->method('set'); } $this->version->process(); }
public function testGet() { //Data $formKey = 'test from key'; //Verification $this->cookieMock->expects($this->once())->method('get')->with(\Magento\Framework\App\PageCache\FormKey::COOKIE_NAME)->will($this->returnValue($formKey)); $this->assertEquals($formKey, $this->formKey->get()); }
/** * Handle private content message box cookie * Set cookie if it is not set. * Set or unset cookie on post request * In all other cases do nothing. */ public function testAfterDispatch() { $this->messageManagerMock->expects($this->once())->method('hasMessages')->will($this->returnValue(true)); $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue(true)); $this->cookieMock->expects($this->once())->method('set')->with($this->equalTo(MessageBox::COOKIE_NAME), 1, $this->equalTo(MessageBox::COOKIE_PERIOD), '/'); $this->assertInstanceOf('\\Magento\\Framework\\App\\ResponseInterface', $this->msgBox->afterDispatch($this->objectMock, $this->responseMock)); }
/** * @covers \Magento\Persistent\Model\Observer\Session::synchronizePersistentOnLogin */ public function testSynchronizePersistentOnLogin() { $event = new \Magento\Framework\Event(); $observer = new \Magento\Framework\Event\Observer(array('event' => $event)); /** @var \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerAccountService */ $customerAccountService = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface'); /** @var $customer \Magento\Customer\Service\V1\Data\Customer */ $customer = $customerAccountService->getCustomer(1); $event->setData('customer', $customer); $this->_persistentSession->setRememberMeChecked(true); $this->_cookieMock->expects($this->once())->method('set')->with(\Magento\Persistent\Model\Session::COOKIE_NAME, $this->anything(), $this->anything(), $this->_customerSession->getCookiePath()); $this->_model->synchronizePersistentOnLogin($observer); // check that persistent session has been stored for Customer /** @var \Magento\Persistent\Model\Session $sessionModel */ $sessionModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Persistent\\Model\\Session'); $sessionModel->loadByCustomerId(1); $this->assertEquals(1, $sessionModel->getCustomerId()); }
/** * @covers \Magento\Store\Model\StorageFactory::_checkCookieStore * @covers \Magento\Store\Model\StorageFactory::getActiveStoreByCode * @covers \Magento\Store\Model\StorageFactory::setCurrentStore * * @dataProvider getFromCookieDataProvider */ public function testGetFromCookie($scopeCode, $scopeType) { $this->_arguments['scopeCode'] = $scopeCode; $this->_arguments['scopeType'] = $scopeType; $this->_appStateMock->expects($this->once())->method('isInstalled')->will($this->returnValue(true)); $this->website->expects($this->any())->method('getDefaultGroupId')->will($this->returnValue(11)); $this->group->expects($this->any())->method('getDefaultStoreId')->will($this->returnValue(21)); $this->store->expects($this->once())->method('getId')->will($this->returnValue(21)); $this->store->expects($this->once())->method('getIsActive')->will($this->returnValue(true)); $this->storage->expects($this->any())->method('setCurrentStore')->with('store1'); $this->_objectManagerMock->expects($this->once())->method('create')->will($this->returnValue($this->storage)); $this->_cookie->expects($this->atLeastOnce())->method('get')->will($this->returnValue('store1')); $this->assertEquals($this->storage, $this->_model->get($this->_arguments)); }
public function testLoadValidOrderStoredCookie() { $this->sessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $orderMock = $this->getMock('Magento\\Sales\\Model\\Order', ['getProtectCode', 'loadByIncrementId', 'getId', 'getBillingAddress', '__wakeup'], [], '', false); $protectedCode = 'protectedCode'; $incrementId = 1; $cookieData = $protectedCode . ':' . $incrementId; $cookieDataHash = base64_encode($cookieData); $this->orderFactoryMock->expects($this->once())->method('create')->will($this->returnValue($orderMock)); $this->cookieMock->expects($this->exactly(3))->method('get')->with(Guest::COOKIE_NAME)->will($this->returnValue($cookieDataHash)); $orderMock->expects($this->once())->method('loadByIncrementId')->with($incrementId); $orderMock->expects($this->exactly(1))->method('getId')->will($this->returnValue($incrementId)); $orderMock->expects($this->once())->method('getProtectCode')->will($this->returnValue($protectedCode)); $this->cookieMock->expects($this->once())->method('renew')->with(Guest::COOKIE_NAME, Guest::COOKIE_LIFETIME, Guest::COOKIE_PATH); $requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false); $responseMock = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false); $this->assertTrue($this->guest->loadValidOrder($requestMock, $responseMock)); }
public function testSendVaryEmptyData() { $this->_cookieMock->expects($this->once())->method('set')->with(Http::COOKIE_VARY_STRING, null, -1, '/'); $this->_model->sendVary(); }