Esempio n. 1
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();
 }
Esempio n. 2
0
 /**
  * Test for execute method
  *
  * @return void
  */
 public function testExecuteWithSuccessOrderSave()
 {
     $testData = $this->getExecuteWithSuccessOrderSaveTestData();
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $paymentMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock();
     $checkoutMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods(['getRedirectUrl'])->getMock();
     $resultJsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock();
     $redirectMock->expects($this->never())->method('setPath')->with('*/*/')->willReturn('redirect');
     $this->formKeyValidatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
     $this->resultRedirectFactoryMock->expects($this->never())->method('create')->willReturn($redirectMock);
     $this->objectManagerMock->expects($this->atLeastOnce())->method('get')->willReturnMap($testData['objectManager.get']);
     // call _expireAjax method
     $this->expireAjaxFlowHasItemsFalse();
     $this->requestMock->expects($this->atLeastOnce())->method('getPost')->willReturnMap($testData['request.getPost']);
     $this->agreementsValidatorMock->expects($this->once())->method('isValid')->with($testData['agreementsValidator.isValid'])->willReturn(true);
     $this->quoteMock->expects($this->atLeastOnce())->method('getPayment')->willReturn($paymentMock);
     $paymentMock->expects($this->once())->method('setQuote')->with($this->quoteMock);
     $paymentMock->expects($this->once())->method('importData')->with($testData['payment.importData']);
     $this->onepageMock->expects($this->once())->method('saveOrder');
     $this->onepageMock->expects($this->once())->method('getCheckout')->willReturn($checkoutMock);
     $checkoutMock->expects($this->once())->method('getRedirectUrl')->willReturn(null);
     $this->eventManagerMock->expects($this->once())->method('dispatch')->withConsecutive($this->equalTo('checkout_controller_onepage_saveOrder'), $this->countOf(2));
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($resultJsonMock);
     $resultJsonMock->expects($this->once())->method('setData')->with($testData['resultJson.setData'])->willReturnSelf();
     $this->assertEquals($resultJsonMock, $this->controller->execute());
 }
Esempio n. 3
0
    public function testExecutePassed()
    {
        $url = 'http://redirect-url.com';
        $wishlist = $this->getMock('Magento\Wishlist\Model\Wishlist', [], [], '', false);
        
        $this->formKeyValidator->expects($this->once())
            ->method('validate')
            ->with($this->request)
            ->will($this->returnValue(true));
        $this->request->expects($this->once())
            ->method('getParam')
            ->with('qty')
            ->will($this->returnValue(2));
        $this->wishlistProvider->expects($this->once())
            ->method('getWishlist')
            ->will($this->returnValue($wishlist));
        $this->itemCarrier->expects($this->once())
            ->method('moveAllToCart')
            ->with($wishlist, 2)
            ->willReturn($url);
        $this->resultRedirectMock->expects($this->once())
            ->method('setUrl')
            ->with($url)
            ->willReturnSelf();

        $this->assertSame($this->resultRedirectMock, $this->getController()->executeInternal());
    }
Esempio n. 4
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());
 }
Esempio n. 5
0
    public function testExecuteWithoutFormKey()
    {
        /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
        $redirectMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect')
            ->disableOriginalConstructor()
            ->getMock();

        $this->resultFactoryMock->expects($this->once())
            ->method('create')
            ->willReturnMap(
                [
                    [\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [], $redirectMock],
                ]
            );

        $this->validatorMock->expects($this->once())
            ->method('validate')
            ->with($this->requestMock)
            ->willReturn(false);

        $redirectMock->expects($this->once())
            ->method('setPath')
            ->with('sendfriend/product/send', ['_current' => true])
            ->willReturnSelf();

        $this->assertEquals($redirectMock, $this->model->executeInternal());
    }
Esempio n. 6
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());
 }
Esempio n. 7
0
 public function testExecuteWithInvalidFormKey()
 {
     $this->prepareContext();
     $this->formKeyValidator->expects($this->once())->method('validate')->with($this->request)->willReturn(false);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();
     $controller = new \Magento\Wishlist\Controller\Index\Remove($this->context, $this->wishlistProvider, $this->formKeyValidator);
     $this->assertSame($this->resultRedirectMock, $controller->execute());
 }
Esempio n. 8
0
 public function testExecutePassed()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $this->formKeyValidator->expects($this->once())->method('validate')->with($this->request)->will($this->returnValue(true));
     $this->request->expects($this->once())->method('getParam')->with('qty')->will($this->returnValue(2));
     $this->response->expects($this->once())->method('setRedirect')->will($this->returnValue('http://redirect-url.com'));
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlist));
     $this->itemCarrier->expects($this->once())->method('moveAllToCart')->with($wishlist, 2)->will($this->returnValue('http://redirect-url.com'));
     $this->getController()->execute();
 }
Esempio n. 9
0
 public function testExecuteWithException()
 {
     $cartUrl = 'cart_url';
     $exceptionMessage = 'exception_message';
     $exception = new \Exception($exceptionMessage);
     $this->formKeyValidator->expects($this->once())->method('validate')->with($this->request)->willReturn(true);
     $wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->willReturn($wishlistMock);
     $this->request->expects($this->once())->method('getParam')->with('item')->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addExceptionMessage')->with($exception, __('We can\'t move the item to the wish list.'))->willReturnSelf();
     $this->cartHelper->expects($this->once())->method('getCartUrl')->willReturn($cartUrl);
     $this->resultRedirect->expects($this->once())->method('setUrl')->with($cartUrl)->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->controller->execute());
 }
Esempio n. 10
0
 /**
  * @param string $message
  * @param string $exception
  *
  * @dataProvider exceptionDataProvider
  */
 public function testGeneralException($message, $exception)
 {
     $customerId = 1;
     $address = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->getMockForAbstractClass();
     $currentCustomerMock = $this->getCurrentCustomerMock($customerId, $address);
     $newCustomerMock = $this->getNewCustomerMock($customerId, $address);
     $exception = new $exception(__($message));
     $this->validator->expects($this->once())->method('validate')->with($this->request)->willReturn(true);
     $this->request->expects($this->once())->method('isPost')->willReturn(true);
     $this->request->expects($this->exactly(3))->method('getParam')->withConsecutive(['change_email'], ['change_email'], ['change_password'])->willReturn(false);
     $this->request->expects($this->any())->method('getPostValue')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->customerSession->expects($this->once())->method('setCustomerFormData')->with(true)->willReturnSelf();
     $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($currentCustomerMock);
     $this->customerRepository->expects($this->once())->method('save')->with($newCustomerMock)->willThrowException($exception);
     $this->customerExtractor->expects($this->once())->method('extract')->with('customer_account_edit', $this->request)->willReturn($newCustomerMock);
     $this->resultRedirect->expects($this->once())->method('setPath')->with('*/*/edit')->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->model->execute());
 }
Esempio n. 11
0
 /**
  * @param bool $formKeyIsValid
  * @param bool $isPost
  * @dataProvider executeDataProvider
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecute($formKeyIsValid, $isPost)
 {
     $this->formKeyValidator->expects($this->any())->method('validate')->willReturn($formKeyIsValid);
     $this->request->expects($this->any())->method('isPost')->willReturn($isPost);
     if (!$formKeyIsValid || !$isPost) {
         $this->messageManager->expects($this->once())->method('addError');
         $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/order/index');
         $this->shipmentLoader->expects($this->never())->method('load');
         $this->assertEquals($this->resultRedirect, $this->saveAction->execute());
     } else {
         $shipmentId = 1000012;
         $orderId = 10003;
         $tracking = [];
         $shipmentData = ['items' => [], 'send_email' => ''];
         $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', 'register', 'getOrder', 'getOrderId', '__wakeup'], [], '', false);
         $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCustomerNoteNotify', '__wakeup'], [], '', false);
         $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipmentData], ['tracking', null, $tracking]]));
         $this->shipmentLoader->expects($this->any())->method('setShipmentId')->with($shipmentId);
         $this->shipmentLoader->expects($this->any())->method('setOrderId')->with($orderId);
         $this->shipmentLoader->expects($this->any())->method('setShipment')->with($shipmentData);
         $this->shipmentLoader->expects($this->any())->method('setTracking')->with($tracking);
         $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($shipment));
         $shipment->expects($this->once())->method('register')->will($this->returnSelf());
         $shipment->expects($this->any())->method('getOrder')->will($this->returnValue($order));
         $order->expects($this->once())->method('setCustomerNoteNotify')->with(false);
         $this->labelGenerator->expects($this->any())->method('create')->with($shipment, $this->request)->will($this->returnValue(true));
         $saveTransaction = $this->getMockBuilder('Magento\\Framework\\DB\\Transaction')->disableOriginalConstructor()->setMethods([])->getMock();
         $saveTransaction->expects($this->at(0))->method('addObject')->with($shipment)->will($this->returnSelf());
         $saveTransaction->expects($this->at(1))->method('addObject')->with($order)->will($this->returnSelf());
         $saveTransaction->expects($this->at(2))->method('save');
         $this->session->expects($this->once())->method('getCommentText')->with(true);
         $this->objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\DB\\Transaction')->will($this->returnValue($saveTransaction));
         $this->objectManager->expects($this->once())->method('get')->with('Magento\\Backend\\Model\\Session')->will($this->returnValue($this->session));
         $path = 'sales/order/view';
         $arguments = ['order_id' => $orderId];
         $shipment->expects($this->once())->method('getOrderId')->will($this->returnValue($orderId));
         $this->prepareRedirect($path, $arguments);
         $this->saveAction->execute();
         $this->assertEquals($this->response, $this->saveAction->getResponse());
     }
 }
Esempio n. 12
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithoutQuantityArrayAndConfigurable()
 {
     $itemId = 2;
     $wishlistId = 1;
     $qty = [];
     $productId = 4;
     $indexUrl = 'index_url';
     $configureUrl = 'configure_url';
     $options = [5 => 'option'];
     $params = ['item' => $itemId, 'qty' => $qty];
     $this->formKeyValidator->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
     $itemMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->setMethods(['load', 'getId', 'getWishlistId', 'setQty', 'setOptions', 'getBuyRequest', 'mergeBuyRequest', 'addToCart', 'getProduct', 'getProductId'])->getMock();
     $this->requestMock->expects($this->at(0))->method('getParam')->with('item', null)->willReturn($itemId);
     $this->itemFactoryMock->expects($this->once())->method('create')->willReturn($itemMock);
     $itemMock->expects($this->once())->method('load')->with($itemId, null)->willReturnSelf();
     $itemMock->expects($this->exactly(2))->method('getId')->willReturn($itemId);
     $itemMock->expects($this->once())->method('getWishlistId')->willReturn($wishlistId);
     $wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->with($wishlistId)->willReturn($wishlistMock);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('qty', null)->willReturn($qty);
     $this->quantityProcessorMock->expects($this->once())->method('process')->with(1)->willReturnArgument(0);
     $itemMock->expects($this->once())->method('setQty')->with(1)->willReturnSelf();
     $this->urlMock->expects($this->at(0))->method('getUrl')->with('*/*', null)->willReturn($indexUrl);
     $itemMock->expects($this->once())->method('getProductId')->willReturn($productId);
     $this->urlMock->expects($this->at(1))->method('getUrl')->with('*/*/configure/', ['id' => $itemId, 'product_id' => $productId])->willReturn($configureUrl);
     $optionMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item\\Option')->disableOriginalConstructor()->getMock();
     $this->optionFactoryMock->expects($this->once())->method('create')->willReturn($optionMock);
     $optionsMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\ResourceModel\\Item\\Option\\Collection')->disableOriginalConstructor()->getMock();
     $optionMock->expects($this->once())->method('getCollection')->willReturn($optionsMock);
     $optionsMock->expects($this->once())->method('addItemFilter')->with([$itemId])->willReturnSelf();
     $optionsMock->expects($this->once())->method('getOptionsByItem')->with($itemId)->willReturn($options);
     $itemMock->expects($this->once())->method('setOptions')->with($options)->willReturnSelf();
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($params);
     $buyRequestMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $itemMock->expects($this->once())->method('getBuyRequest')->willReturn($buyRequestMock);
     $this->productHelperMock->expects($this->once())->method('addParamsToBuyRequest')->with($params, ['current_config' => $buyRequestMock])->willReturn($buyRequestMock);
     $itemMock->expects($this->once())->method('mergeBuyRequest')->with($buyRequestMock)->willReturnSelf();
     $itemMock->expects($this->once())->method('addToCart')->with($this->checkoutCartMock, true)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message')));
     $this->messageManagerMock->expects($this->once())->method('addNotice')->with('message', null)->willReturnSelf();
     $this->helperMock->expects($this->once())->method('calculate')->willReturnSelf();
     $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($configureUrl)->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->model->execute());
 }