public function testExecute()
 {
     $quoteMock = $this->getQuoteMock();
     $quoteMock->expects(self::exactly(2))->method('getIsVirtual')->willReturn(false);
     $quoteMock->expects(self::exactly(2))->method('getShippingAddress')->willReturn($this->shippingAddressMock);
     $this->shippingAddressMock->expects(self::once())->method('getShippingMethod')->willReturn(self::TEST_SHIPPING_METHOD . '-bad');
     $this->disabledQuoteAddressValidationStep($quoteMock);
     $this->shippingAddressMock->expects(self::once())->method('setShippingMethod')->willReturn(self::TEST_SHIPPING_METHOD);
     $this->shippingAddressMock->expects(self::once())->method('setCollectShippingRates')->willReturn(true);
     $quoteMock->expects(self::once())->method('collectTotals');
     $this->quoteRepositoryMock->expects(self::once())->method('save')->with($quoteMock);
     $this->shippingMethodUpdater->execute(self::TEST_SHIPPING_METHOD, $quoteMock);
 }
 public function testSavePaymentInQuote()
 {
     $quoteId = 1;
     $response = new DataObject();
     $payment = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock();
     $payment->expects($this->once())->method('setAdditionalInformation')->with('pnref');
     $this->errorHandlerMock->expects($this->once())->method('handle')->with($payment, $response);
     $quote = $this->getMock('Magento\\Quote\\Api\\Data\\CartInterface', [], [], '', false);
     $quote->expects($this->exactly(2))->method('getId')->willReturn($quoteId);
     $this->sessionTransparent->expects($this->once())->method('getQuoteId')->willReturn($quoteId);
     $this->quoteRepository->expects($this->once())->method('get')->willReturn($quote);
     $this->paymentMethodManagementInterface->expects($this->once())->method('get')->willReturn($payment);
     $this->paymentMethodManagementInterface->expects($this->once())->method('set');
     $this->model->savePaymentInQuote($response);
 }
Пример #3
0
 public function testGetCartForCustomer()
 {
     $customerId = 100;
     $cartMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->quoteRepositoryMock->expects($this->once())->method('getActiveForCustomer')->with($customerId)->willReturn($cartMock);
     $this->assertEquals($cartMock, $this->model->getCartForCustomer($customerId));
 }
Пример #4
0
 public function testSaveCheckoutMethod()
 {
     $this->assertEquals(['error' => -1, 'message' => 'Invalid data'], $this->onepage->saveCheckoutMethod(null));
     /** @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject $quoteMock */
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['setCheckoutMethod', '__wakeup'], [], '', false);
     $quoteMock->expects($this->once())->method('setCheckoutMethod')->with('someMethod')->will($this->returnSelf());
     $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock);
     $this->checkoutSessionMock->expects($this->once())->method('setStepData')->with('billing', 'allow', true);
     $this->onepage->setQuote($quoteMock);
     $this->assertEquals([], $this->onepage->saveCheckoutMethod('someMethod'));
 }
 /**
  * @param \PHPUnit_Framework_MockObject_MockObject $quoteMock
  * @param array $details
  */
 private function updateQuoteStep(\PHPUnit_Framework_MockObject_MockObject $quoteMock, array $details)
 {
     $quoteMock->expects(self::once())->method('setMayEditShippingAddress')->with(false);
     $quoteMock->expects(self::once())->method('setMayEditShippingMethod')->with(true);
     $quoteMock->expects(self::exactly(2))->method('getShippingAddress')->willReturn($this->shippingAddressMock);
     $quoteMock->expects(self::exactly(2))->method('getBillingAddress')->willReturn($this->billingAddressMock);
     $this->updateQuoteAddressStep($quoteMock, $details);
     $this->disabledQuoteAddressValidationStep();
     $quoteMock->expects(self::once())->method('collectTotals');
     $this->quoteRepositoryMock->expects(self::once())->method('save')->with($quoteMock);
 }
Пример #6
0
    /**
     * @dataProvider initializeQuoteForReviewDataProvider
     */
    public function testInitializeQuoteForReview(
        $paymentMethodNonce,
        $details,
        $expectedShipping,
        $expectedBilling,
        $expectedPaymentAdditionalInfo
    ) {
        $this->verifyIgnoreAddressValidation();
        $this->quoteMock->expects($this->any())
            ->method('getIsVirtual')
            ->willReturn(false);

        $paymentMock = $this->getMockBuilder('\Magento\Quote\Model\Quote\Payment')
            ->disableOriginalConstructor()
            ->getMock();
        $paymentMock->expects($this->once())
            ->method('setMethod')
            ->with(PayPal::METHOD_CODE);

        $this->quoteMock->expects($this->any())
            ->method('getPayment')
            ->willReturn($paymentMock);

        foreach ($expectedShipping as $methodName => $value) {
            $this->shippingAddressMock->expects($this->once())
                ->method($methodName)
                ->with($value)
                ->willReturnSelf();
        }
        foreach ($expectedBilling as $methodName => $value) {
            $this->billingAddressMock->expects($this->once())
                ->method($methodName)
                ->with($value)
                ->willReturnSelf();
        }
        $index = 1;
        foreach ($expectedPaymentAdditionalInfo as $key => $value) {
            $paymentMock->expects($this->at($index))
                ->method('setAdditionalInformation')
                ->with($key, $value);
            $index++;
        }

        $this->quoteMock->expects($this->once())
            ->method('collectTotals');
        $this->quoteRepositoryMock->expects($this->once())
            ->method('save')
            ->with($this->quoteMock);

        $this->model->initializeQuoteForReview($paymentMethodNonce, $details);
    }
 /**
  * @param bool $isWebsiteScope
  * @param array $websites
  * @dataProvider dispatchDataProvider
  */
 public function testDispatch($isWebsiteScope, $websites)
 {
     $this->configMock->expects($this->once())->method('isWebsiteScope')->will($this->returnValue($isWebsiteScope));
     $customerDataObjectMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $customerDataObjectMock->expects($this->any())->method('getGroupId')->will($this->returnValue(1));
     $customerDataObjectMock->expects($this->any())->method('getWebsiteId')->will($this->returnValue(2));
     if ($isWebsiteScope) {
         $websites = $websites[0];
         $this->storeManagerMock->expects($this->once())->method('getWebsite')->with(2)->will($this->returnValue($websites));
     } else {
         $this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
     }
     $this->eventMock->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($customerDataObjectMock));
     /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote $quoteMock */
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->setMethods(['setWebsite', 'setCustomerGroupId', 'getCustomerGroupId', 'collectTotals', '__wakeup'])->disableOriginalConstructor()->getMock();
     $websiteCount = count($websites);
     $this->quoteRepositoryMock->expects($this->once())->method('getForCustomer')->will($this->returnValue($quoteMock));
     $quoteMock->expects($this->exactly($websiteCount))->method('setWebsite');
     $quoteMock->expects($this->exactly($websiteCount))->method('setCustomerGroupId');
     $quoteMock->expects($this->exactly($websiteCount))->method('collectTotals');
     $this->quoteRepositoryMock->expects($this->exactly($websiteCount))->method('save')->with($quoteMock);
     $quoteMock->expects($this->once())->method('getCustomerGroupId')->willReturn(2);
     $this->customerQuote->execute($this->observerMock);
 }
Пример #8
0
 /**
  * @param int $direction
  * @param string $expectedDirection
  * @dataProvider getListSuccessDataProvider
  */
 public function testGetListSuccess($direction, $expectedDirection)
 {
     $this->markTestSkipped('MAGETWO-48531');
     $searchResult = $this->getMock('\\Magento\\Quote\\Api\\Data\\CartSearchResultsInterface', [], [], '', false);
     $searchCriteriaMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
     $cartMock = $this->getMock('Magento\\Payment\\Model\\Cart', [], [], '', false);
     $filterMock = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false);
     $pageSize = 10;
     $this->searchResultsDataFactory->expects($this->once())->method('create')->will($this->returnValue($searchResult));
     $searchResult->expects($this->once())->method('setSearchCriteria');
     $filterGroupMock = $this->getMock('\\Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
     $searchCriteriaMock->expects($this->any())->method('getFilterGroups')->will($this->returnValue([$filterGroupMock]));
     //addFilterGroupToCollection() checks
     $filterGroupMock->expects($this->any())->method('getFilters')->will($this->returnValue([$filterMock]));
     $filterMock->expects($this->once())->method('getField')->will($this->returnValue('store_id'));
     $filterMock->expects($this->any())->method('getConditionType')->will($this->returnValue('eq'));
     $filterMock->expects($this->once())->method('getValue')->will($this->returnValue('filter_value'));
     //back in getList()
     $this->quoteCollectionMock->expects($this->once())->method('getSize')->willReturn($pageSize);
     $searchResult->expects($this->once())->method('setTotalCount')->with($pageSize);
     $sortOrderMock = $this->getMockBuilder('Magento\\Framework\\Api\\SortOrder')->setMethods(['getField', 'getDirection'])->disableOriginalConstructor()->getMock();
     //foreach cycle
     $searchCriteriaMock->expects($this->once())->method('getSortOrders')->will($this->returnValue([$sortOrderMock]));
     $sortOrderMock->expects($this->once())->method('getField')->will($this->returnValue('id'));
     $sortOrderMock->expects($this->once())->method('getDirection')->will($this->returnValue($direction));
     $this->quoteCollectionMock->expects($this->once())->method('addOrder')->with('id', $expectedDirection);
     $searchCriteriaMock->expects($this->once())->method('getCurrentPage')->will($this->returnValue(1));
     $searchCriteriaMock->expects($this->once())->method('getPageSize')->will($this->returnValue(10));
     $this->quoteCollectionMock->expects($this->once())->method('setCurPage')->with(1);
     $this->quoteCollectionMock->expects($this->once())->method('setPageSize')->with(10);
     $this->extensionAttributesJoinProcessorMock->expects($this->once())->method('process')->with($this->isInstanceOf('\\Magento\\Quote\\Model\\ResourceModel\\Quote\\Collection'));
     $this->quoteCollectionMock->expects($this->once())->method('getItems')->willReturn([$cartMock]);
     $searchResult->expects($this->once())->method('setItems')->with([$cartMock]);
     $this->model = $this->getMock('Magento\\Quote\\Model\\QuoteRepository', ['getQuoteCollection'], ['quoteFactory' => $this->quoteFactoryMock, 'storeManager' => $this->storeManagerMock, 'quoteCollection' => $this->quoteCollectionMock, 'searchResultsDataFactory' => $this->searchResultsDataFactory, 'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock]);
     $this->model->expects($this->once())->method('getQuoteCollection')->willReturn($this->quoteCollectionMock);
     $this->assertEquals($searchResult, $this->model->getList($searchCriteriaMock));
 }