13 class WeeeTest extends \PHPUnit\Framework\TestCase
25 private $serializerMock;
35 $taxHelper = $this->createMock(\
Magento\Tax\Helper\Data::class);
38 $taxHelper->expects($this->any())->method(
$method)->will($this->returnValue(
$value));
52 $storeTaxRate = $taxRates[
'store_tax_rate'];
53 $customerTaxRate = $taxRates[
'customer_tax_rate'];
55 $taxCalculation = $this->createPartialMock(
56 \
Magento\Tax\Model\Calculation::class,
57 [
'getRateOriginRequest',
'getRateRequest',
'getRate']
60 $rateRequest = new \Magento\Framework\DataObject();
61 $defaultRateRequest = new \Magento\Framework\DataObject();
63 $taxCalculation->expects($this->any())->method(
'getRateRequest')->will($this->returnValue($rateRequest));
65 ->expects($this->any())
66 ->method(
'getRateOriginRequest')
67 ->will($this->returnValue($defaultRateRequest));
70 ->expects($this->any())
72 ->will($this->onConsecutiveCalls($storeTaxRate, $customerTaxRate));
74 return $taxCalculation;
85 $this->serializerMock = $this->getMockBuilder(\
Magento\Framework\
Serialize\Serializer\Json::class)->getMock();
87 $weeeHelper = $this->getMockBuilder(\
Magento\Weee\Helper\Data::class)
88 ->setConstructorArgs([
'serializer' => $this->serializerMock])
89 ->disableOriginalConstructor()
93 $weeeHelper->expects($this->any())->method(
$method)->will($this->returnValue(
$value));
107 $itemMock = $this->createPartialMock(\
Magento\Quote\Model\Quote\Item::class, [
115 'isChildrenCalculated',
119 $productMock = $this->createMock(\
Magento\Catalog\Model\Product::class);
120 $itemMock->expects($this->any())->method(
'getProduct')->will($this->returnValue($productMock));
121 $itemMock->expects($this->any())->method(
'getTotalQty')->will($this->returnValue($itemTotalQty));
136 $itemMock->expects($this->any())->method(
'getParentItem')->will($this->returnValue(
false));
137 $itemMock->expects($this->any())->method(
'getHasChildren')->will($this->returnValue(
false));
138 $itemMock->expects($this->any())->method(
'getChildren')->will($this->returnValue([]));
139 $itemMock->expects($this->any())->method(
'isChildrenCalculated')->will($this->returnValue(
false));
158 $childItemMock->expects($this->any())->method(
'getParentItem')->will($this->returnValue($parentItemMock));
159 $childItemMock->expects($this->any())->method(
'getHasChildren')->will($this->returnValue(
false));
160 $childItemMock->expects($this->any())->method(
'getChildren')->will($this->returnValue([]));
161 $childItemMock->expects($this->any())->method(
'isChildrenCalculated')->will($this->returnValue(
false));
163 $parentItemMock->expects($this->any())->method(
'getParentItem')->will($this->returnValue(
false));
164 $parentItemMock->expects($this->any())->method(
'getHasChildren')->will($this->returnValue(
true));
165 $parentItemMock->expects($this->any())->method(
'getChildren')->will($this->returnValue([$childItemMock]));
166 $parentItemMock->expects($this->any())->method(
'isChildrenCalculated')->will($this->returnValue(
true));
168 $items[] = $parentItemMock;
169 $items[] = $childItemMock;
181 $addressMock = $this->createPartialMock(\
Magento\Quote\Model\Quote\Address::class, [
185 'getCustomAttributesCodes' 188 $quoteMock = $this->createMock(\
Magento\Quote\Model\Quote::class);
189 $storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
190 $this->priceCurrency = $this->getMockBuilder(
191 \
Magento\Framework\Pricing\PriceCurrencyInterface::class
193 $this->priceCurrency->expects($this->any())->method(
'round')->willReturnArgument(0);
194 $this->priceCurrency->expects($this->any())->method(
'convert')->willReturnArgument(0);
195 $quoteMock->expects($this->any())->method(
'getStore')->will($this->returnValue($storeMock));
197 $addressMock->expects($this->any())->method(
'getAllItems')->will($this->returnValue(
$items));
198 $addressMock->expects($this->any())->method(
'getQuote')->will($this->returnValue($quoteMock));
199 $addressMock->expects($this->any())->method(
'getCustomAttributesCodes')->willReturn([]);
212 $shippingMock = $this->createMock(\
Magento\Quote\Api\Data\ShippingInterface::class);
213 $shippingMock->expects($this->any())->method(
'getAddress')->willReturn($addressMock);
214 $shippingAssignmentMock = $this->createMock(\
Magento\Quote\Api\Data\ShippingAssignmentInterface::class);
215 $shippingAssignmentMock->expects($this->any())->method(
'getItems')->willReturn($itemMock);
216 $shippingAssignmentMock->expects($this->any())->method(
'getShipping')->willReturn($shippingMock);
218 return $shippingAssignmentMock;
229 foreach ($itemData as $key =>
$value) {
230 $this->assertEquals(
$value,
$item->getData($key),
'item ' . $key .
' is incorrect');
243 $this->assertEquals(
$value,
$address->getData($key),
'address ' . $key .
' is incorrect');
268 $assertSetApplied =
false 271 if ($parentQty > 0) {
277 $quoteMock = $this->createMock(\
Magento\Quote\Model\Quote::class);
278 $storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
279 $quoteMock->expects($this->any())->method(
'getStore')->will($this->returnValue($storeMock));
281 $totalMock = new \Magento\Quote\Model\Quote\Address\Total(
283 $this->getMockBuilder(\
Magento\Framework\
Serialize\Serializer\Json::class)->getMock()
291 if ($assertSetApplied) {
293 ->expects($this->at(1))
294 ->method(
'setApplied')
295 ->with(reset(
$items), []);
298 ->expects($this->at(2))
299 ->method(
'setApplied')
303 ->expects($this->at(8))
304 ->method(
'setApplied')
307 'title' =>
'Recycling Fee',
308 'base_amount' =>
'10',
310 'row_amount' =>
'20',
311 'base_row_amount' =>
'20',
312 'base_amount_incl_tax' =>
'10',
313 'amount_incl_tax' =>
'10',
314 'row_amount_incl_tax' =>
'20',
315 'base_row_amount_incl_tax' =>
'20',
318 'title' =>
'FPT Fee',
319 'base_amount' =>
'5',
321 'row_amount' =>
'10',
322 'base_row_amount' =>
'10',
323 'base_amount_incl_tax' =>
'5',
324 'amount_incl_tax' =>
'5',
325 'row_amount_incl_tax' =>
'10',
326 'base_row_amount_incl_tax' =>
'10',
332 'taxData' => $taxHelper,
333 'calculation' => $calculator,
334 'weeeData' => $weeeHelper,
338 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
341 $this->weeeCollector->collect($quoteMock, $shippingAssignmentMock, $totalMock);
363 $data[
'price_incl_tax_weee_taxable_unit_included_in_subtotal'] = [
365 'priceIncludesTax' =>
true,
370 'includeInSubtotal' =>
true,
373 'getProductWeeeAttributes' => [
374 new \Magento\Framework\DataObject(
376 'name' =>
'Recycling Fee',
383 'store_tax_rate' => 8.25,
384 'customer_tax_rate' => 8.25,
387 'weee_tax_applied_amount' => 10,
388 'base_weee_tax_applied_amount' => 10,
389 'weee_tax_applied_row_amount' => 20,
390 'base_weee_tax_applied_row_amnt' => 20,
391 'weee_tax_applied_amount_incl_tax' => 10,
392 'base_weee_tax_applied_amount_incl_tax' => 10,
393 'weee_tax_applied_row_amount_incl_tax' => 20,
394 'base_weee_tax_applied_row_amnt_incl_tax' => 20,
399 'subtotal_incl_tax' => 20,
400 'base_subtotal_incl_tax' => 20,
404 $data[
'price_incl_tax_weee_taxable_unit_not_included_in_subtotal'] = [
406 'priceIncludesTax' =>
true,
411 'includeInSubtotal' =>
false,
414 'getProductWeeeAttributes' => [
415 new \Magento\Framework\DataObject(
417 'name' =>
'Recycling Fee',
424 'store_tax_rate' => 8.25,
425 'customer_tax_rate' => 8.25,
428 'weee_tax_applied_amount' => 10,
429 'base_weee_tax_applied_amount' => 10,
430 'weee_tax_applied_row_amount' => 20,
431 'base_weee_tax_applied_row_amnt' => 20,
432 'weee_tax_applied_amount_incl_tax' => 10,
433 'base_weee_tax_applied_amount_incl_tax' => 10,
434 'weee_tax_applied_row_amount_incl_tax' => 20,
435 'base_weee_tax_applied_row_amnt_incl_tax' => 20,
440 'subtotal_incl_tax' => 20,
441 'base_subtotal_incl_tax' => 20,
445 $data[
'price_excl_tax_weee_taxable_unit_included_in_subtotal'] = [
447 'priceIncludesTax' =>
false,
452 'includeInSubtotal' =>
true,
455 'getProductWeeeAttributes' => [
456 new \Magento\Framework\DataObject(
458 'name' =>
'Recycling Fee',
465 'store_tax_rate' => 8.25,
466 'customer_tax_rate' => 8.25,
469 'weee_tax_applied_amount' => 10,
470 'base_weee_tax_applied_amount' => 10,
471 'weee_tax_applied_row_amount' => 20,
472 'base_weee_tax_applied_row_amnt' => 20,
473 'weee_tax_applied_amount_incl_tax' => 10,
474 'base_weee_tax_applied_amount_incl_tax' => 10,
475 'weee_tax_applied_row_amount_incl_tax' => 20,
476 'base_weee_tax_applied_row_amnt_incl_tax' => 20,
481 'subtotal_incl_tax' => 20,
482 'base_subtotal_incl_tax' => 20,
486 $data[
'price_incl_tax_weee_non_taxable_unit_included_in_subtotal'] = [
488 'priceIncludesTax' =>
true,
493 'includeInSubtotal' =>
true,
494 'isTaxable' =>
false,
496 'getProductWeeeAttributes' => [
497 new \Magento\Framework\DataObject(
499 'name' =>
'Recycling Fee',
506 'store_tax_rate' => 8.25,
507 'customer_tax_rate' => 8.25,
510 'weee_tax_applied_amount' => 10,
511 'base_weee_tax_applied_amount' => 10,
512 'weee_tax_applied_row_amount' => 20,
513 'base_weee_tax_applied_row_amnt' => 20,
514 'weee_tax_applied_amount_incl_tax' => 10,
515 'base_weee_tax_applied_amount_incl_tax' => 10,
516 'weee_tax_applied_row_amount_incl_tax' => 20,
517 'base_weee_tax_applied_row_amnt_incl_tax' => 20,
522 'subtotal_incl_tax' => 20,
523 'base_subtotal_incl_tax' => 20,
524 'weee_total_excl_tax' => 20,
525 'weee_base_total_excl_tax' => 20,
529 $data[
'price_excl_tax_weee_non_taxable_unit_included_in_subtotal'] = [
531 'priceIncludesTax' =>
false,
536 'includeInSubtotal' =>
true,
537 'isTaxable' =>
false,
539 'getProductWeeeAttributes' => [
540 new \Magento\Framework\DataObject(
542 'name' =>
'Recycling Fee',
549 'store_tax_rate' => 8.25,
550 'customer_tax_rate' => 8.25,
553 'weee_tax_applied_amount' => 10,
554 'base_weee_tax_applied_amount' => 10,
555 'weee_tax_applied_row_amount' => 20,
556 'base_weee_tax_applied_row_amnt' => 20,
557 'weee_tax_applied_amount_incl_tax' => 10,
558 'base_weee_tax_applied_amount_incl_tax' => 10,
559 'weee_tax_applied_row_amount_incl_tax' => 20,
560 'base_weee_tax_applied_row_amnt_incl_tax' => 20,
565 'subtotal_incl_tax' => 20,
566 'base_subtotal_incl_tax' => 20,
567 'weee_total_excl_tax' => 20,
568 'weee_base_total_excl_tax' => 20,
572 $data[
'price_incl_tax_weee_taxable_row_included_in_subtotal'] = [
574 'priceIncludesTax' =>
true,
579 'includeInSubtotal' =>
true,
582 'getProductWeeeAttributes' => [
583 new \Magento\Framework\DataObject(
585 'name' =>
'Recycling Fee',
592 'store_tax_rate' => 8.25,
593 'customer_tax_rate' => 8.25,
596 'weee_tax_applied_amount' => 10,
597 'base_weee_tax_applied_amount' => 10,
598 'weee_tax_applied_row_amount' => 20,
599 'base_weee_tax_applied_row_amnt' => 20,
600 'weee_tax_applied_amount_incl_tax' => 10,
601 'base_weee_tax_applied_amount_incl_tax' => 10,
602 'weee_tax_applied_row_amount_incl_tax' => 20,
603 'base_weee_tax_applied_row_amnt_incl_tax' => 20,
608 'subtotal_incl_tax' => 20,
609 'base_subtotal_incl_tax' => 20,
613 $data[
'price_excl_tax_weee_taxable_row_included_in_subtotal'] = [
615 'priceIncludesTax' =>
false,
620 'includeInSubtotal' =>
true,
623 'getProductWeeeAttributes' => [
624 new \Magento\Framework\DataObject(
626 'name' =>
'Recycling Fee',
633 'store_tax_rate' => 8.25,
634 'customer_tax_rate' => 8.25,
637 'weee_tax_applied_amount' => 10,
638 'base_weee_tax_applied_amount' => 10,
639 'weee_tax_applied_row_amount' => 20,
640 'base_weee_tax_applied_row_amnt' => 20,
641 'weee_tax_applied_amount_incl_tax' => 10,
642 'base_weee_tax_applied_amount_incl_tax' => 10,
643 'weee_tax_applied_row_amount_incl_tax' => 20,
644 'base_weee_tax_applied_row_amnt_incl_tax' => 20,
649 'subtotal_incl_tax' => 20,
650 'base_subtotal_incl_tax' => 20,
654 $data[
'price_incl_tax_weee_non_taxable_row_included_in_subtotal'] = [
656 'priceIncludesTax' =>
true,
661 'includeInSubtotal' =>
true,
662 'isTaxable' =>
false,
664 'getProductWeeeAttributes' => [
665 new \Magento\Framework\DataObject(
667 'name' =>
'Recycling Fee',
674 'store_tax_rate' => 8.25,
675 'customer_tax_rate' => 8.25,
678 'weee_tax_applied_amount' => 10,
679 'base_weee_tax_applied_amount' => 10,
680 'weee_tax_applied_row_amount' => 20,
681 'base_weee_tax_applied_row_amnt' => 20,
682 'weee_tax_applied_amount_incl_tax' => 10,
683 'base_weee_tax_applied_amount_incl_tax' => 10,
684 'weee_tax_applied_row_amount_incl_tax' => 20,
685 'base_weee_tax_applied_row_amnt_incl_tax' => 20,
690 'subtotal_incl_tax' => 20,
691 'base_subtotal_incl_tax' => 20,
692 'weee_total_excl_tax' => 20,
693 'weee_base_total_excl_tax' => 20,
697 $data[
'price_excl_tax_weee_non_taxable_row_included_in_subtotal'] = [
699 'priceIncludesTax' =>
false,
704 'includeInSubtotal' =>
true,
705 'isTaxable' =>
false,
707 'getProductWeeeAttributes' => [
708 new \Magento\Framework\DataObject(
710 'name' =>
'Recycling Fee',
717 'store_tax_rate' => 8.25,
718 'customer_tax_rate' => 8.25,
721 'weee_tax_applied_amount' => 10,
722 'base_weee_tax_applied_amount' => 10,
723 'weee_tax_applied_row_amount' => 20,
724 'base_weee_tax_applied_row_amnt' => 20,
725 'weee_tax_applied_amount_incl_tax' => 10,
726 'base_weee_tax_applied_amount_incl_tax' => 10,
727 'weee_tax_applied_row_amount_incl_tax' => 20,
728 'base_weee_tax_applied_row_amnt_incl_tax' => 20,
733 'subtotal_incl_tax' => 20,
734 'base_subtotal_incl_tax' => 20,
735 'weee_total_excl_tax' => 20,
736 'weee_base_total_excl_tax' => 20,
740 $data[
'price_excl_tax_weee_non_taxable_row_not_included_in_subtotal'] = [
742 'priceIncludesTax' =>
false,
747 'includeInSubtotal' =>
false,
748 'isTaxable' =>
false,
750 'getProductWeeeAttributes' => [
751 new \Magento\Framework\DataObject(
753 'name' =>
'Recycling Fee',
760 'store_tax_rate' => 8.25,
761 'customer_tax_rate' => 8.25,
764 'weee_tax_applied_amount' => 10,
765 'base_weee_tax_applied_amount' => 10,
766 'weee_tax_applied_row_amount' => 20,
767 'base_weee_tax_applied_row_amnt' => 20,
768 'weee_tax_applied_amount_incl_tax' => 10,
769 'base_weee_tax_applied_amount_incl_tax' => 10,
770 'weee_tax_applied_row_amount_incl_tax' => 20,
771 'base_weee_tax_applied_row_amnt_incl_tax' => 20,
776 'subtotal_incl_tax' => 20,
777 'base_subtotal_incl_tax' => 20,
778 'weee_total_excl_tax' => 20,
779 'weee_base_total_excl_tax' => 20,
783 $data[
'price_excl_tax_weee_taxable_unit_not_included_in_subtotal_PARENT_ITEM'] = [
785 'priceIncludesTax' =>
false,
790 'includeInSubtotal' =>
false,
793 'getProductWeeeAttributes' => [
794 new \Magento\Framework\DataObject(
796 'name' =>
'Recycling Fee',
803 'store_tax_rate' => 8.25,
804 'customer_tax_rate' => 8.25,
807 'weee_tax_applied_amount' => 10,
808 'base_weee_tax_applied_amount' => 10,
809 'weee_tax_applied_row_amount' => 60,
810 'base_weee_tax_applied_row_amnt' => 60,
811 'weee_tax_applied_amount_incl_tax' => 10,
812 'base_weee_tax_applied_amount_incl_tax' => 10,
813 'weee_tax_applied_row_amount_incl_tax' => 60,
814 'base_weee_tax_applied_row_amnt_incl_tax' => 60,
819 'subtotal_incl_tax' => 60,
820 'base_subtotal_incl_tax' => 60,
821 'weee_total_excl_tax' => 0,
822 'weee_base_total_excl_tax' => 0,
826 $data[
'price_excl_tax_weee_non_taxable_row_not_included_in_subtotal_dynamic_multiple_weee'] = [
828 'priceIncludesTax' =>
false,
833 'includeInSubtotal' =>
false,
834 'isTaxable' =>
false,
836 'getProductWeeeAttributes' => [
837 new \Magento\Framework\DataObject(
839 'name' =>
'Recycling Fee',
843 new \Magento\Framework\DataObject(
852 'store_tax_rate' => 8.25,
853 'customer_tax_rate' => 8.25,
856 'weee_tax_applied_amount' => 15,
857 'base_weee_tax_applied_amount' => 15,
858 'weee_tax_applied_row_amount' => 30,
859 'base_weee_tax_applied_row_amnt' => 30,
860 'weee_tax_applied_amount_incl_tax' => 15,
861 'base_weee_tax_applied_amount_incl_tax' => 15,
862 'weee_tax_applied_row_amount_incl_tax' => 30,
863 'base_weee_tax_applied_row_amnt_incl_tax' => 30,
866 'item_is_parent' =>
true,
868 'subtotal_incl_tax' => 30,
869 'base_subtotal_incl_tax' => 30,
870 'weee_total_excl_tax' => 30,
871 'weee_base_total_excl_tax' => 30,
873 'assertSetApplied' =>
true,
testCollect( $taxConfig, $weeeConfig, $taxRates, $itemData, $itemQty, $parentQty, $addressData, $assertSetApplied=false)
verifyAddress($address, $addressData)
verifyItem(\Magento\Quote\Model\Quote\Item $item, $itemData)
setupTaxHelper($taxConfig)
setupItemMockBasics($itemTotalQty)
setupShippingAssignmentMock($addressMock, $itemMock)
setupTaxCalculation($taxRates)
setupParentItemWithChildrenMock($parentQty, $itemQty)
setupWeeeHelper($weeeConfig)