14 class DataTest extends \PHPUnit\Framework\TestCase
46 private $serializerMock;
50 $this->product = $this->createMock(\
Magento\Catalog\Model\Product::class);
51 $weeeConfig = $this->createMock(\
Magento\Weee\Model\Config::class);
52 $weeeConfig->expects($this->any())->method(
'isEnabled')->will($this->returnValue(
true));
53 $weeeConfig->expects($this->any())->method(
'getListPriceDisplayType')->will($this->returnValue(1));
54 $this->weeeTax = $this->createMock(\
Magento\Weee\Model\Tax::class);
55 $this->weeeTax->expects($this->any())->method(
'getWeeeAmount')->will($this->returnValue(
'11.26'));
56 $this->taxData = $this->createPartialMock(
57 \
Magento\Tax\Helper\Data::class,
58 [
'getPriceDisplayType',
'priceIncludesTax']
61 $this->serializerMock = $this->getMockBuilder(\
Magento\Framework\Serialize\Serializer\Json::class)->getMock();
64 'weeeConfig' => $weeeConfig,
67 'serializer' => $this->serializerMock
69 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
75 $this->product->expects($this->any())->method(
'hasData')->will($this->returnValue(
false));
76 $this->product->expects($this->any())->method(
'getData')->will($this->returnValue(11.26));
78 $this->assertEquals(
'11.26', $this->helperData->getAmountExclTax($this->product));
84 private function setupOrderItem()
87 ->disableOriginalConstructor()
88 ->setMethods([
'__wakeup'])
116 json_encode($weeeTaxApplied)
119 $this->serializerMock->expects($this->any())
120 ->method(
'unserialize')
121 ->will($this->returnValue($weeeTaxApplied));
130 $this->assertEquals(self::ROW_AMOUNT_INVOICED,
$value);
137 $this->assertEquals(self::BASE_ROW_AMOUNT_INVOICED,
$value);
144 $this->assertEquals(self::TAX_AMOUNT_INVOICED,
$value);
151 $this->assertEquals(self::BASE_TAX_AMOUNT_INVOICED,
$value);
158 $this->assertEquals(self::ROW_AMOUNT_REFUNDED,
$value);
165 $this->assertEquals(self::BASE_ROW_AMOUNT_REFUNDED,
$value);
172 $this->assertEquals(self::TAX_AMOUNT_REFUNDED,
$value);
179 $this->assertEquals(self::BASE_TAX_AMOUNT_REFUNDED,
$value);
188 public function testGetWeeeAttributesForBundle(
$priceDisplay, $priceIncludesTax, $expectedAmount)
192 $fptCode1 =
'fpt' . $prodId1;
193 $fptCode2 =
'fpt' . $prodId2;
195 $weeeObject1 = new \Magento\Framework\DataObject(
199 'amount_excl_tax' =>
'15.0000',
203 $weeeObject2 = new \Magento\Framework\DataObject(
207 'amount_excl_tax' =>
'10.0000',
211 $expectedObject1 = new \Magento\Framework\DataObject(
214 'amount' => $expectedAmount[0],
215 'amount_excl_tax' =>
'15.0000',
219 $expectedObject2 = new \Magento\Framework\DataObject(
222 'amount' => $expectedAmount[1],
223 'amount_excl_tax' =>
'10.0000',
228 $expectedArray = [$prodId1 => [$fptCode1 => $expectedObject1], $prodId2 => [$fptCode2 => $expectedObject2]];
229 $this->weeeTax->expects($this->any())
230 ->method(
'getProductWeeeAttributes')
231 ->will($this->returnValue([$weeeObject1, $weeeObject2]));
232 $this->taxData->expects($this->any())
233 ->method(
'getPriceDisplayType')
235 $this->taxData->expects($this->any())
236 ->method(
'priceIncludesTax')
237 ->willReturn($priceIncludesTax);
239 $productSimple = $this->createPartialMock(\
Magento\Catalog\Model\Product\Type\Simple::class, [
'getId']);
240 $productSimple->expects($this->at(0))
242 ->will($this->returnValue($prodId1));
243 $productSimple->expects($this->at(1))
245 ->will($this->returnValue($prodId2));
247 $productInstance = $this->createMock(\
Magento\Bundle\Model\Product\Type::class);
248 $productInstance->expects($this->any())
249 ->method(
'getSelectionsCollection')
250 ->will($this->returnValue([$productSimple]));
254 $product = $this->createPartialMock(
255 \
Magento\Catalog\Model\Product::class,
256 [
'getTypeInstance',
'getStoreId',
'getStore',
'getTypeId']
259 ->method(
'getTypeInstance')
260 ->will($this->returnValue($productInstance));
262 ->method(
'getStoreId')
263 ->will($this->returnValue(1));
266 ->will($this->returnValue(
$store));
268 ->method(
'getTypeId')
269 ->will($this->returnValue(
'bundle'));
274 ->with(
'current_product')
275 ->will($this->returnValue(
$product));
278 $this->assertEquals($expectedArray,
$result);
287 [2,
false, [
"16.00",
"15.00"]],
288 [2,
true, [
"15.00",
"10.00"]],
289 [1,
false, [
"15.00",
"10.00"]],
290 [1,
true, [
"15.00",
"10.00"]],
291 [3,
false, [
"16.00",
"15.00"]],
292 [3,
true, [
"15.00",
"10.00"]],
298 $testArray = [
'key' =>
'value'];
299 $itemProductSimple = $this->createPartialMock(
300 \
Magento\Quote\Model\Quote\Item::class,
301 [
'getWeeeTaxApplied',
'getHasChildren']
303 $itemProductSimple->expects($this->any())
304 ->method(
'getHasChildren')
305 ->will($this->returnValue(
false));
307 $itemProductSimple->expects($this->any())
308 ->method(
'getWeeeTaxApplied')
309 ->will($this->returnValue(json_encode($testArray)));
311 $this->serializerMock->expects($this->any())
312 ->method(
'unserialize')
313 ->will($this->returnValue($testArray));
315 $this->assertEquals($testArray, $this->helperData->getApplied($itemProductSimple));
320 $testArray1 = [
'key1' =>
'value1'];
321 $testArray2 = [
'key2' =>
'value2'];
323 $testArray = array_merge($testArray1, $testArray2);
325 $itemProductSimple1=$this->createPartialMock(\
Magento\Quote\Model\Quote\Item::class, [
'getWeeeTaxApplied']);
326 $itemProductSimple2=$this->createPartialMock(\
Magento\Quote\Model\Quote\Item::class, [
'getWeeeTaxApplied']);
328 $itemProductSimple1->expects($this->any())
329 ->method(
'getWeeeTaxApplied')
330 ->will($this->returnValue(json_encode($testArray1)));
332 $itemProductSimple2->expects($this->any())
333 ->method(
'getWeeeTaxApplied')
334 ->will($this->returnValue(json_encode($testArray2)));
336 $itemProductBundle = $this->createPartialMock(
337 \
Magento\Quote\Model\Quote\Item::class,
338 [
'getHasChildren',
'isChildrenCalculated',
'getChildren']
340 $itemProductBundle->expects($this->any())
341 ->method(
'getHasChildren')
342 ->will($this->returnValue(
true));
343 $itemProductBundle->expects($this->any())
344 ->method(
'isChildrenCalculated')
345 ->will($this->returnValue(
true));
346 $itemProductBundle->expects($this->any())
347 ->method(
'getChildren')
348 ->will($this->returnValue([$itemProductSimple1, $itemProductSimple2]));
350 $this->serializerMock->expects($this->any())
351 ->method(
'unserialize')
352 ->will($this->returnValue($testArray));
354 $this->assertEquals($testArray, $this->helperData->getApplied($itemProductBundle));
362 $itemProductSimple = $this->createPartialMock(
363 \
Magento\Quote\Model\Quote\Item::class,
364 [
'getHasChildren',
'getWeeeTaxAppliedAmount',
'getWeeeTaxAppliedRowAmount']
366 $itemProductSimple->expects($this->any())
367 ->method(
'getHasChildren')
368 ->will($this->returnValue(
false));
370 $itemProductSimple->expects($this->any())
371 ->method(
'getWeeeTaxAppliedAmount')
372 ->will($this->returnValue($testAmountUnit));
373 $itemProductSimple->expects($this->any())
374 ->method(
'getWeeeTaxAppliedRowAmount')
375 ->will($this->returnValue($testAmountRow));
377 $this->assertEquals($testAmountUnit, $this->helperData->getWeeeTaxAppliedAmount($itemProductSimple));
378 $this->assertEquals($testAmountRow, $this->helperData->getWeeeTaxAppliedRowAmount($itemProductSimple));
383 $testAmountUnit1 = 1;
384 $testAmountUnit2 = 2;
385 $testTotalUnit = $testAmountUnit1 + $testAmountUnit2;
387 $testAmountRow1 = 33;
388 $testAmountRow2 = 444;
389 $testTotalRow = $testAmountRow1 + $testAmountRow2;
391 $itemProductSimple1 = $this->createPartialMock(
392 \
Magento\Quote\Model\Quote\Item::class,
393 [
'getWeeeTaxAppliedAmount',
'getWeeeTaxAppliedRowAmount']
395 $itemProductSimple2 = $this->createPartialMock(
396 \
Magento\Quote\Model\Quote\Item::class,
397 [
'getWeeeTaxAppliedAmount',
'getWeeeTaxAppliedRowAmount']
400 $itemProductSimple1->expects($this->any())
401 ->method(
'getWeeeTaxAppliedAmount')
402 ->will($this->returnValue($testAmountUnit1));
403 $itemProductSimple1->expects($this->any())
404 ->method(
'getWeeeTaxAppliedRowAmount')
405 ->will($this->returnValue($testAmountRow1));
407 $itemProductSimple2->expects($this->any())
408 ->method(
'getWeeeTaxAppliedAmount')
409 ->will($this->returnValue($testAmountUnit2));
410 $itemProductSimple2->expects($this->any())
411 ->method(
'getWeeeTaxAppliedRowAmount')
412 ->will($this->returnValue($testAmountRow2));
414 $itemProductBundle = $this->createPartialMock(
415 \
Magento\Quote\Model\Quote\Item::class,
416 [
'getHasChildren',
'isChildrenCalculated',
'getChildren']
418 $itemProductBundle->expects($this->any())
419 ->method(
'getHasChildren')
420 ->will($this->returnValue(
true));
421 $itemProductBundle->expects($this->any())
422 ->method(
'isChildrenCalculated')
423 ->will($this->returnValue(
true));
424 $itemProductBundle->expects($this->any())
425 ->method(
'getChildren')
426 ->will($this->returnValue([$itemProductSimple1, $itemProductSimple2]));
428 $this->assertEquals($testTotalUnit, $this->helperData->getWeeeTaxAppliedAmount($itemProductBundle));
429 $this->assertEquals($testTotalRow, $this->helperData->getWeeeTaxAppliedRowAmount($itemProductBundle));
434 $store = $this->createMock(\
Magento\Store\Model\Store::class);
435 $this->product->expects($this->any())
437 ->will($this->returnValue(
$store));
439 $result = $this->helperData->getProductWeeeAttributesForDisplay($this->product);
446 $taxData = $this->createPartialMock(\
Magento\Tax\Helper\Data::class, [
'getPriceDisplayType']);
447 $taxData->expects($this->any())->method(
'getPriceDisplayType')->will($this->returnValue($expected));
451 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
454 $this->assertEquals($expected,
$helperData->getTaxDisplayConfig());
461 $expected = $item1Weee + $item2Weee;
462 $itemProductSimple1 = $this->createPartialMock(
463 \
Magento\Quote\Model\Quote\Item::class,
464 [
'getWeeeTaxAppliedRowAmount']
466 $itemProductSimple2 = $this->createPartialMock(
467 \
Magento\Quote\Model\Quote\Item::class,
468 [
'getWeeeTaxAppliedRowAmount']
470 $items = [$itemProductSimple1, $itemProductSimple2];
472 $itemProductSimple1->expects($this->any())
473 ->method(
'getWeeeTaxAppliedRowAmount')
474 ->willReturn($item1Weee);
475 $itemProductSimple2->expects($this->any())
476 ->method(
'getWeeeTaxAppliedRowAmount')
477 ->willReturn($item2Weee);
479 $this->assertEquals($expected, $this->helperData->getTotalAmounts(
$items));
486 $expected = $item1BaseWeee + $item2BaseWeee;
487 $itemProductSimple1 = $this->createPartialMock(
488 \
Magento\Quote\Model\Quote\Item::class,
489 [
'getBaseWeeeTaxAppliedRowAmnt']
491 $itemProductSimple2 = $this->createPartialMock(
492 \
Magento\Quote\Model\Quote\Item::class,
493 [
'getBaseWeeeTaxAppliedRowAmnt']
495 $items = [$itemProductSimple1, $itemProductSimple2];
497 $itemProductSimple1->expects($this->any())
498 ->method(
'getBaseWeeeTaxAppliedRowAmnt')
499 ->willReturn($item1BaseWeee);
500 $itemProductSimple2->expects($this->any())
501 ->method(
'getBaseWeeeTaxAppliedRowAmnt')
502 ->willReturn($item2BaseWeee);
504 $this->assertEquals($expected, $this->helperData->getBaseTotalAmounts(
$items));
testGetBaseWeeeAmountRefunded()
testGetBaseTotalAmounts()
testGetBaseWeeeAmountInvoiced()
const BASE_TAX_AMOUNT_INVOICED
dataProviderGetWeeeAttributesForBundle()
testGetWeeeTaxAmountInvoiced()
const TAX_AMOUNT_INVOICED
testGetWeeeAmountInvoiced()
const BASE_ROW_AMOUNT_INVOICED
const ROW_AMOUNT_INVOICED
const ROW_AMOUNT_REFUNDED
testGetProductWeeeAttributesForDisplay()
testGetRecursiveAmountBundle()
testGetRecursiveAmountSimple()
const BASE_TAX_AMOUNT_REFUNDED
testGetBaseWeeeTaxAmountRefunded()
testGetWeeeTaxAmountRefunded()
testGetWeeeAmountRefunded()
testGetWeeeBaseTaxAmountInvoiced()
const BASE_ROW_AMOUNT_REFUNDED
const TAX_AMOUNT_REFUNDED
testGetTaxDisplayConfig()