10 class WeeeTest extends \PHPUnit\Framework\TestCase
42 protected function setUp()
44 $this->weeeData = $this->getMockBuilder(\
Magento\Weee\Helper\Data::class)
47 'getRowWeeeTaxInclTax',
48 'getBaseRowWeeeTaxInclTax',
49 'getWeeeAmountInvoiced',
50 'getBaseWeeeAmountInvoiced',
51 'getWeeeAmountRefunded',
52 'getBaseWeeeAmountRefunded',
53 'getWeeeTaxAmountInvoiced',
54 'getBaseWeeeTaxAmountInvoiced',
55 'getWeeeTaxAmountRefunded',
56 'getBaseWeeeTaxAmountRefunded',
61 )->disableOriginalConstructor()
64 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
65 $serializer = $this->objectManager->getObject(Json::class);
67 $this->model = $this->objectManager->getObject(
68 \
Magento\Weee\Model\Total\Creditmemo\Weee::class,
70 'weeeData' => $this->weeeData,
75 $this->order = $this->createPartialMock(\
Magento\Sales\Model\Order::class, [
79 $this->creditmemo = $this->createPartialMock(\
Magento\Sales\Model\Order\Creditmemo::class, [
93 public function testCollect($creditmemoData, $expectedResults)
98 $this->weeeData->expects($this->once())
99 ->method(
'includeInSubtotal')
100 ->will($this->returnValue($creditmemoData[
'include_in_subtotal']));
104 $creditmemoItems = [];
105 foreach ($creditmemoData[
'items'] as $itemKey => $creditmemoItemData) {
106 $creditmemoItems[$itemKey] = $this->getInvoiceItem($creditmemoItemData);
108 $this->creditmemo->expects($this->once())
109 ->method(
'getAllItems')
110 ->will($this->returnValue($creditmemoItems));
111 foreach ($creditmemoData[
'data_fields'] as $key =>
$value) {
112 $this->creditmemo->setData($key,
$value);
114 $this->creditmemo->expects($this->any())
115 ->method(
'roundPrice')
116 ->will($this->returnCallback(
118 if (!isset($roundingDelta[
$type])) {
119 $roundingDelta[
$type] = 0;
121 $roundedPrice = round(
$price + $roundingDelta[
$type], 2);
124 return $roundedPrice;
128 $this->model->collect($this->creditmemo);
131 foreach ($expectedResults[
'creditmemo_data'] as $key =>
$value) {
134 $this->creditmemo->getData($key),
135 'Creditmemo data field '.$key.
' is incorrect' 139 foreach ($expectedResults[
'creditmemo_items'] as $itemKey => $itemData) {
140 $creditmemoItem = $creditmemoItems[$itemKey];
141 foreach ($itemData as $key =>
$value) {
142 if ($key ==
'tax_ratio') {
143 $taxRatio = json_decode($creditmemoItem->getData($key),
true);
144 $this->assertEquals(
$value[
'weee'], $taxRatio[
'weee'],
"Tax ratio is incorrect");
148 $creditmemoItem->getData($key),
149 'Creditmemo item field '.$key.
' is incorrect' 165 $result[
'complete_creditmemo'] = [
166 'creditmemo_data' => [
171 'weee_tax_applied_row_amount' => 30,
172 'base_weee_tax_applied_row_amnt' => 30,
173 'row_weee_tax_incl_tax' => 32.47,
174 'base_row_weee_tax_incl_tax' => 32.47,
175 'weee_amount_invoiced' => 30,
176 'base_weee_amount_invoiced' => 30,
177 'weee_amount_refunded' => 0,
178 'base_weee_amount_refunded' => 0,
179 'weee_tax_amount_invoiced' => 2.47,
180 'base_weee_tax_amount_invoiced' => 2.47,
181 'weee_tax_amount_refunded' => 0,
182 'base_weee_tax_amount_refunded' => 0,
185 'title' =>
'recycling_fee',
186 'base_row_amount' => 30,
188 'base_row_amount_incl_tax' => 32.47,
189 'row_amount_incl_tax' => 32.47,
204 'include_in_subtotal' =>
false,
206 'grand_total' => 300,
207 'base_grand_total' => 300,
209 'base_subtotal' => 300,
210 'subtotal_incl_tax' => 324.75,
211 'base_subtotal_incl_tax' => 324.75,
213 'base_tax_amount' => 0,
216 'expected_results' => [
217 'creditmemo_items' => [
221 'title' =>
'recycling_fee',
222 'base_row_amount' => 30,
224 'base_row_amount_incl_tax' => 32.47,
225 'row_amount_incl_tax' => 32.47,
228 'tax_ratio' => [
"weee" => 1.0],
229 'weee_tax_applied_row_amount' => 30,
230 'base_weee_tax_applied_row_amount' => 30,
233 'creditmemo_data' => [
234 'grand_total' => 332.47,
235 'base_grand_total' => 332.47,
236 'tax_amount' => 2.47,
237 'base_tax_amount' => 2.47,
239 'base_subtotal' => 300,
240 'subtotal_incl_tax' => 357.22,
241 'base_subtotal_incl_tax' => 357.22,
247 $result[
'partial_creditmemo'] = [
248 'creditmemo_data' => [
253 'weee_tax_applied_row_amount' => 30,
254 'base_weee_tax_applied_row_amnt' => 30,
255 'row_weee_tax_incl_tax' => 32.47,
256 'base_row_weee_tax_incl_tax' => 32.47,
257 'weee_amount_invoiced' => 30,
258 'base_weee_amount_invoiced' => 30,
259 'weee_amount_refunded' => 0,
260 'base_weee_amount_refunded' => 0,
261 'weee_tax_amount_invoiced' => 2.47,
262 'base_weee_tax_amount_invoiced' => 2.47,
263 'weee_tax_amount_refunded' => 0,
264 'base_weee_tax_amount_refunded' => 0,
267 'title' =>
'recycling_fee',
268 'base_row_amount' => 30,
270 'base_row_amount_incl_tax' => 32.47,
271 'row_amount_incl_tax' => 32.47,
286 'include_in_subtotal' =>
false,
288 'grand_total' => 200,
289 'base_grand_total' => 200,
291 'base_subtotal' => 200,
292 'subtotal_incl_tax' => 216.5,
293 'base_subtotal_incl_tax' => 216.5,
295 'base_tax_amount' => 0,
298 'expected_results' => [
299 'creditmemo_items' => [
303 'title' =>
'recycling_fee',
304 'base_row_amount' => 20,
306 'base_row_amount_incl_tax' => 21.65,
307 'row_amount_incl_tax' => 21.65,
310 'tax_ratio' => [
'weee' => 1.65 / 2.47],
311 'weee_tax_applied_row_amount' => 20,
312 'base_weee_tax_applied_row_amount' => 20,
315 'creditmemo_data' => [
316 'grand_total' => 221.65,
317 'base_grand_total' => 221.65,
318 'tax_amount' => 1.65,
319 'base_tax_amount' => 1.65,
321 'base_subtotal' => 200,
322 'subtotal_incl_tax' => 238.15,
323 'base_subtotal_incl_tax' => 238.15,
329 $result[
'last_partial_creditmemo'] = [
330 'creditmemo_data' => [
335 'weee_tax_applied_row_amount' => 30,
336 'base_weee_tax_applied_row_amnt' => 30,
337 'row_weee_tax_incl_tax' => 32.47,
338 'base_row_weee_tax_incl_tax' => 32.47,
339 'weee_amount_invoiced' => 30,
340 'base_weee_amount_invoiced' => 30,
341 'weee_amount_refunded' => 20,
342 'base_weee_amount_refunded' => 20,
343 'weee_tax_amount_invoiced' => 2.47,
344 'base_weee_tax_amount_invoiced' => 2.47,
345 'weee_tax_amount_refunded' => 1.64,
346 'base_weee_tax_amount_refunded' => 1.64,
349 'title' =>
'recycling_fee',
350 'base_row_amount' => 30,
352 'base_row_amount_incl_tax' => 32.47,
353 'row_amount_incl_tax' => 32.47,
368 'include_in_subtotal' =>
false,
370 'grand_total' => 100,
371 'base_grand_total' => 100,
373 'base_subtotal' => 100,
374 'subtotal_incl_tax' => 108.25,
375 'base_subtotal_incl_tax' => 108.25,
377 'base_tax_amount' => 0,
380 'expected_results' => [
381 'creditmemo_items' => [
385 'title' =>
'recycling_fee',
386 'base_row_amount' => 10,
388 'base_row_amount_incl_tax' => 10.82,
389 'row_amount_incl_tax' => 10.82,
392 'tax_ratio' => [
'weee' => 0.83 / 2.47],
393 'weee_tax_applied_row_amount' => 10,
394 'base_weee_tax_applied_row_amount' => 10,
397 'creditmemo_data' => [
398 'grand_total' => 110.83,
399 'base_grand_total' => 110.83,
400 'tax_amount' => 0.83,
401 'base_tax_amount' => 0.83,
403 'base_subtotal' => 100,
404 'subtotal_incl_tax' => 119.07,
405 'base_subtotal_incl_tax' => 119.07,
412 'creditmemo_data' => [
417 'weee_tax_applied_row_amount' => 30,
418 'base_weee_tax_applied_row_amnt' => 30,
419 'row_weee_tax_incl_tax' => 32.47,
420 'base_row_weee_tax_incl_tax' => 32.47,
421 'weee_amount_invoiced' => 30,
422 'base_weee_amount_invoiced' => 30,
423 'weee_amount_refunded' => 0,
424 'base_weee_amount_refunded' => 0,
425 'weee_tax_amount_invoiced' => 2.47,
426 'base_weee_tax_amount_invoiced' => 2.47,
427 'weee_tax_amount_refunded' => 0,
428 'base_weee_tax_amount_refunded' => 0,
431 'title' =>
'recycling_fee',
432 'base_row_amount' => 30,
434 'base_row_amount_incl_tax' => 32.47,
435 'row_amount_incl_tax' => 32.47,
450 'include_in_subtotal' =>
false,
452 'grand_total' => 300,
453 'base_grand_total' => 300,
455 'base_subtotal' => 300,
456 'subtotal_incl_tax' => 324.75,
457 'base_subtotal_incl_tax' => 324.75,
459 'base_tax_amount' => 0,
462 'expected_results' => [
463 'creditmemo_items' => [
467 'title' =>
'recycling_fee',
468 'base_row_amount' => 0,
470 'base_row_amount_incl_tax' => 0,
471 'row_amount_incl_tax' => 0,
476 'creditmemo_data' => [
478 'base_subtotal' => 300,
490 protected function getInvoiceItem($creditmemoItemData)
497 foreach ($creditmemoItemData[
'order_item'] as $key =>
$value) {
501 $this->weeeData->expects($this->once())
502 ->method(
'getRowWeeeTaxInclTax')
504 ->will($this->returnValue(
$orderItem->getRowWeeeTaxInclTax()));
505 $this->weeeData->expects($this->once())
506 ->method(
'getBaseRowWeeeTaxInclTax')
508 ->will($this->returnValue(
$orderItem->getBaseRowWeeeTaxInclTax()));
509 $this->weeeData->expects($this->once())
510 ->method(
'getWeeeAmountInvoiced')
512 ->will($this->returnValue(
$orderItem->getWeeeAmountInvoiced()));
513 $this->weeeData->expects($this->once())
514 ->method(
'getBaseWeeeAmountInvoiced')
516 ->will($this->returnValue(
$orderItem->getBaseWeeeAmountInvoiced()));
517 $this->weeeData->expects($this->once())
518 ->method(
'getWeeeTaxAmountInvoiced')
520 ->will($this->returnValue(
$orderItem->getWeeeTaxAmountInvoiced()));
521 $this->weeeData->expects($this->once())
522 ->method(
'getBaseWeeeTaxAmountInvoiced')
524 ->will($this->returnValue(
$orderItem->getBaseWeeeTaxAmountInvoiced()));
525 $this->weeeData->expects($this->once())
526 ->method(
'getWeeeAmountRefunded')
528 ->will($this->returnValue(
$orderItem->getWeeeAmountRefunded()));
529 $this->weeeData->expects($this->once())
530 ->method(
'getBaseWeeeAmountRefunded')
532 ->will($this->returnValue(
$orderItem->getBaseWeeeAmountRefunded()));
533 $this->weeeData->expects($this->once())
534 ->method(
'getWeeeTaxAmountRefunded')
536 ->will($this->returnValue(
$orderItem->getWeeeTaxAmountRefunded()));
537 $this->weeeData->expects($this->once())
538 ->method(
'getBaseWeeeTaxAmountRefunded')
540 ->will($this->returnValue(
$orderItem->getBaseWeeeTaxAmountRefunded()));
551 ->will($this->returnValue($creditmemoItemData[
'is_last']));
552 foreach ($creditmemoItemData[
'data_fields'] as $key =>
$value) {
556 $this->weeeData->expects($this->any())
557 ->method(
'getApplied')
558 ->will($this->returnCallback(
560 return $item->getAppliedWeee();
564 $this->weeeData->expects($this->any())
565 ->method(
'setApplied')
566 ->will($this->returnCallback(
567 function (
$item, $weee) {
568 return $item->setAppliedWeee($weee);