本文整理汇总了PHP中Magento\Customer\Model\Session::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::expects方法的具体用法?PHP Session::expects怎么用?PHP Session::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Model\Session
的用法示例。
在下文中一共展示了Session::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSubscribe
public function testSubscribe()
{
$email = 'subscriber_email@magento.com';
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(['subscriber_status' => 3, 'subscriber_email' => $email, 'name' => 'subscriber_name']);
$this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field');
$this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true);
$this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true);
$customerDataModel = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface');
$this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel);
$this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1);
$customerDataModel->expects($this->any())->method('getEmail')->willReturn($email);
$this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel);
$customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1);
$customerDataModel->expects($this->any())->method('getId')->willReturn(1);
$this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf();
$storeModel = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId'], [], '', false);
$this->scopeConfig->expects($this->any())->method('getValue')->willReturn('owner_email@magento.com');
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
$storeModel->expects($this->any())->method('getId')->willReturn(1);
$transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface');
$this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport);
$transport->expects($this->any())->method('sendMessage')->willReturnSelf();
$inlineTranslation = $this->getMock('Magento\\Framework\\Translate\\Inline\\StateInterface');
$inlineTranslation->expects($this->any())->method('resume')->willReturnSelf();
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
$this->assertEquals(1, $this->subscriber->subscribe($email));
}
示例2: testAroundDispatch
/**
* Test aroundDispatch
*/
public function testAroundDispatch()
{
$this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(1));
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
$this->httpContextMock->expects($this->atLeastOnce())->method('setValue')->will($this->returnValueMap([[Context::CONTEXT_GROUP, 'UAH', $this->httpContextMock], [Context::CONTEXT_AUTH, 0, $this->httpContextMock]]));
$this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
}
示例3: testExecute
/**
* @return void
*/
public function testExecute()
{
$customerId = 7;
$captchaValue = 'some-value';
$email = 'test@example.com';
$redirectUrl = 'http://magento.com/customer/account/edit/';
$captcha = $this->getMock('Magento\\Captcha\\Model\\DefaultModel', [], [], '', false);
$captcha->expects($this->once())->method('isRequired')->willReturn(true);
$captcha->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
$this->helperMock->expects($this->once())->method('getCaptcha')->with(\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captcha);
$response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
$request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID => $captchaValue]);
$controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
$controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));
$controller->expects($this->any())->method('getResponse')->will($this->returnValue($response));
$this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, \Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captchaValue);
$customerDataMock = $this->getMock('\\Magento\\Customer\\Model\\Data\\Customer', [], [], '', false);
$this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomer')->willReturn($customerDataMock);
$this->authenticationMock->expects($this->once())->method('processAuthenticationFailure')->with($customerId);
$this->authenticationMock->expects($this->once())->method('isLocked')->with($customerId)->willReturn(true);
$this->customerSessionMock->expects($this->once())->method('logout');
$this->customerSessionMock->expects($this->once())->method('start');
$this->scopeConfigMock->expects($this->once())->method('getValue')->with('contact/email/recipient_email')->willReturn($email);
$message = __('The account is locked. Please wait and try again or contact %1.', $email);
$this->messageManagerMock->expects($this->exactly(2))->method('addError')->withConsecutive([$message], [__('Incorrect CAPTCHA')]);
$this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirectMock->expects($this->once())->method('redirect')->with($response, '*/*/edit')->willReturn($redirectUrl);
$this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
}
示例4: testExecute
public function testExecute()
{
$event = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
/** @var $event \Magento\Framework\Event\Observer */
$this->customerSession->expects($this->once())->method('setWishlistItemCount')->with($this->equalTo(0));
$this->observer->execute($event);
}
示例5: setUp
protected function setUp()
{
$this->markTestIncomplete();
$this->messageManager = $this->getMockForAbstractClass('Magento\\Framework\\Message\\ManagerInterface');
$this->config = $this->getMock('Magento\\Paypal\\Model\\Config', [], [], '', false);
$this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
$this->quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
$this->quote->expects($this->any())->method('hasItems')->will($this->returnValue(true));
$this->redirect = $this->getMockForAbstractClass('Magento\\Framework\\App\\Response\\RedirectInterface');
$this->response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$this->customerData = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
$this->checkout = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout', [], [], '', false);
$this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false);
$this->customerSession->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($this->customerData));
$this->checkoutSession = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
$this->checkoutFactory = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout\\Factory', [], [], '', false);
$this->checkoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->checkout));
$this->checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote));
$this->session = $this->getMock('Magento\\Framework\\Session\\Generic', [], [], '', false);
$objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
$this->objectManagerCallback = function ($className) {
if ($className == 'Magento\\Paypal\\Model\\Config') {
return $this->config;
}
return $this->getMock($className, [], [], '', false);
};
$objectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) {
return call_user_func($this->objectManagerCallback, $className);
}));
$objectManager->expects($this->any())->method('create')->will($this->returnCallback(function ($className) {
return call_user_func($this->objectManagerCallback, $className);
}));
$helper = new ObjectManagerHelper($this);
$this->model = $helper->getObject('\\Magento\\\\Paypal\\Controller\\Express\\' . $this->name, ['messageManager' => $this->messageManager, 'response' => $this->response, 'redirect' => $this->redirect, 'request' => $this->request, 'customerSession' => $this->customerSession, 'checkoutSession' => $this->checkoutSession, 'checkoutFactory' => $this->checkoutFactory, 'paypalSession' => $this->session, 'objectManager' => $objectManager]);
}
示例6: testExecute
/**
* @return void
*/
public function testExecute()
{
$formId = 'user_login';
$login = 'login';
$loginParams = ['username' => $login];
$customerId = 7;
$redirectUrl = 'http://magento.com/customer/account/login/';
$captchaValue = 'some-value';
$captcha = $this->getMock('Magento\\Captcha\\Model\\DefaultModel', [], [], '', false);
$captcha->expects($this->once())->method('isRequired')->with($login)->willReturn(true);
$captcha->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
$captcha->expects($this->once())->method('logAttempt')->with($login);
$this->helperMock->expects($this->once())->method('getCaptcha')->with($formId)->willReturn($captcha);
$response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$response->expects($this->once())->method('setRedirect')->with($redirectUrl);
$request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
$request->expects($this->any())->method('getPost')->with('login')->willReturn($loginParams);
$controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
$controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));
$controller->expects($this->any())->method('getResponse')->will($this->returnValue($response));
$this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, $formId)->willReturn($captchaValue);
$customerDataMock = $this->getMock('\\Magento\\Customer\\Model\\Data\\Customer', ['getId'], [], '', false);
$customerDataMock->expects($this->once())->method('getId')->willReturn($customerId);
$this->customerRepositoryMock->expects($this->once())->method('get')->with($login)->willReturn($customerDataMock);
$this->authenticationMock->expects($this->once())->method('processAuthenticationFailure')->with($customerId);
$this->messageManagerMock->expects($this->once())->method('addError')->with(__('Incorrect CAPTCHA'));
$this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->customerSessionMock->expects($this->once())->method('setUsername')->with($login);
$this->customerSessionMock->expects($this->once())->method('getBeforeAuthUrl')->willReturn(false);
$this->customerUrlMock->expects($this->once())->method('getLoginUrl')->willReturn($redirectUrl);
$this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
}
示例7: testExecute
/**
* Executes the controller action and asserts non exception logic
*/
public function testExecute()
{
$objectManager = new ObjectManagerHelper($this);
$customerId = 1;
$this->customerSession->expects($this->any())->method('getCustomerId')->willReturn($customerId);
$notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\NewCard', ['resultPageFactory' => $this->resultPageFactory, 'customerSession' => $this->customerSession]);
$this->assertSame($this->resultPage, $notification->execute());
}
示例8: testGetUserEmail
public function testGetUserEmail()
{
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true);
$customerDataObject = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
$customerDataObject->expects($this->once())->method('getEmail')->willReturn('customer@email.com');
$this->customerSessionMock->expects($this->once())->method('getCustomerDataObject')->willReturn($customerDataObject);
$this->assertEquals('customer@email.com', $this->helper->getUserEmail());
}
示例9: testGetUserEmail
public function testGetUserEmail()
{
$this->_customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
$customerDataObject = $this->getMock('\\Magento\\Customer\\Service\\V1\\Data\\Customer', [], [], '', false);
$customerDataObject->expects($this->once())->method('getEmail')->will($this->returnValue('customer@email.com'));
$this->_customerSession->expects($this->once())->method('getCustomerDataObject')->will($this->returnValue($customerDataObject));
$this->assertEquals('customer@email.com', $this->_helper->getUserEmail());
}
示例10: testGetCustomerSessionTokens
public function testGetCustomerSessionTokens()
{
$customerId = 1;
$token = $this->getMock(PaymentTokenInterface::class);
$expectation = [$token];
$this->customerSession->expects(static::once())->method('getCustomerId')->willReturn($customerId);
$this->paymentTokenManagement->expects(static::once())->method('getVisibleAvailableTokens')->with($customerId)->willReturn($expectation);
static::assertEquals($expectation, $this->tokenManagement->getCustomerSessionTokens());
}
示例11: testSaveActionWithException
public function testSaveActionWithException()
{
$this->formKeyValidatorMock->expects($this->once())->method('validate')->will($this->returnValue(true));
$this->customerSessionMock->expects($this->any())->method('getCustomerId')->will($this->returnValue(1));
$this->customerRepositoryMock->expects($this->any())->method('getById')->will($this->throwException(new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'customerId', 'value' => 'value']))));
$this->redirectMock->expects($this->once())->method('redirect')->with($this->responseMock, 'customer/account/', []);
$this->messageManagerMock->expects($this->never())->method('addSuccess');
$this->messageManagerMock->expects($this->once())->method('addError')->with('Something went wrong while saving your subscription.');
$this->action->execute();
}
示例12: testBeforeStart
/**
* @param bool $result
* @param string $callCount
* @return void
* @dataProvider testBeforeStartDataProvider
*/
public function testBeforeStart($result, $callCount)
{
$phpSessionCookieName = 'PHPSESSID';
$frontendSessionCookieName = 'mage-cache-sessid';
$this->sessionManager->expects($this->once())->method('getName')->willReturn($phpSessionCookieName);
$this->cookieManager->expects($this->exactly(2))->method('getCookie')->withConsecutive([$phpSessionCookieName], [$frontendSessionCookieName])->willReturnOnConsecutiveCalls(false, $result);
$this->metadataFactory->expects($this->{$callCount}())->method('createCookieMetadata')->willReturn($this->metadata);
$this->metadata->expects($this->{$callCount}())->method('setPath')->with('/');
$this->cookieManager->expects($this->{$callCount}())->method('deleteCookie')->with('mage-cache-sessid', $this->metadata);
$this->plugin->beforeStart($this->sessionManager);
}
示例13: testCustomerLoginLoggedInFalse
/**
* @return void
*/
public function testCustomerLoginLoggedInFalse()
{
$observerMock = $this->getObserverMock(111);
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
$this->customerSessionMock->expects($this->never())->method('getCustomerId');
$this->customerVisitorMock->expects($this->never())->method('getId');
$this->productCompModelMock->expects($this->never())->method('updateCustomerFromVisitor')->willReturnSelf();
$this->productCompModelMock->expects($this->never())->method('calculate')->willReturnSelf();
$this->productIndexMock->expects($this->never())->method('updateCustomerFromVisitor')->willReturnSelf();
$this->productIndexMock->expects($this->never())->method('calculate')->willReturnSelf();
$this->observer->execute($observerMock);
}
示例14: testGetConfig
/**
* @param int $customerId
* @param bool $vaultEnabled
* @dataProvider customerIdProvider
*/
public function testGetConfig($customerId, $vaultEnabled)
{
$storeId = 1;
$vaultPaymentCode = 'vault_payment';
$expectedConfiguration = ['vault' => [$vaultPaymentCode => ['is_enabled' => $vaultEnabled]]];
$this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId);
$this->storeManager->expects(static::exactly(2))->method('getStore')->willReturn($this->store);
$this->store->expects(static::exactly(2))->method('getId')->willReturn($storeId);
$this->paymentDataHelper->expects(static::once())->method('getStoreMethods')->with($storeId)->willReturn([$this->vaultPayment]);
$this->vaultPayment->expects(static::once())->method('getCode')->willReturn($vaultPaymentCode);
$this->vaultPayment->expects($customerId !== null ? static::once() : static::never())->method('isActive')->with($storeId)->willReturn($vaultEnabled);
static::assertEquals($expectedConfiguration, $this->vaultConfigProvider->getConfig());
}
示例15: testDispatchNotLoggedIn
/**
* Executes the dispatch override
*/
public function testDispatchNotLoggedIn()
{
$objectManager = new ObjectManagerHelper($this);
$this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
$this->resultRedirect->expects($this->any())->method('setPath')->willReturnSelf();
$this->customerSession->expects($this->any())->method('authenticate')->willReturn(false);
$this->config->expects($this->any())->method('useVault')->willReturn(true);
/**
* @var \Magento\Framework\App\RequestInterface $requestInterface
*/
$requestInterface = $this->getMockBuilder('\\Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
$notification = $objectManager->getObject('Magento\\Braintree\\Controller\\MyCreditCards', ['customerSession' => $this->customerSession, 'resultRedirectFactory' => $this->resultRedirectFactory, 'config' => $this->config, 'customerUrl' => $this->customerUrl, 'response' => $this->_response]);
$this->assertSame($this->_response, $notification->dispatch($requestInterface));
}