Exemplo n.º 1
0
 public function testSubscribe()
 {
     $email = '*****@*****.**';
     $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('*****@*****.**');
     $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));
 }
 /**
  * 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));
 }
 /**
  * @return void
  */
 public function testExecute()
 {
     $customerId = 7;
     $captchaValue = 'some-value';
     $email = '*****@*****.**';
     $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]));
 }
 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);
 }
Exemplo n.º 5
0
 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]);
 }
 /**
  * @return void
  */
 public function testExecute()
 {
     $formId = 'user_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]));
 }
Exemplo n.º 7
0
 /**
  * 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());
 }
Exemplo n.º 8
0
 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('*****@*****.**');
     $this->customerSessionMock->expects($this->once())->method('getCustomerDataObject')->willReturn($customerDataObject);
     $this->assertEquals('*****@*****.**', $this->helper->getUserEmail());
 }
Exemplo n.º 9
0
 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('*****@*****.**'));
     $this->_customerSession->expects($this->once())->method('getCustomerDataObject')->will($this->returnValue($customerDataObject));
     $this->assertEquals('*****@*****.**', $this->_helper->getUserEmail());
 }
 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());
 }
Exemplo n.º 11
0
 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();
 }
Exemplo n.º 12
0
 /**
  * @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);
 }
Exemplo n.º 13
0
 /**
  * test get group price, customer group in session
  */
 public function testGroupPriceCustomerGroupInSession()
 {
     $this->productMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(null));
     $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(3));
     $this->productMock->expects($this->once())->method('getResource')->will($this->returnValue($this->productResourceMock));
     $this->productResourceMock->expects($this->once())->method('getAttribute')->with($this->equalTo('group_price'))->will($this->returnValue($this->attributeMock));
     $this->attributeMock->expects($this->once())->method('getBackend')->will($this->returnValue($this->backendMock));
     $this->backendMock->expects($this->once())->method('afterLoad')->with($this->equalTo($this->productMock))->will($this->returnValue($this->backendMock));
     $this->productMock->expects($this->once())->method('getData')->with($this->equalTo('group_price'), $this->equalTo(null))->will($this->returnValue([['cust_group' => 3, 'website_price' => 80]]));
     $this->assertEquals(80, $this->groupPrice->getValue());
 }
Exemplo n.º 14
0
 public function testGetWishlistWithIdAndCustomer()
 {
     $wishlist = $this->getMock('\\Magento\\Wishlist\\Model\\Wishlist', ['loadByCustomerId', 'load', 'getId', 'getCustomerId', '__wakeup'], [], '', false);
     $wishlist->expects($this->once())->method('load')->will($this->returnSelf());
     $wishlist->expects($this->any())->method('getId')->will($this->returnValue(1));
     $wishlist->expects($this->once())->method('getCustomerId')->will($this->returnValue(1));
     $this->wishlistFactory->expects($this->once())->method('create')->will($this->returnValue($wishlist));
     $this->request->expects($this->once())->method('getParam')->will($this->returnValue(1));
     $this->customerSession->expects($this->once())->method('getCustomerId')->will($this->returnValue(1));
     $this->assertEquals($wishlist, $this->wishlistProvider->getWishlist());
 }
 /**
  * @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);
 }
 /**
  * @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());
 }
Exemplo n.º 17
0
 /**
  * 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));
 }
 public function testGetCustomerSessionTokens()
 {
     $customerId = 1;
     $providerCode = 'vault_provider';
     $storeId = 1;
     $token = $this->getMock(PaymentTokenInterface::class);
     $expectation = [$token];
     $this->customerSessionMock->expects(self::once())->method('getCustomerId')->willReturn($customerId);
     $this->storeManager->expects(static::once())->method('getStore')->with(null)->willReturn($this->store);
     $this->store->expects(static::once())->method('getId')->willReturn($storeId);
     $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true);
     $this->vaultPayment->expects(static::once())->method('getProviderCode')->with($storeId)->willReturn($providerCode);
     $this->paymentTokenManagementMock->expects(static::once())->method('getVisibleAvailableTokens')->with($customerId, $providerCode)->willReturn($expectation);
     static::assertEquals($expectation, $this->tokenManagement->getCustomerSessionTokens());
 }
Exemplo n.º 19
0
 public function testExecuteWithException()
 {
     $token = 'token';
     $customerId = '11';
     $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturnMap([['token', null, $token], ['id', null, null]]);
     $this->sessionMock->expects($this->once())->method('getRpToken')->willReturn($token);
     $this->sessionMock->expects($this->once())->method('getRpCustomerId')->willReturn($customerId);
     $this->accountManagementMock->expects($this->once())->method('validateResetPasswordLinkToken')->with($customerId, $token)->willThrowException(new \Exception('Exception.'));
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('Your password reset link has expired.'))->willReturnSelf();
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->redirectFactoryMock->expects($this->once())->method('create')->with([])->willReturn($redirectMock);
     $redirectMock->expects($this->once())->method('setPath')->with('*/*/forgotpassword', [])->willReturnSelf();
     $this->assertEquals($redirectMock, $this->model->executeInternal());
 }
Exemplo n.º 20
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testEditPostActionWithoutErrors()
 {
     $customerId = 24;
     $address = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false);
     $loadedCustomer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], 'loadedCustomer', false);
     $loadedCustomer->expects($this->once())->method('getAddresses')->willReturn([$address, $address]);
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->redirectResultMock);
     $this->formKeyValidator->expects($this->once())->method('validate')->willReturn(true);
     $this->request->expects($this->once())->method('isPost')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->customerExtractor->expects($this->once())->method('extract')->willReturn($this->customer);
     $this->customer->expects($this->once())->method('setId')->with($customerId);
     $this->customer->expects($this->once())->method('getAddresses')->willReturn(null);
     $this->customerRepository->expects($this->exactly(2))->method('getById')->with($customerId)->willReturn($loadedCustomer);
     $this->customer->expects($this->once())->method('setAddresses')->with([$address, $address]);
     $this->request->expects($this->once())->method('getParam')->with('change_password')->willReturn(true);
     $this->request->expects($this->at(2))->method('getPost')->with('current_password', null)->willReturn(123);
     $this->request->expects($this->at(3))->method('getPost')->with('password', null)->willReturn(321);
     $this->request->expects($this->at(4))->method('getPost')->with('password_confirmation', null)->willReturn(321);
     $this->customerAccountManagement->expects($this->once())->method('changePassword');
     $this->customerRepository->expects($this->once())->method('save');
     $messageCollection = $this->getMock('Magento\\Framework\\Message\\Collection', [], [], '', false);
     $messageCollection->expects($this->once())->method('getCount')->willReturn(0);
     $this->messageManager->expects($this->once())->method('getMessages')->willReturn($messageCollection);
     $this->messageManager->expects($this->once())->method('addSuccess')->with('You saved the account information.');
     $this->redirectResultMock->expects($this->once())->method('setPath')->with('customer/account')->willReturn('http://test.com/customer/account/edit');
     $this->assertSame($this->redirectResultMock, $this->getController()->execute());
 }
 /**
  * @param bool $isLoggedIn
  * @param string $userKey
  * @param int $userId
  * @dataProvider catalogProductCompareAddProductDataProvider
  * @return void
  */
 public function testCatalogProductCompareAddProduct($isLoggedIn, $userKey, $userId)
 {
     $productId = 111;
     $customerId = 222;
     $visitorId = 333;
     $viewData = ['product_id' => $productId, $userKey => $userId];
     $observerMock = $this->getObserverMock($productId);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn($isLoggedIn);
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($customerId);
     $this->customerVisitorMock->expects($this->any())->method('getId')->willReturn($visitorId);
     $this->productCompModelMock->expects($this->any())->method('setData')->with($viewData)->willReturnSelf();
     $this->productCompModelMock->expects($this->any())->method('save')->willReturnSelf();
     $this->productCompModelMock->expects($this->any())->method('calculate')->willReturnSelf();
     $this->eventSaverMock->expects($this->once())->method('save');
     $this->observer->execute($observerMock);
 }
Exemplo n.º 22
0
 /**
  * @expectedException \Magento\Framework\Exception\NotFoundException
  */
 public function testBeforeDispatch()
 {
     $actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', [], [], '', false);
     $indexController = $this->getMock('Magento\\Wishlist\\Controller\\Index\\Index', [], [], '', false);
     $actionFlag->expects($this->once())->method('set')->with('', 'no-dispatch', true)->willReturn(true);
     $indexController->expects($this->once())->method('getActionFlag')->willReturn($actionFlag);
     $this->authenticationState->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->customerSession->expects($this->once())->method('authenticate')->willReturn(false);
     $this->redirector->expects($this->once())->method('getRefererUrl')->willReturn('http://referer-url.com');
     $this->request->expects($this->once())->method('getParams')->willReturn(['product' => 1]);
     $this->customerSession->expects($this->at(1))->method('__call')->with('getBeforeWishlistUrl', [])->willReturn(false);
     $this->customerSession->expects($this->at(2))->method('__call')->with('setBeforeWishlistUrl', ['http://referer-url.com'])->willReturn(false);
     $this->customerSession->expects($this->at(3))->method('__call')->with('setBeforeWishlistRequest', [['product' => 1]])->willReturn(true);
     $this->config->expects($this->once())->method('isSetFlag')->with('wishlist/general/active')->willReturn(false);
     $this->getPlugin()->beforeDispatch($indexController, $this->request);
 }
Exemplo n.º 23
0
 public function testConstructMethod()
 {
     $data = [];
     $customerId = 25;
     $this->customerSession->expects($this->once())->method('getCustomerId')->will($this->returnValue($customerId));
     $statuses = ['pending', 'processing', 'comlete'];
     $this->orderConfig->expects($this->once())->method('getVisibleOnFrontStatuses')->will($this->returnValue($statuses));
     $orderCollection = $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Collection', ['addFieldToSelect', 'addFieldToFilter', 'setOrder'], [], '', false, false);
     $orderCollection->expects($this->at(0))->method('addFieldToSelect')->with($this->equalTo('*'))->will($this->returnSelf());
     $orderCollection->expects($this->at(1))->method('addFieldToFilter')->with('customer_id', $this->equalTo($customerId))->will($this->returnSelf());
     $orderCollection->expects($this->at(2))->method('addFieldToFilter')->with('status', $this->equalTo(['in' => $statuses]))->will($this->returnSelf());
     $orderCollection->expects($this->at(3))->method('setOrder')->with('created_at', 'desc')->will($this->returnSelf());
     $this->orderCollectionFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($orderCollection));
     $this->model = new \Magento\Sales\Block\Order\History($this->context, $this->orderCollectionFactory, $this->customerSession, $this->orderConfig, $this->pageConfig, $data);
     $this->assertEquals($orderCollection, $this->model->getOrders());
 }
 public function testBeforeDispatch()
 {
     $customerId = 1;
     $customerGroupId = 1;
     $this->appState->expects($this->any())->method('getAreaCode')->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
     $this->request->expects($this->any())->method('isPost')->willReturn(true);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMockForAbstractClass();
     $customerMock->expects($this->any())->method('getGroupId')->willReturn($customerGroupId);
     $this->customerRepository->expects($this->any())->method('getById')->with($customerId)->willReturn($customerMock);
     $this->session->expects($this->any())->method('getCustomerId')->willReturn($customerId);
     $this->session->expects($this->any())->method('setCustomerData')->with($customerMock);
     $this->session->expects($this->any())->method('setCustomerGroupId')->with($customerGroupId);
     $this->session->expects($this->once())->method('regenerateId');
     $this->notificationStorage->expects($this->any())->method('isExists')->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId)->willReturn(true);
     $this->plugin->beforeDispatch($this->abstractAction, $this->request);
 }
Exemplo n.º 25
0
 /**
  * @param string $params
  * @dataProvider dataProcessNonce
  */
 public function testProcessNonceException($params = null, $exceptionMessage = null)
 {
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($params['customerId']);
     $countryCollectionMock = $this->getMockBuilder('\\Magento\\Directory\\Model\\Resource\\Country\\Collection')->disableOriginalConstructor()->getMock();
     $countryCollectionMock->expects($this->any())->method('addCountryCodeFilter')->willReturn($countryCollectionMock);
     $this->countryFactoryMock->expects($this->any())->method('create')->willReturn($countryCollectionMock);
     $this->configMock->expects($this->any())->method('canUseForCountry')->willReturn($params['canUseForCountry']);
     $this->configMock->expects($this->any())->method('canUseCcTypeForCountry')->willReturn($params['canUseCcTypeForCountry']);
     $this->helperMock->expects($this->any())->method('generateCustomerId')->willReturn($params['customerId']);
     $this->customerMock->expects($this->any())->method('load')->willReturn($this->customerMock);
     $this->customerFactoryMock->expects($this->any())->method('create')->willReturn($this->customerMock);
     if (is_object($params['paymentMethodObj'])) {
         if (!$params['optionsArray']['update']) {
             $this->braintreePaymentMethodMock->expects($this->once())->method('create')->willReturn($params['paymentMethodObj']);
         } else {
             $this->braintreePaymentMethodMock->expects($this->once())->method('update')->willReturn($params['paymentMethodObj']);
         }
         if (!$params['paymentMethodObj']->success) {
             $this->errorHelperMock->expects($this->once())->method('parseBraintreeError')->willReturn(new \Magento\Framework\Phrase($exceptionMessage));
         } else {
             $this->errorHelperMock->expects($this->never())->method('parseBraintreeError');
         }
     }
     try {
         $this->model->processNonce($params['nonce'], $params['optionsArray'], $params['billingAddress']);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->assertEquals($exceptionMessage, $e->getMessage());
     }
 }
Exemplo n.º 26
0
 public function testExecuteWithException()
 {
     $addressId = 1;
     $customerId = 2;
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->request->expects($this->once())->method('getParam')->with('id', false)->willReturn($addressId);
     $this->validatorMock->expects($this->once())->method('validate')->with($this->request)->willReturn(true);
     $this->addressRepositoryMock->expects($this->once())->method('getById')->with($addressId)->willReturn($this->address);
     $this->sessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->address->expects($this->once())->method('getCustomerId')->willReturn(34);
     $exception = new \Exception('Exception');
     $this->messageManager->expects($this->once())->method('addError')->with(__('We can\'t delete the address right now.'))->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addException')->with($exception, __('We can\'t delete the address right now.'));
     $this->resultRedirect->expects($this->once())->method('setPath')->with('*/*/index')->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->model->execute());
 }
 /**
  * test get customer method, method returns customer from service
  */
 public function testGetCustomerLoadCustomerFromService()
 {
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(false));
     $this->customerSessionMock->expects($this->once())->method('getId')->will($this->returnValue($this->customerId));
     $this->customerRepositoryMock->expects($this->once())->method('getById')->with($this->equalTo($this->customerId))->will($this->returnValue($this->customerDataMock));
     $this->assertEquals($this->customerDataMock, $this->currentCustomer->getCustomer());
 }
Exemplo n.º 28
0
 /**
  * @dataProvider getCustomerEmptyDataProvider
  */
 public function testGetCustomerEmpty($useVault, $isLoggedIn)
 {
     $this->configMock->expects($this->any())->method('useVault')->willReturn($useVault);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn($isLoggedIn);
     $this->assertEquals('', $this->block->currentCustomerName());
     $this->assertEquals('', $this->block->currentCustomerLastName());
 }
Exemplo n.º 29
0
 /**
  * @param \PHPUnit_Framework_MockObject_MockObject $quoteMock
  */
 private function getCheckoutMethodStep(\PHPUnit_Framework_MockObject_MockObject $quoteMock)
 {
     $this->customerSessionMock->expects(self::once())->method('isLoggedIn')->willReturn(false);
     $quoteMock->expects(self::at(1))->method('getCheckoutMethod')->willReturn(null);
     $this->checkoutHelperMock->expects(self::once())->method('isAllowedGuestCheckout')->with($quoteMock)->willReturn(true);
     $quoteMock->expects(self::once())->method('setCheckoutMethod')->with(Onepage::METHOD_GUEST);
     $quoteMock->expects(self::at(2))->method('getCheckoutMethod')->willReturn(Onepage::METHOD_GUEST);
 }
Exemplo n.º 30
0
 public function testGetValueNotGroupPrice()
 {
     $this->productMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(null));
     $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(3));
     $this->productMock->expects($this->once())->method('getResource')->will($this->returnValue($this->productResourceMock));
     $this->productResourceMock->expects($this->once())->method('getAttribute')->with($this->equalTo('group_price'))->will($this->returnValue(null));
     $this->assertFalse($this->groupPrice->getValue());
 }