/** * @covers \Magento\SalesRule\Model\Rule\Action\Discount\CartFixed::calculate */ public function testCalculate() { $this->rule->setData(['id' => 1, 'discount_amount' => 10.0]); $this->address->expects($this->any())->method('getCartFixedRules')->will($this->returnValue([])); $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->priceCurrency->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0)); $this->priceCurrency->expects($this->atLeastOnce())->method('round')->will($this->returnArgument(0)); $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($store)); /** validators data */ $this->validator->expects($this->once())->method('getItemPrice')->with($this->item)->will($this->returnValue(100)); $this->validator->expects($this->once())->method('getItemBasePrice')->with($this->item)->will($this->returnValue(100)); $this->validator->expects($this->once())->method('getItemOriginalPrice')->with($this->item)->will($this->returnValue(100)); $this->validator->expects($this->once())->method('getItemBaseOriginalPrice')->with($this->item)->will($this->returnValue(100)); $this->address->expects($this->once())->method('setCartFixedRules')->with([1 => 0.0]); $this->model->calculate($this->rule, $this->item, 1); $this->assertEquals($this->data->getAmount(), 10); $this->assertEquals($this->data->getBaseAmount(), 10); $this->assertEquals($this->data->getOriginalAmount(), 10); $this->assertEquals($this->data->getBaseOriginalAmount(), 100); }
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]); }
public function testCollect() { $this->shippingAssignment->expects($this->exactly(3))->method('getShipping')->willReturn($this->shipping); $this->shipping->expects($this->exactly(2))->method('getAddress')->willReturn($this->address); $this->shipping->expects($this->once())->method('getMethod')->willReturn('flatrate'); $this->shippingAssignment->expects($this->atLeastOnce())->method('getItems')->willReturn([$this->cartItem]); $this->freeShipping->expects($this->once())->method('isFreeShipping')->with($this->quote, [$this->cartItem])->willReturn(true); $this->address->expects($this->once())->method('setFreeShipping')->with(true); $this->total->expects($this->atLeastOnce())->method('setTotalAmount'); $this->total->expects($this->atLeastOnce())->method('setBaseTotalAmount'); $this->cartItem->expects($this->atLeastOnce())->method('getProduct')->willReturnSelf(); $this->cartItem->expects($this->atLeastOnce())->method('isVirtual')->willReturn(false); $this->cartItem->expects($this->once())->method('getParentItem')->willReturn(false); $this->cartItem->expects($this->once())->method('getHasChildren')->willReturn(false); $this->cartItem->expects($this->once())->method('getWeight')->willReturn(2); $this->cartItem->expects($this->atLeastOnce())->method('getQty')->willReturn(2); $this->address->expects($this->once())->method('getFreeShipping')->willReturn(true); $this->cartItem->expects($this->once())->method('setRowWeight')->with(0); $this->address->expects($this->once())->method('setItemQty')->with(2); $this->address->expects($this->atLeastOnce())->method('setWeight'); $this->address->expects($this->atLeastOnce())->method('setFreeMethodWeight'); $this->address->expects($this->once())->method('collectShippingRates'); $this->address->expects($this->once())->method('getAllShippingRates')->willReturn([$this->rate]); $this->rate->expects($this->once())->method('getCode')->willReturn('flatrate'); $this->quote->expects($this->once())->method('getStore')->willReturn($this->store); $this->rate->expects($this->atLeastOnce())->method('getPrice')->willReturn(5); $this->priceCurrency->expects($this->once())->method('convert')->with(5, $this->store)->willReturn(5); $this->total->expects($this->once())->method('setShippingAmount')->with(5); $this->rate->expects($this->once())->method('getCarrierTitle')->willReturn('Carrier title'); $this->rate->expects($this->once())->method('getMethodTitle')->willReturn('Method title'); $this->address->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title'); $this->address->expects($this->once())->method('getShippingDescription')->willReturn('Carrier title - Method title'); $this->total->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title'); $this->shippingModel->collect($this->quote, $this->shippingAssignment, $this->total); }
public function testSuggestItemsQty() { $data = [[], ['qty' => -2], ['qty' => 3], ['qty' => 3.5], ['qty' => 5], ['qty' => 4]]; $this->quoteMock->expects($this->any())->method('getItemById')->will($this->returnValueMap([[2, $this->prepareQuoteItemMock(2)], [3, $this->prepareQuoteItemMock(3)], [4, $this->prepareQuoteItemMock(4)], [5, $this->prepareQuoteItemMock(5)]])); $this->stockState->expects($this->at(0))->method('suggestQty')->will($this->returnValue(3.0)); $this->stockState->expects($this->at(1))->method('suggestQty')->will($this->returnValue(3.5)); $this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($this->quoteMock)); $this->assertSame([[], ['qty' => -2], ['qty' => 3.0, 'before_suggest_qty' => 3.0], ['qty' => 3.5, 'before_suggest_qty' => 3.5], ['qty' => 5], ['qty' => 4]], $this->cart->suggestItemsQty($data)); }
public function testInitWithNonDecimalQty() { $quoteItemMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Item', ['getStockId', 'getIsQtyDecimal', '__wakeup'], [], '', false); $this->productMock->expects($this->once())->method('getId')->will($this->returnSelf()); $this->productMock->expects($this->never())->method('setIsQtyDecimal'); $this->productMock->expects($this->once())->method('setCartQty')->will($this->returnSelf()); $this->configMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(10)); $this->configMock->expects($this->once())->method('setQty')->will($this->returnSelf()); $this->quoteMock->expects($this->once())->method('addProduct')->will($this->returnValue($quoteItemMock)); $this->assertInstanceOf('Magento\\Quote\\Model\\Quote\\Item', $this->model->init($this->quoteMock, $this->productMock, $this->configMock)); }
protected function setUp() { $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->priceCurrency = $this->getMockBuilder('Magento\\Framework\\Pricing\\PriceCurrencyInterface')->getMock(); $this->store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->quote = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getStore', '__wakeup', 'getCustomerTaxClassId'])->getMock(); $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); $checkoutSession = $this->getMockBuilder('\\Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods(['getQuote', '__wakeup'])->getMock(); $checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote)); $this->taxHelper = $this->getMockBuilder('\\Magento\\Tax\\Helper\\Data')->disableOriginalConstructor()->setMethods(['getShippingPrice', 'displayShippingPriceIncludingTax', 'displayShippingBothPrices'])->getMock(); $this->priceObj = $objectManager->getObject('Magento\\Tax\\Block\\Checkout\\Shipping\\Price', ['checkoutSession' => $checkoutSession, 'taxHelper' => $this->taxHelper, 'priceCurrency' => $this->priceCurrency]); }
public function prepare() { $this->contextMock = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false); $this->checkoutSessionMock = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false); $this->orderFactoryMock = $this->getMock('Magento\\Sales\\Model\\OrderFactory', ['getQuote'], [], '', false); $this->hssHelperMock = $this->getMock('Magento\\Paypal\\Helper\\Hss', [], [], '', false); $this->paymentDataMock = $this->getMock('Magento\\Payment\\Helper\\Data', [], [], '', false); $this->quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['getPayment', '__wakeup'], [], '', false); $this->paymentMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false); $this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->any())->method('getPayment')->will($this->returnValue($this->paymentMock)); $this->hssHelperMock->expects($this->any())->method('getHssMethods')->will($this->returnValue([])); }
/** * @dataProvider totalsDataProvider */ public function testGetTotals($isVirtual) { $expected = 'expected'; $this->quoteMock->expects($this->at(0))->method('setTotalsCollectedFlag')->with(false); $this->quoteMock->expects($this->at(1))->method('collectTotals'); $this->quoteMock->expects($this->once())->method('isVirtual')->willreturn($isVirtual); if ($isVirtual) { $this->billingAddressMock->expects($this->once())->method('getTotals')->willReturn($expected); } else { $this->shippingAddressMock->expects($this->once())->method('getTotals')->willReturn($expected); } $this->assertEquals($expected, $this->totals->getTotals()); }
protected function setUp() { $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface'); $this->quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false); $this->orderMock = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false); $this->paymentMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false); $this->orderSenderMock = $this->getMock('Magento\\Sales\\Model\\Order\\Email\\Sender\\OrderSender', [], [], '', false); $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getQuote', 'getOrder'])->getMock(); $this->observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', ['getEvent'], [], '', false); $this->observerMock->expects($this->any())->method('getEvent')->willReturn($eventMock); $eventMock->expects($this->once())->method('getQuote')->willReturn($this->quoteMock); $eventMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock); $this->quoteMock->expects($this->once())->method('getPayment')->willReturn($this->paymentMock); $this->model = new \Magento\Quote\Observer\Webapi\SubmitObserver($this->loggerMock, $this->orderSenderMock); }
public function setUp() { $objectManager = new ObjectManager($this); $this->taxConfig = $this->getMockBuilder('\\Magento\\Tax\\Model\\Config')->disableOriginalConstructor()->setMethods(['getShippingTaxClass', 'shippingPriceIncludesTax'])->getMock(); $this->store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock(); $this->quote = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['__wakeup', 'getStore'])->getMock(); $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); $this->address = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote\\Address')->disableOriginalConstructor()->setMethods(['__wakeup', 'getQuote', 'getShippingDiscountAmount', 'getBaseShippingDiscountAmount'])->getMock(); $this->address->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote)); $methods = ['setType', 'setCode', 'setQuantity', 'setUnitPrice', 'setDiscountAmount', 'setTaxClassKey', 'setTaxIncluded', 'create']; $this->quoteDetailsItemBuilderMock = $this->getMock('Magento\\Tax\\Api\\Data\\QuoteDetailsItemDataBuilder', $methods, [], '', false); $classMethods = ['setType', 'setValue', 'create']; $this->taxClassKeyBuilderMock = $this->getMock('Magento\\Tax\\Api\\Data\\TaxClassKeyDataBuilder', $classMethods, [], '', false); $this->commonTaxCollector = $objectManager->getObject('Magento\\Tax\\Model\\Sales\\Total\\Quote\\CommonTaxCollector', ['taxConfig' => $this->taxConfig, 'quoteDetailsItemBuilder' => $this->quoteDetailsItemBuilderMock, 'taxClassKeyBuilder' => $this->taxClassKeyBuilderMock]); }
public function testDelete() { $this->quoteMock->expects($this->once())->method('delete'); $this->quoteMock->expects($this->exactly(1))->method('getId')->willReturn(1); $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2); $this->model->delete($this->quoteMock); }
/** * 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()); }
/** * @param $paymentMethod * @param $controller * @param $quoteId * @param $result * @dataProvider textExecuteFailedPlaceOrderDataProvider */ public function testExecuteFailedPlaceOrder($paymentMethod, $controller, $quoteId, $result) { $this->requestMock->expects($this->at(0))->method('getParam')->with('payment')->will($this->returnValue($paymentMethod)); $this->requestMock->expects($this->at(1))->method('getParam')->with('controller')->will($this->returnValue($controller)); $this->quoteMock->expects($this->any())->method('getId')->will($this->returnValue($quoteId)); $this->cartManagementMock->expects($this->once())->method('placeOrder')->willThrowException(new \Exception()); $this->jsonHelperMock->expects($this->any())->method('jsonEncode')->with($result); $this->placeOrderController->execute(); }
public function setUp() { $objectManager = new ObjectManager($this); $this->taxConfig = $this->getMockBuilder('\\Magento\\Tax\\Model\\Config')->disableOriginalConstructor()->setMethods(['getShippingTaxClass', 'shippingPriceIncludesTax'])->getMock(); $this->store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock(); $this->quote = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['__wakeup', 'getStore'])->getMock(); $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); $this->address = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote\\Address')->disableOriginalConstructor()->getMock(); $this->address->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote)); $methods = ['create']; $this->quoteDetailsItemDataObject = $objectManager->getObject('Magento\\Tax\\Model\\Sales\\Quote\\ItemDetails'); $this->taxClassKeyDataObject = $objectManager->getObject('Magento\\Tax\\Model\\TaxClass\\Key'); $this->quoteDetailsItemDataObjectFactoryMock = $this->getMock('Magento\\Tax\\Api\\Data\\QuoteDetailsItemInterfaceFactory', $methods, [], '', false); $this->quoteDetailsItemDataObjectFactoryMock->expects($this->any())->method('create')->willReturn($this->quoteDetailsItemDataObject); $this->taxClassKeyDataObjectFactoryMock = $this->getMock('Magento\\Tax\\Api\\Data\\TaxClassKeyInterfaceFactory', $methods, [], '', false); $this->taxClassKeyDataObjectFactoryMock->expects($this->any())->method('create')->willReturn($this->taxClassKeyDataObject); $this->commonTaxCollector = $objectManager->getObject('Magento\\Tax\\Model\\Sales\\Total\\Quote\\CommonTaxCollector', ['taxConfig' => $this->taxConfig, 'quoteDetailsItemDataObjectFactory' => $this->quoteDetailsItemDataObjectFactoryMock, 'taxClassKeyDataObjectFactory' => $this->taxClassKeyDataObjectFactoryMock]); }
/** * @expectedExcpetion \Magento\Framework\Exception\NoSuchEntityException * @expectedExceptionMessage No such entity with cartId = 15 */ public function testGetWithExceptionByIsActive() { $cartId = 15; $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->once())->method('getId')->willReturn($this->storeMock); $this->quoteMock->expects($this->never())->method('setSharedStoreIds'); $this->quoteMock->expects($this->once())->method('load')->with($cartId)->willReturn($this->storeMock); $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); $this->quoteMock->expects($this->once())->method('getIsActive')->willReturn(0); $this->model->get($cartId); }
/** * @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); }
/** * Test for processRelation */ public function testProcessRelation() { $addressCollectionMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], [], '', false); $this->quoteMock->expects($this->once())->method('addressCollectionWasSet')->willReturn(true); $this->quoteMock->expects($this->once())->method('getAddressesCollection')->willReturn($addressCollectionMock); $addressCollectionMock->expects($this->once())->method('save'); $itemsCollectionMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], [], '', false); $this->quoteMock->expects($this->once())->method('itemsCollectionWasSet')->willReturn(true); $this->quoteMock->expects($this->once())->method('getItemsCollection')->willReturn($itemsCollectionMock); $itemsCollectionMock->expects($this->once())->method('save'); $paymentCollectionMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], [], '', false); $this->quoteMock->expects($this->once())->method('paymentsCollectionWasSet')->willReturn(true); $this->quoteMock->expects($this->once())->method('getPaymentsCollection')->willReturn($paymentCollectionMock); $paymentCollectionMock->expects($this->once())->method('save'); $paymentMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false); $this->quoteMock->expects($this->once())->method('currentPaymentWasSet')->willReturn(true); $this->quoteMock->expects($this->once())->method('getPayment')->willReturn($paymentMock); $paymentMock->expects($this->once())->method('save'); $this->model->processRelation($this->quoteMock); }
/** * @param bool $result * @param bool $quoteHasItems * @param bool $isMultiShipping * @param bool $hasItemsWithDecimalQty * @param bool $validateMinimumAmount * @param int $itemsSummaryQty * @param int $itemVirtualQty * @param int $maximumQty * @dataProvider isMultishippingCheckoutAvailableDataProvider */ public function testIsMultishippingCheckoutAvailable($result, $quoteHasItems, $isMultiShipping, $hasItemsWithDecimalQty, $validateMinimumAmount, $itemsSummaryQty, $itemVirtualQty, $maximumQty) { $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with(\Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE)->will($this->returnValue($isMultiShipping)); $this->checkoutSessionMock->expects($this->once())->method('getQuote')->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once())->method('hasItems')->will($this->returnValue($quoteHasItems)); $this->quoteMock->expects($this->any())->method('hasItemsWithDecimalQty')->will($this->returnValue($hasItemsWithDecimalQty)); $this->quoteMock->expects($this->any())->method('validateMinimumAmount')->with(true)->will($this->returnValue($validateMinimumAmount)); $this->quoteMock->expects($this->any())->method('getItemsSummaryQty')->will($this->returnValue($itemsSummaryQty)); $this->quoteMock->expects($this->any())->method('getItemVirtualQty')->will($this->returnValue($itemVirtualQty)); $this->scopeConfigMock->expects($this->any())->method('getValue')->with(\Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_MAXIMUM_QUANTITY)->will($this->returnValue($maximumQty)); $this->assertEquals($result, $this->helper->isMultishippingCheckoutAvailable()); }
public function testPopulateCustomerInfo() { $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($this->customerMock); $this->customerMock->expects($this->atLeastOnce())->method('getId')->willReturn(null); $this->customerMock->expects($this->atLeastOnce())->method('getDefaultBilling')->willReturn(100500); $this->quoteMock->expects($this->atLeastOnce())->method('getBillingAddress')->willReturn($this->quoteAddressMock); $this->quoteMock->expects($this->atLeastOnce())->method('getShippingAddress')->willReturn($this->quoteAddressMock); $this->quoteMock->expects($this->atLeastOnce())->method('setCustomer')->with($this->customerMock)->willReturnSelf(); $this->quoteMock->expects($this->once())->method('getPasswordHash')->willReturn('password hash'); $this->quoteAddressMock->expects($this->atLeastOnce())->method('getId')->willReturn(null); $this->customerAddressRepositoryMock->expects($this->atLeastOnce())->method('getById')->with(100500)->willReturn($this->customerAddressMock); $this->quoteAddressMock->expects($this->atLeastOnce())->method('importCustomerAddressData')->willReturnSelf(); $this->accountManagementMock->expects($this->once())->method('createAccountWithPasswordHash')->with($this->customerMock, 'password hash')->willReturn($this->customerMock); $this->customerManagement->populateCustomerInfo($this->quoteMock); }
/** * @covers \Magento\Quote\Model\ShippingMethodManagement::estimateByExtendedAddress */ public function testEstimateByExtendedAddress() { $cartId = 1; $addressData = ['region' => 'California', 'region_id' => 23, 'country_id' => 1, 'postcode' => 90200]; $currencyCode = 'UAH'; $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->setMethods(['getData'])->getMock(); $this->quoteRepository->expects(static::once())->method('getActive')->with($cartId)->willReturn($this->quote); $this->quote->expects(static::once())->method('isVirtual')->willReturn(false); $this->quote->expects(static::once())->method('getItemsCount')->willReturn(1); $address->expects(static::once())->method('getData')->willReturn($addressData); $this->quote->expects(static::once())->method('getShippingAddress')->willReturn($this->shippingAddress); $this->shippingAddress->expects(static::once())->method('addData')->with($addressData)->willReturnSelf(); $this->shippingAddress->expects(static::once())->method('setCollectShippingRates')->with(true)->willReturnSelf(); $this->totalsCollector->expects(static::once())->method('collectAddressTotals')->with($this->quote, $this->shippingAddress)->willReturnSelf(); $rate = $this->getMockBuilder(Rate::class)->disableOriginalConstructor()->setMethods([])->getMock(); $methodObject = $this->getMockForAbstractClass(ShippingMethodInterface::class); $expectedRates = [$methodObject]; $this->shippingAddress->expects(static::once())->method('getGroupedAllShippingRates')->willReturn([[$rate]]); $this->quote->expects(static::once())->method('getQuoteCurrencyCode')->willReturn($currencyCode); $this->converter->expects(static::once())->method('modelToDataObject')->with($rate, $currencyCode)->willReturn($methodObject); $carriersRates = $this->model->estimateByExtendedAddress($cartId, $address); static::assertEquals($expectedRates, $carriersRates); }
/** * @param $conditions * @param $exportShippingCustomerAddressCalls * @param $exportBillingCustomerAddressCalls * @dataProvider prepareRegisteredCustomerQuoteDataProvider */ public function testPrepareRegisteredCustomerQuote($conditions, $exportBillingCustomerAddressCalls, $exportShippingCustomerAddressCalls) { $customerDataMock = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->setMethods(['getDefaultShipping', 'getDefaultBilling'])->disableOriginalConstructor()->getMock(); $customerDataMock->expects($this->any())->method('getDefaultBilling')->willReturn($conditions['isDefaultBilling']); $customerDataMock->expects($this->any())->method('getDefaultShipping')->willReturn($conditions['isDefaultShipping']); $this->customerRepositoryMock->expects($this->once())->method('getById')->willReturn($customerDataMock); $customerAddressMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock(); $shippingAddressMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Address')->setMethods(['getTelephone', 'getSameAsBilling', 'getCustomerId', 'getSaveInAddressBook', 'exportCustomerAddress'])->disableOriginalConstructor()->getMock(); $shippingAddressMock->expects($this->any())->method('getTelephone')->willReturn($conditions['isTelephone']); $shippingAddressMock->expects($this->any())->method('getSameAsBilling')->willReturn($conditions['isShippingSameAsBilling']); $shippingAddressMock->expects($this->any())->method('getCustomerId')->willReturn(true); $shippingAddressMock->expects($this->any())->method('getSaveInAddressBook')->willReturn($conditions['isShippingSaveInAddressBook']); $shippingAddressMock->expects($this->exactly($exportShippingCustomerAddressCalls))->method('exportCustomerAddress')->willReturn($customerAddressMock); $billingAddressMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Address')->setMethods(['getTelephone', 'getCustomerId', 'getSaveInAddressBook', 'exportCustomerAddress'])->disableOriginalConstructor()->getMock(); $billingAddressMock->expects($this->any())->method('getTelephone')->willReturn($conditions['isTelephone']); $billingAddressMock->expects($this->any())->method('getCustomerId')->willReturn(true); $billingAddressMock->expects($this->any())->method('getSaveInAddressBook')->willReturn($conditions['isBillingSaveInAddressBook']); $billingAddressMock->expects($this->exactly($exportBillingCustomerAddressCalls))->method('exportCustomerAddress')->willReturn($customerAddressMock); $this->quoteMock->expects($this->any())->method('isVirtual')->willReturn(false); $this->quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddressMock); $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($shippingAddressMock); $this->assertInstanceOf('Magento\\Quote\\Model\\Quote', $this->quote->prepareRegisteredCustomerQuote($this->quoteMock, 1)); }
/** * @dataProvider getSubtotalExclTaxDataProvider */ public function testGetSubtotalExclTax($totals, $expectedValue) { $this->quote->expects($this->once())->method('getTotals')->will($this->returnValue($totals)); $this->assertEquals($expectedValue, $this->totalsObj->getSubtotalExclTax()); }
public function testGetSubtotalZero() { $totals = []; $this->quote->expects($this->once())->method('getTotals')->will($this->returnValue($totals)); $this->assertEquals(0, $this->totalsObj->getSubtotal()); }
/** * @param mixed $customerNoteNotify * @param bool $expectedResult * @dataProvider getNoteNotifyDataProvider */ public function testGetNoteNotify($customerNoteNotify, $expectedResult) { $this->quoteMock->expects($this->any())->method('getCustomerNoteNotify')->willReturn($customerNoteNotify); $this->assertEquals($expectedResult, $this->totals->getNoteNotify()); }
public function testGetBaseSubtotal() { $this->_quoteMock->expects($this->once())->method('__call')->with('getBaseSubtotal')->will($this->returnValue(100)); $this->assertEquals(100, $this->_model->getBaseSubtotal()); }