/** * @magentoConfigFixture current_store persistent/options/enabled 1 * @magentoConfigFixture current_store persistent/options/remember_enabled 1 * @magentoConfigFixture current_store persistent/options/remember_default 1 * @magentoAppArea frontend * @magentoAppIsolation enabled */ public function testEmulateWelcomeBlock() { $this->_customerSession->loginById(1); $httpContext = new \Magento\Framework\App\Http\Context(); $httpContext->setValue(Context::CONTEXT_AUTH, 1, 1); $block = $this->_objectManager->create('Magento\\Sales\\Block\\Reorder\\Sidebar', ['httpContext' => $httpContext]); $this->_observer->emulateWelcomeBlock($block); $customerName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId()))); $translation = __('Welcome, %1!', $customerName); $this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome()); $this->_customerSession->logout(); }
/** * @magentoAppArea frontend * @magentoAppIsolation enabled * @magentoConfigFixture current_store persistent/options/shopping_cart 1 * @magentoConfigFixture current_store persistent/options/logout_clear 0 * @magentoConfigFixture current_store persistent/options/enabled 1 */ public function testEmulateCustomer() { $observer = new \Magento\Framework\Event\Observer(); $this->_customerSession->loginById(1); $this->_customerSession->logout(); $this->assertNull($this->_customerSession->getCustomerId()); $this->assertEquals(\Magento\Customer\Service\V1\CustomerGroupServiceInterface::NOT_LOGGED_IN_ID, $this->_customerSession->getCustomerGroupId()); $this->_observer->emulateCustomer($observer); $customer = $this->_customerAccountService->getCustomer($this->_persistentSessionHelper->getSession()->getCustomerId()); $this->assertEquals($customer->getId(), $this->_customerSession->getCustomerId()); $this->assertEquals($customer->getGroupId(), $this->_customerSession->getCustomerGroupId()); }
public function testPreventExpressCheckoutEmpty() { $this->_customerSession->expects($this->any())->method('isLoggedIn')->will($this->returnValue(false)); $this->_persistentSession->expects($this->any())->method('isPersistent')->will($this->returnValue(true)); $this->_event->setControllerAction(null); $this->_model->preventExpressCheckout($this->_observer); $this->_event->setControllerAction(new \StdClass()); $this->_model->preventExpressCheckout($this->_observer); $expectedActionName = 'realAction'; $unexpectedActionName = 'notAction'; $request = new \Magento\Framework\Object(); $request->setActionName($unexpectedActionName); $expressRedirectMock = $this->getMockBuilder('Magento\\Checkout\\Controller\\Express\\RedirectLoginInterface')->disableOriginalConstructor()->setMethods(array('getActionFlagList', 'getResponse', 'getCustomerBeforeAuthUrl', 'getLoginUrl', 'getRedirectActionName', 'getRequest'))->getMock(); $expressRedirectMock->expects($this->any())->method('getRequest')->will($this->returnValue($request)); $expressRedirectMock->expects($this->any())->method('getRedirectActionName')->will($this->returnValue($expectedActionName)); $this->_event->setControllerAction($expressRedirectMock); $this->_model->preventExpressCheckout($this->_observer); $expectedAuthUrl = 'expectedAuthUrl'; $request->setActionName($expectedActionName); $this->_url->expects($this->once())->method('getUrl')->will($this->returnValue($expectedAuthUrl)); $this->_expressRedirectHelper->expects($this->once())->method('redirectLogin')->with($expressRedirectMock, $expectedAuthUrl); $this->_model->preventExpressCheckout($this->_observer); }