/** * @param $creditmemoItemData array * @return \Magento\Sales\Model\Order\Creditmemo\Item|\PHPUnit_Framework_MockObject_MockObject */ protected function getInvoiceItem($creditmemoItemData) { /** @var \Magento\Sales\Model\Order\Item|\PHPUnit_Framework_MockObject_MockObject $orderItem */ $orderItem = $this->getMock('\\Magento\\Sales\\Model\\Order\\Item', ['isDummy', '__wakeup'], [], '', false); foreach ($creditmemoItemData['order_item'] as $key => $value) { $orderItem->setData($key, $value); } $this->weeeData->expects($this->once())->method('getRowWeeeTaxInclTax')->with($orderItem)->will($this->returnValue($orderItem->getRowWeeeTaxInclTax())); $this->weeeData->expects($this->once())->method('getBaseRowWeeeTaxInclTax')->with($orderItem)->will($this->returnValue($orderItem->getBaseRowWeeeTaxInclTax())); $this->weeeData->expects($this->once())->method('getWeeeAmountInvoiced')->with($orderItem)->will($this->returnValue($orderItem->getWeeeAmountInvoiced())); $this->weeeData->expects($this->once())->method('getBaseWeeeAmountInvoiced')->with($orderItem)->will($this->returnValue($orderItem->getBaseWeeeAmountInvoiced())); $this->weeeData->expects($this->once())->method('getWeeeTaxAmountInvoiced')->with($orderItem)->will($this->returnValue($orderItem->getWeeeTaxAmountInvoiced())); $this->weeeData->expects($this->once())->method('getBaseWeeeTaxAmountInvoiced')->with($orderItem)->will($this->returnValue($orderItem->getBaseWeeeTaxAmountInvoiced())); $this->weeeData->expects($this->once())->method('getWeeeAmountRefunded')->with($orderItem)->will($this->returnValue($orderItem->getWeeeAmountRefunded())); $this->weeeData->expects($this->once())->method('getBaseWeeeAmountRefunded')->with($orderItem)->will($this->returnValue($orderItem->getBaseWeeeAmountRefunded())); $this->weeeData->expects($this->once())->method('getWeeeTaxAmountRefunded')->with($orderItem)->will($this->returnValue($orderItem->getWeeeTaxAmountRefunded())); $this->weeeData->expects($this->once())->method('getBaseWeeeTaxAmountRefunded')->with($orderItem)->will($this->returnValue($orderItem->getBaseWeeeTaxAmountRefunded())); /** @var \Magento\Sales\Model\Order\Invoice\Item|\PHPUnit_Framework_MockObject_MockObject $invoiceItem */ $invoiceItem = $this->getMock('\\Magento\\Sales\\Model\\Order\\Invoice\\Item', ['getOrderItem', 'isLast', '__wakeup'], [], '', false); $invoiceItem->expects($this->any())->method('getOrderItem')->will($this->returnValue($orderItem)); $invoiceItem->expects($this->any())->method('isLast')->will($this->returnValue($creditmemoItemData['is_last'])); foreach ($creditmemoItemData['data_fields'] as $key => $value) { $invoiceItem->setData($key, $value); } $this->weeeData->expects($this->any())->method('getApplied')->will($this->returnCallback(function ($item) { return $item->getAppliedWeee(); })); $this->weeeData->expects($this->any())->method('setApplied')->will($this->returnCallback(function ($item, $weee) { return $item->setAppliedWeee($weee); })); return $invoiceItem; }
public function testAfterAddressSave() { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->weeeHelperMock->expects($this->any())->method('isEnabled')->willReturn(true); $address = $this->objectManager->getObject('Magento\\Customer\\Model\\Address'); $address->setIsDefaultShipping(true); $address->setIsDefaultBilling(true); $address->setIsPrimaryBilling(true); $address->setIsPrimaryShipping(true); $address->setCountryId(1); $address->setData('postcode', 11111); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxBillingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxShippingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->observerMock->expects($this->once())->method('getCustomerAddress')->willReturn($address); $this->session->afterAddressSave($this->observerMock); }
public function testExecute() { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->weeeHelperMock->expects($this->any())->method('isEnabled')->willReturn(true); $customerMock = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\Customer')->disableOriginalConstructor()->getMock(); $this->observerMock->expects($this->once())->method('getData')->with('customer')->willReturn($customerMock); $address = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Address'); $address->setIsDefaultShipping(true); $address->setIsDefaultBilling(true); $address->setCountryId(1); $address->setPostCode(11111); $addresses = [$address]; $customerMock->expects($this->once())->method('getAddresses')->willReturn($addresses); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxBillingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxShippingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->session->execute($this->observerMock); }
public function testGetBaseTotalAmount() { $baseRowTotal = 100; $baseTaxAmount = 10; $baseDiscountTaxCompensationAmount = 2; $baseDiscountAmount = 20; $baseWeeeAmount = 5; $expectedValue = $baseRowTotal + $baseTaxAmount + $baseDiscountTaxCompensationAmount - $baseDiscountAmount + $baseWeeeAmount; $itemMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->setMethods(['getBaseRowTotal', 'getBaseTaxAmount', 'getBaseDiscountTaxCompensationAmount', 'getBaseDiscountAmount', '__wakeup'])->getMock(); $itemMock->expects($this->once())->method('getBaseRowTotal')->will($this->returnValue($baseRowTotal)); $itemMock->expects($this->once())->method('getBaseTaxAmount')->will($this->returnValue($baseTaxAmount)); $itemMock->expects($this->once())->method('getBaseDiscountTaxCompensationAmount')->will($this->returnValue($baseDiscountTaxCompensationAmount)); $itemMock->expects($this->once())->method('getBaseDiscountAmount')->will($this->returnValue($baseDiscountAmount)); $this->weeeHelper->expects($this->once())->method('getBaseRowWeeeTaxInclTax')->with($itemMock)->will($this->returnValue($baseWeeeAmount)); $this->assertEquals($expectedValue, $this->renderer->getBaseTotalAmount($itemMock)); }
public function testAroundDispatchBasedOnShipping() { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->weeeHelperMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->taxHelperMock->expects($this->once())->method('getTaxBasedOn')->willReturn('shipping'); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->once())->method('getWebsiteId')->willReturn(1); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn('US'); $this->scopeConfigMock->expects($this->at(1))->method('getValue')->with(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn(0); $this->customerSessionMock->expects($this->once())->method('getDefaultTaxShippingAddress')->willReturn(['country_id' => 'US', 'region_id' => 1]); $this->weeeTaxMock->expects($this->once())->method('isWeeeInLocation')->with('US', 1, 1)->willReturn(true); $this->httpContextMock->expects($this->once())->method('setValue')->with('weee_tax_region', ['countryId' => 'US', 'regionId' => 1], 0); $action = $this->objectManager->getObject('Magento\\Framework\\App\\Test\\Unit\\Action\\Stub\\ActionStub'); $request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getActionName'], [], '', false); $expectedResult = 'expectedResult'; $proceed = function ($request) use($expectedResult) { return $expectedResult; }; $this->contextPlugin->aroundDispatch($action, $proceed, $request); }
/** * Test for method getWeeeTaxAttributes * * @param int $typeOfDisplay * @param array $attributes * @param array $expectedResult * @dataProvider getWeeeTaxAttributesDataProvider */ public function testGetWeeeTaxAttributes($typeOfDisplay, $attributes, $expectedResult) { /** @var \Magento\Framework\Pricing\Render\Amount $amountRender */ $amountRender = $this->getMockBuilder('Magento\\Framework\\Pricing\\Render\\Amount')->disableOriginalConstructor()->setMethods(['getSaleableItem', 'getDisplayValue', 'getAmount'])->getMock(); /** @var \Magento\Catalog\Model\Product $saleable */ $saleable = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock(); /** @var \Magento\Framework\Pricing\Amount\Base $baseAmount */ $baseAmount = $this->getMockBuilder('Magento\\Framework\\Pricing\\Amount\\Base')->disableOriginalConstructor()->setMethods(['getValue'])->getMock(); $amountRender->expects($this->any())->method('getAmount')->will($this->returnValue($baseAmount)); $callback = function ($argument) use($typeOfDisplay) { if (is_array($argument)) { return in_array($typeOfDisplay, $argument); } else { return $argument == $typeOfDisplay; } }; $this->weeeHelperMock->expects($this->any())->method('typeOfDisplay')->will($this->returnCallback($callback)); $this->weeeHelperMock->expects($this->any())->method('getProductWeeeAttributesForDisplay')->will($this->returnValue($attributes)); $amountRender->expects($this->any())->method('getSaleableItem')->will($this->returnValue($saleable)); $this->model->render($amountRender); $result = $this->model->getWeeeTaxAttributes(); $this->assertEquals($expectedResult, $result); }