21
21
*/
22
22
class ResetQuoteAddressesTest extends TestCase
23
23
{
24
+ /**
25
+ * @var int
26
+ */
27
+ private const STUB_ADDRESS_ID = 1 ;
28
+
29
+ /**
30
+ * @var int
31
+ */
32
+ private const STUB_ITEM_ID = 1 ;
33
+
34
+ /**
35
+ * @var array
36
+ */
37
+ private const STUB_QUOTE_ITEMS = [1 , 2 ];
38
+
24
39
/**
25
40
* @var ResetQuoteAddresses
26
41
*/
@@ -65,11 +80,9 @@ protected function setUp()
65
80
*/
66
81
public function testRemovingTheAddressesFromNonEmptyQuote ()
67
82
{
68
- $ quoteVisibleItems = [1 , 2 ];
69
-
70
83
$ this ->quoteMock ->expects ($ this ->any ())
71
84
->method ('getAllVisibleItems ' )
72
- ->will ($ this ->returnValue ($ quoteVisibleItems ));
85
+ ->will ($ this ->returnValue (static :: STUB_QUOTE_ITEMS ));
73
86
$ this ->quoteMock ->expects ($ this ->never ())
74
87
->method ('getAllAddresses ' )
75
88
->willReturnSelf ();
@@ -78,46 +91,81 @@ public function testRemovingTheAddressesFromNonEmptyQuote()
78
91
}
79
92
80
93
/**
81
- * Test clearing the addresses from an empty quote
94
+ * Test clearing the addresses from an empty quote with addresses
95
+ *
96
+ * @dataProvider quoteAddressesDataProvider
82
97
*
83
- * @dataProvider quoteDataProvider
84
98
* @param bool $isVirtualQuote
85
- * @param bool $quoteHasAddresses
86
- * @param $extensionAttributes
99
+ * @param array $extensionAttributes
87
100
*/
88
- public function testClearingTheAddressesFromEmptyQuote (
101
+ public function testClearingAddressesSuccessfullyFromEmptyQuoteWithAddress (
89
102
bool $ isVirtualQuote ,
90
- bool $ quoteHasAddresses ,
91
- $ extensionAttributes
103
+ array $ extensionAttributes
92
104
) {
93
- $ quoteVisibleItems = [];
94
-
95
105
$ this ->quoteMock ->expects ($ this ->any ())
96
106
->method ('getAllVisibleItems ' )
97
- ->will ($ this ->returnValue ($ quoteVisibleItems ));
107
+ ->will ($ this ->returnValue ([] ));
98
108
99
- if ($ quoteHasAddresses ) {
100
- $ address = $ this ->createPartialMock (Address::class, ['getId ' ]);
109
+ $ address = $ this ->createPartialMock (Address::class, ['getId ' ]);
101
110
102
- $ address ->expects ($ this ->any ())
103
- ->method ('getId ' )
104
- ->willReturn (1 );
111
+ $ address ->expects ($ this ->any ())
112
+ ->method ('getId ' )
113
+ ->willReturn (static :: STUB_ADDRESS_ID );
105
114
106
- $ addresses = [$ address ];
115
+ $ addresses = [$ address ];
107
116
108
- $ this ->quoteMock ->expects ($ this ->any ())
109
- ->method ('getAllAddresses ' )
110
- ->will ($ this ->returnValue ($ addresses ));
117
+ $ this ->quoteMock ->expects ($ this ->any ())
118
+ ->method ('getAllAddresses ' )
119
+ ->will ($ this ->returnValue ($ addresses ));
111
120
112
- $ this ->quoteMock ->expects ($ this ->exactly (count ($ addresses )))
113
- ->method ('removeAddress ' )
121
+ $ this ->quoteMock ->expects ($ this ->exactly (count ($ addresses )))
122
+ ->method ('removeAddress ' )
123
+ ->willReturnSelf ();
124
+
125
+ $ this ->quoteMock ->expects ($ this ->once ())
126
+ ->method ('getExtensionAttributes ' )
127
+ ->willReturn ($ this ->extensionAttributesMock );
128
+
129
+ $ this ->quoteMock ->expects ($ this ->once ())
130
+ ->method ('isVirtual ' )
131
+ ->willReturn ($ isVirtualQuote );
132
+
133
+ if (!$ isVirtualQuote && $ extensionAttributes ) {
134
+ $ this ->extensionAttributesMock ->expects ($ this ->any ())
135
+ ->method ('getShippingAssignments ' )
136
+ ->willReturn ($ extensionAttributes );
137
+
138
+ $ this ->extensionAttributesMock ->expects ($ this ->once ())
139
+ ->method ('setShippingAssignments ' )
114
140
->willReturnSelf ();
115
- } else {
116
- $ this ->quoteMock ->expects ($ this ->any ())
117
- ->method ('getAllAddresses ' )
118
- ->willReturn ([]);
119
141
}
120
142
143
+ $ this ->plugin ->afterRemoveItem ($ this ->quoteMock , $ this ->quoteMock , static ::STUB_ITEM_ID );
144
+ }
145
+
146
+ /**
147
+ * Test clearing the addresses from an empty quote
148
+ *
149
+ * @dataProvider quoteNoAddressesDataProvider
150
+ *
151
+ * @param bool $isVirtualQuote
152
+ * @param array $extensionAttributes
153
+ */
154
+ public function testClearingTheAddressesFromEmptyQuote (
155
+ bool $ isVirtualQuote ,
156
+ array $ extensionAttributes
157
+ ) {
158
+ $ quoteVisibleItems = [];
159
+ $ addresses = [];
160
+
161
+ $ this ->quoteMock ->expects ($ this ->any ())
162
+ ->method ('getAllVisibleItems ' )
163
+ ->will ($ this ->returnValue ($ quoteVisibleItems ));
164
+
165
+ $ this ->quoteMock ->expects ($ this ->any ())
166
+ ->method ('getAllAddresses ' )
167
+ ->willReturn ($ addresses );
168
+
121
169
$ this ->quoteMock ->expects ($ this ->once ())
122
170
->method ('getExtensionAttributes ' )
123
171
->willReturn ($ this ->extensionAttributesMock );
@@ -126,45 +174,60 @@ public function testClearingTheAddressesFromEmptyQuote(
126
174
->method ('isVirtual ' )
127
175
->willReturn ($ isVirtualQuote );
128
176
129
- if ($ isVirtualQuote && $ extensionAttributes ) {
177
+ if (! $ isVirtualQuote && $ extensionAttributes ) {
130
178
$ this ->extensionAttributesMock ->expects ($ this ->any ())
131
179
->method ('getShippingAssignments ' )
132
- ->willReturn ([ 1 ] );
180
+ ->willReturn ($ extensionAttributes );
133
181
134
182
$ this ->extensionAttributesMock ->expects ($ this ->once ())
135
183
->method ('setShippingAssignments ' )
136
184
->willReturnSelf ();
137
185
}
138
186
139
- $ this ->plugin ->afterRemoveItem ($ this ->quoteMock , $ this ->quoteMock , 1 );
187
+ $ this ->plugin ->afterRemoveItem ($ this ->quoteMock , $ this ->quoteMock , static :: STUB_ITEM_ID );
140
188
}
141
189
142
190
/**
143
- * Quote information data provider
191
+ * Quote without address data provider
144
192
*
145
193
* @return array
146
194
*/
147
- public function quoteDataProvider (): array
195
+ public function quoteNoAddressesDataProvider (): array
148
196
{
149
197
return [
150
198
'Test case with virtual quote ' => [
151
199
true ,
152
- true ,
153
- null
154
- ],
155
- 'Test case with virtual quote and without a quote address ' => [
156
- true ,
157
- false ,
158
- null
200
+ []
159
201
],
160
202
'Test case with a non virtual quote without extension attributes ' => [
161
203
false ,
162
- true ,
163
204
[]
164
205
],
165
206
'Test case with a non virtual quote with shipping assignments ' => [
166
207
false ,
208
+ [1 ]
209
+ ]
210
+ ];
211
+ }
212
+
213
+ /**
214
+ * Quote with address information data provider
215
+ *
216
+ * @return array
217
+ */
218
+ public function quoteAddressesDataProvider (): array
219
+ {
220
+ return [
221
+ 'Test case with a virtual quote and no shipping assignments ' => [
167
222
true ,
223
+ []
224
+ ],
225
+ 'Test case with a virtual quote and with shipping assignments ' => [
226
+ true ,
227
+ [1 ]
228
+ ],
229
+ 'Test case with none virtual quote and with shipping assignments ' => [
230
+ false ,
168
231
[1 ]
169
232
]
170
233
];
0 commit comments