13 class TaxTest extends \PHPUnit\Framework\TestCase
95 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
97 $className = \Magento\Framework\Model\Context::class;
98 $this->context = $this->createMock(
$className);
100 $className = \Magento\Framework\Registry::class;
101 $this->registry = $this->createMock(
$className);
103 $className = \Magento\Eav\Model\Entity\AttributeFactory::class;
104 $this->attributeFactory = $this->createPartialMock(
$className, [
'create']);
106 $className = \Magento\Store\Model\StoreManagerInterface::class;
107 $this->storeManager = $this->createMock(
$className);
109 $className = \Magento\Tax\Model\CalculationFactory::class;
110 $this->calculationFactory = $this->createPartialMock(
$className, [
'create']);
112 $className = \Magento\Customer\Model\Session::class;
113 $this->customerSession = $this->createPartialMock(
115 [
'getCustomerId',
'getDefaultTaxShippingAddress',
'getDefaultTaxBillingAddress',
'getCustomerTaxClassId']
117 $this->customerSession->expects($this->any())->method(
'getCustomerId')->willReturn(
null);
118 $this->customerSession->expects($this->any())->method(
'getDefaultTaxShippingAddress')->willReturn(
null);
119 $this->customerSession->expects($this->any())->method(
'getDefaultTaxBillingAddress')->willReturn(
null);
120 $this->customerSession->expects($this->any())->method(
'getCustomerTaxClassId')->willReturn(
null);
122 $className = \Magento\Customer\Api\AccountManagementInterface::class;
123 $this->accountManagement = $this->createMock(
$className);
126 $this->taxData = $this->createMock(
$className);
128 $className = \Magento\Weee\Model\ResourceModel\Tax::class;
129 $this->resource = $this->createMock(
$className);
131 $className = \Magento\Weee\Model\Config::class;
132 $this->weeeConfig = $this->createMock(
$className);
134 $className = \Magento\Framework\Pricing\PriceCurrencyInterface::class;
135 $this->priceCurrency = $this->createMock(
$className);
137 $className = \Magento\Framework\Data\Collection\AbstractDb::class;
138 $this->resourceCollection = $this->createMock(
$className);
140 $this->model = $this->objectManager->getObject(
141 \
Magento\Weee\Model\Tax::class,
143 'context' => $this->context,
144 'registry' => $this->registry,
145 'attributeFactory' => $this->attributeFactory,
146 'storeManager' => $this->storeManager,
147 'calculationFactory' => $this->calculationFactory,
148 'customerSession' => $this->customerSession,
149 'accountManagement' => $this->accountManagement,
150 'taxData' => $this->taxData,
151 'resource' => $this->resource,
152 'weeeConfig' => $this->weeeConfig,
153 'priceCurrency' => $this->priceCurrency,
154 'resourceCollection' => $this->resourceCollection,
167 array $weeeTaxCalculationsByEntity,
169 string $expectedFptLabel
173 $store = $this->createMock(\
Magento\Store\Model\Store::class);
174 $group = $this->createMock(\
Magento\Store\Model\Group::class);
177 $calculation = $this->createMock(\
Magento\Tax\Model\Calculation::class);
179 $obj = new \Magento\Framework\DataObject([
'country' =>
'US',
'region' =>
'TX']);
180 $calculation->expects($this->once())
181 ->method(
'getRateRequest')
183 $calculation->expects($this->once())
184 ->method(
'getDefaultRateRequest')
186 $calculation->expects($this->any())
191 ->method(
'getAttributeCodesByFrontendType')
192 ->willReturn([
'0'=>
'fpt']);
194 $this->storeManager->expects($this->any())
195 ->method(
'getWebsite')
199 ->willReturn($websitePassed);
201 ->method(
'getDefaultGroup')
203 $group->expects($this->any())
204 ->method(
'getDefaultStore')
206 $store->expects($this->any())
210 if ($websitePassed) {
218 $store->expects($this->once())
219 ->method(
'getWebsiteId')
227 $this->weeeConfig->expects($this->any())
228 ->method(
'isEnabled')
231 $this->weeeConfig->expects($this->any())
232 ->method(
'isTaxable')
235 $this->attributeFactory->expects($this->any())
239 $this->calculationFactory->expects($this->any())
241 ->willReturn($calculation);
243 $this->priceCurrency->expects($this->any())
248 $this->resource->expects($this->any())
249 ->method(
'fetchWeeeTaxCalculationsByEntity')
251 0 => $weeeTaxCalculationsByEntity
254 $result = $this->model->getProductWeeeAttributes(
$product,
null,
null, $websitePassed,
true);
255 $this->assertTrue(is_array(
$result));
256 $this->assertArrayHasKey(0,
$result);
258 $this->assertEquals(1, $obj->getAmount());
259 $this->assertEquals(0.25, $obj->getTaxAmount());
260 $this->assertEquals($weeeTaxCalculationsByEntity[
'attribute_code'], $obj->getCode());
261 $this->assertEquals(
__($expectedFptLabel), $obj->getName());
273 $product = $this->getMockBuilder(\
Magento\Catalog\Model\Product::class)
274 ->disableOriginalConstructor()
275 ->setMethods([
'getTypeId',
'getPriceType'])
277 $product->expects($this->any())->method(
'getTypeId')->willReturn($productTypeId);
278 $product->expects($this->any())->method(
'getPriceType')->willReturn($productPriceType);
279 $weeeDataHelper = $this->getMockBuilder(\
Magento\Framework\DataObject::class)
280 ->disableOriginalConstructor()
281 ->setMethods([
'getAmountExclTax'])
283 $weeeDataHelper->expects($this->at(0))->method(
'getAmountExclTax')->willReturn(10);
284 $weeeDataHelper->expects($this->at(1))->method(
'getAmountExclTax')->willReturn(30);
285 $tax = $this->getMockBuilder(\
Magento\Weee\Model\Tax::class)
286 ->disableOriginalConstructor()
287 ->setMethods([
'getProductWeeeAttributes'])
289 $tax->expects($this->once())->method(
'getProductWeeeAttributes')
290 ->willReturn([$weeeDataHelper, $weeeDataHelper]);
291 $this->assertEquals(40,
$tax->getWeeeAmountExclTax(
$product));
299 $product = $this->getMockBuilder(\
Magento\Catalog\Model\Product::class)
300 ->disableOriginalConstructor()
301 ->setMethods([
'getTypeId',
'getPriceType'])
303 $product->expects($this->once())->method(
'getTypeId')->willReturn(
'bundle');
304 $product->expects($this->once())->method(
'getPriceType')->willReturn(0);
305 $weeeDataHelper = $this->getMockBuilder(\
Magento\Framework\DataObject::class)
306 ->disableOriginalConstructor()
308 $tax = $this->getMockBuilder(\
Magento\Weee\Model\Tax::class)
309 ->disableOriginalConstructor()
310 ->setMethods([
'getProductWeeeAttributes'])
312 $tax->expects($this->once())->method(
'getProductWeeeAttributes')->willReturn([$weeeDataHelper]);
313 $this->assertEquals(0,
$tax->getWeeeAmountExclTax(
$product));
322 'store_label_defined' => [
323 'weeeTaxCalculationsByEntity' => [
325 'label_value' =>
'fpt_label',
326 'frontend_label' =>
'fpt_label_frontend',
327 'attribute_code' =>
'fpt_code',
329 'websitePassed' => 1,
330 'expectedFptLabel' =>
'fpt_label',
332 'store_label_not_defined' => [
333 'weeeTaxCalculationsByEntity' => [
336 'frontend_label' =>
'fpt_label_frontend',
337 'attribute_code' =>
'fpt_code',
339 'websitePassed' => 1,
340 'expectedFptLabel' =>
'fpt_label_frontend',
342 'website_not_passed' => [
343 'weeeTaxCalculationsByEntity' => [
346 'frontend_label' =>
'fpt_label_frontend',
347 'attribute_code' =>
'fpt_code',
349 'websitePassed' =>
null,
350 'expectedFptLabel' =>
'fpt_label_frontend',
getWeeeAmountExclTaxDataProvider()
testGetWeeeAmountExclTaxForDynamicBundleProduct()
getProductWeeeAttributesDataProvider()
testGetProductWeeeAttributes(array $weeeTaxCalculationsByEntity, $websitePassed, string $expectedFptLabel)
testGetWeeeAmountExclTax($productTypeId, $productPriceType)