Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractItemTest.php
Go to the documentation of this file.
1 <?php
7 
11 class AbstractItemTest extends \PHPUnit\Framework\TestCase
12 {
22  public function testGetTotalDiscountAmount($expectedDiscountAmount, $children, $calculated, $myDiscountAmount)
23  {
24  $abstractItemMock = $this->getMockForAbstractClass(
25  \Magento\Quote\Model\Quote\Item\AbstractItem::class,
26  [],
27  '',
28  false,
29  false,
30  true,
31  ['getChildren', 'isChildrenCalculated', 'getDiscountAmount']
32  );
33  $abstractItemMock->expects($this->any())
34  ->method('getChildren')
35  ->will($this->returnValue($children));
36  $abstractItemMock->expects($this->any())
37  ->method('isChildrenCalculated')
38  ->will($this->returnValue($calculated));
39  $abstractItemMock->expects($this->any())
40  ->method('getDiscountAmount')
41  ->will($this->returnValue($myDiscountAmount));
42 
43  $totalDiscountAmount = $abstractItemMock->getTotalDiscountAmount();
44  $this->assertEquals($expectedDiscountAmount, $totalDiscountAmount);
45  }
46 
51  {
52  $childOneDiscountAmount = 1000;
53  $childOneItemMock = $this->getMockForAbstractClass(
54  \Magento\Quote\Model\Quote\Item\AbstractItem::class,
55  [],
56  '',
57  false,
58  false,
59  true,
60  ['getDiscountAmount']
61  );
62  $childOneItemMock->expects($this->any())
63  ->method('getDiscountAmount')
64  ->will($this->returnValue($childOneDiscountAmount));
65 
66  $childTwoDiscountAmount = 50;
67  $childTwoItemMock = $this->getMockForAbstractClass(
68  \Magento\Quote\Model\Quote\Item\AbstractItem::class,
69  [],
70  '',
71  false,
72  false,
73  true,
74  ['getDiscountAmount']
75  );
76  $childTwoItemMock->expects($this->any())
77  ->method('getDiscountAmount')
78  ->will($this->returnValue($childTwoDiscountAmount));
79 
80  $valueHasNoEffect = 0;
81 
82  $data = [
83  'no_children' => [
84  10,
85  [],
86  false,
87  10,
88  ],
89  'kids_but_not_calculated' => [
90  10,
91  [$childOneItemMock],
92  false,
93  10,
94  ],
95  'one_kid' => [
96  $childOneDiscountAmount,
97  [$childOneItemMock],
98  true,
99  $valueHasNoEffect,
100  ],
101  'two_kids' => [
102  $childOneDiscountAmount + $childTwoDiscountAmount,
103  [$childOneItemMock, $childTwoItemMock],
104  true,
105  $valueHasNoEffect,
106  ],
107  ];
108  return $data;
109  }
110 }
testGetTotalDiscountAmount($expectedDiscountAmount, $children, $calculated, $myDiscountAmount)
$children
Definition: actions.phtml:11