|
5 | 5 | */
|
6 | 6 | namespace Magento\OfflineShipping\Model\SalesRule;
|
7 | 7 |
|
8 |
| -class CalculatorForTest extends Calculator |
9 |
| -{ |
10 |
| - public function setValidatorUtility($validatorUtility) |
11 |
| - { |
12 |
| - $this->validatorUtility = $validatorUtility; |
13 |
| - } |
14 |
| -} |
15 |
| - |
16 | 8 | class CalculatorTest extends \PHPUnit_Framework_TestCase
|
17 | 9 | {
|
18 | 10 | /**
|
19 |
| - * @var \Magento\OfflineShipping\Model\SalesRule\CalculatorForTest|\PHPUnit_Framework_MockObject_MockObject |
| 11 | + * @var \Magento\SalesRule\Model\Validator|\PHPUnit_Framework_MockObject_MockObject |
20 | 12 | */
|
21 | 13 | protected $_model;
|
22 | 14 |
|
23 |
| - /** |
24 |
| - * @var \Magento\Sales\Model\Quote\Item\AbstractItem|\PHPUnit_Framework_MockObject_MockObject |
25 |
| - */ |
26 |
| - protected $itemMock; |
27 |
| - |
28 |
| - /** |
29 |
| - * @var \Magento\SalesRule\Model\Utility|\PHPUnit_Framework_MockObject_MockObject |
30 |
| - */ |
31 |
| - protected $utilityMock; |
32 |
| - |
33 |
| - /** |
34 |
| - * @var \Magento\SalesRule\Model\Rule|\PHPUnit_Framework_MockObject_MockObject |
35 |
| - */ |
36 |
| - protected $ruleMock; |
37 |
| - |
38 |
| - /** |
39 |
| - * @var \Magento\Sales\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject |
40 |
| - */ |
41 |
| - protected $addressMock; |
42 |
| - |
43 | 15 | protected function setUp()
|
44 | 16 | {
|
45 |
| - $this->utilityMock = $this->getMockBuilder('Magento\SalesRule\Model\Utility') |
46 |
| - ->disableOriginalConstructor() |
47 |
| - ->setMethods(['canProcessRule']) |
48 |
| - ->getMock(); |
49 |
| - |
50 |
| - $this->_model = $this->getMockBuilder('Magento\OfflineShipping\Model\SalesRule\CalculatorForTest') |
51 |
| - ->disableOriginalConstructor() |
52 |
| - ->setMethods(['_getRules', '__wakeup']) |
53 |
| - ->getMock(); |
54 |
| - |
55 |
| - $this->ruleMock = $this->getMockBuilder('Magento\SalesRule\Model\Rule') |
56 |
| - ->disableOriginalConstructor() |
57 |
| - ->setMethods(['getActions', 'getSimpleFreeShipping']) |
58 |
| - ->getMock(); |
59 |
| - |
60 |
| - $this->addressMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Address') |
61 |
| - ->disableOriginalConstructor() |
62 |
| - ->setMethods(['setFreeShipping']) |
63 |
| - ->getMock(); |
64 |
| - |
65 |
| - $this->_model->setValidatorUtility($this->utilityMock); |
66 |
| - |
67 |
| - $this->itemMock = $this->getMock('Magento\Sales\Model\Quote\Item', ['getAddress'], [], '', false); |
68 |
| - |
69 |
| - $this->itemMock->expects($this->once()) |
70 |
| - ->method('getAddress') |
71 |
| - ->willReturn($this->addressMock); |
| 17 | + $this->_model = $this->getMock( |
| 18 | + 'Magento\OfflineShipping\Model\SalesRule\Calculator', |
| 19 | + ['_getRules', '__wakeup'], |
| 20 | + [], |
| 21 | + '', |
| 22 | + false |
| 23 | + ); |
| 24 | + $this->_model->expects($this->any())->method('_getRules')->will($this->returnValue([])); |
72 | 25 | }
|
73 | 26 |
|
74 | 27 | public function testProcessFreeShipping()
|
75 | 28 | {
|
76 |
| - $this->_model->expects($this->any())->method('_getRules')->will($this->returnValue([])); |
| 29 | + $item = $this->getMock('Magento\Sales\Model\Quote\Item', ['getAddress', '__wakeup'], [], '', false); |
| 30 | + $item->expects($this->once())->method('getAddress')->will($this->returnValue(true)); |
77 | 31 |
|
78 | 32 | $this->assertInstanceOf(
|
79 | 33 | 'Magento\OfflineShipping\Model\SalesRule\Calculator',
|
80 |
| - $this->_model->processFreeShipping($this->itemMock) |
| 34 | + $this->_model->processFreeShipping($item) |
81 | 35 | );
|
82 |
| - } |
83 |
| - |
84 |
| - public function testProcessFreeShippingContinueOnProcessRule() |
85 |
| - { |
86 |
| - $this->_model->expects($this->once()) |
87 |
| - ->method('_getRules') |
88 |
| - ->willReturn(['rule1']); |
89 |
| - |
90 |
| - $this->utilityMock->expects($this->once()) |
91 |
| - ->method('canProcessRule') |
92 |
| - ->willReturn(false); |
93 |
| - |
94 |
| - $this->_model->processFreeShipping($this->itemMock); |
95 |
| - } |
96 |
| - |
97 |
| - public function testProcessFreeShippingContinueOnValidateItem() |
98 |
| - { |
99 |
| - $this->utilityMock->expects($this->once()) |
100 |
| - ->method('canProcessRule') |
101 |
| - ->willReturn(true); |
102 |
| - |
103 |
| - $actionsCollectionMock = $this->getMockBuilder('Magento\Rule\Model\Action\Collection') |
104 |
| - ->disableOriginalConstructor() |
105 |
| - ->setMethods(['validate']) |
106 |
| - ->getMock(); |
107 |
| - |
108 |
| - $actionsCollectionMock->expects($this->once()) |
109 |
| - ->method('validate') |
110 |
| - ->willReturn(false); |
111 |
| - |
112 |
| - $this->ruleMock->expects($this->once()) |
113 |
| - ->method('getActions') |
114 |
| - ->willReturn($actionsCollectionMock); |
115 |
| - |
116 |
| - $this->_model->expects($this->once()) |
117 |
| - ->method('_getRules') |
118 |
| - ->willReturn([$this->ruleMock]); |
119 |
| - |
120 |
| - $this->_model->processFreeShipping($this->itemMock); |
121 |
| - } |
122 | 36 |
|
123 |
| - /** |
124 |
| - * @dataProvider rulesDataProvider |
125 |
| - */ |
126 |
| - public function testProcessFreeShippingFreeShippingItem($rule) |
127 |
| - { |
128 |
| - $this->utilityMock->expects($this->once()) |
129 |
| - ->method('canProcessRule') |
130 |
| - ->willReturn(true); |
131 |
| - |
132 |
| - $actionsCollectionMock = $this->getMockBuilder('Magento\Rule\Model\Action\Collection') |
133 |
| - ->disableOriginalConstructor() |
134 |
| - ->setMethods(['validate']) |
135 |
| - ->getMock(); |
136 |
| - |
137 |
| - $actionsCollectionMock->expects($this->once()) |
138 |
| - ->method('validate') |
139 |
| - ->willReturn(true); |
140 |
| - |
141 |
| - $this->ruleMock->expects($this->once()) |
142 |
| - ->method('getActions') |
143 |
| - ->willReturn($actionsCollectionMock); |
144 |
| - |
145 |
| - $this->_model->expects($this->once()) |
146 |
| - ->method('_getRules') |
147 |
| - ->willReturn([$this->ruleMock]); |
148 |
| - |
149 |
| - $this->ruleMock->expects($this->once()) |
150 |
| - ->method('getSimpleFreeShipping') |
151 |
| - ->willReturn($rule); |
152 |
| - |
153 |
| - $this->addressMock->expects( |
154 |
| - $rule == \Magento\OfflineShipping\Model\SalesRule\Rule::FREE_SHIPPING_ADDRESS ? $this->once() : $this->never() |
155 |
| - )->method('setFreeShipping'); |
156 |
| - |
157 |
| - $this->_model->processFreeShipping($this->itemMock); |
158 |
| - } |
159 |
| - |
160 |
| - public function rulesDataProvider() |
161 |
| - { |
162 |
| - return [ |
163 |
| - [\Magento\OfflineShipping\Model\SalesRule\Rule::FREE_SHIPPING_ITEM], |
164 |
| - [\Magento\OfflineShipping\Model\SalesRule\Rule::FREE_SHIPPING_ADDRESS] |
165 |
| - ]; |
| 37 | + return true; |
166 | 38 | }
|
167 | 39 | }
|
0 commit comments