7
7
8
8
namespace Magento \GraphQl \Customer ;
9
9
10
+ use Exception ;
10
11
use Magento \Customer \Api \CustomerRepositoryInterface ;
11
12
use Magento \Customer \Api \AddressRepositoryInterface ;
12
13
use Magento \TestFramework \Helper \Bootstrap ;
@@ -33,13 +34,19 @@ class DeleteCustomerAddressTest extends GraphQlAbstract
33
34
*/
34
35
private $ addressRepository ;
35
36
37
+ /**
38
+ * @var LockCustomer
39
+ */
40
+ private $ lockCustomer ;
41
+
36
42
protected function setUp ()
37
43
{
38
44
parent ::setUp ();
39
45
40
46
$ this ->customerTokenService = Bootstrap::getObjectManager ()->get (CustomerTokenServiceInterface::class);
41
47
$ this ->customerRepository = Bootstrap::getObjectManager ()->get (CustomerRepositoryInterface::class);
42
48
$ this ->addressRepository = Bootstrap::getObjectManager ()->get (AddressRepositoryInterface::class);
49
+ $ this ->lockCustomer = Bootstrap::getObjectManager ()->get (LockCustomer::class);
43
50
}
44
51
45
52
/**
@@ -64,7 +71,7 @@ public function testDeleteCustomerAddress()
64
71
}
65
72
66
73
/**
67
- * @expectedException \ Exception
74
+ * @expectedException Exception
68
75
* @expectedExceptionMessage The current customer isn't authorized.
69
76
*/
70
77
public function testDeleteCustomerAddressIfUserIsNotAuthorized ()
@@ -83,7 +90,7 @@ public function testDeleteCustomerAddressIfUserIsNotAuthorized()
83
90
* @magentoApiDataFixture Magento/Customer/_files/customer.php
84
91
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
85
92
*
86
- * @expectedException \ Exception
93
+ * @expectedException Exception
87
94
* @expectedExceptionMessage Customer Address 2 is set as default shipping address and can not be deleted
88
95
*/
89
96
public function testDeleteDefaultShippingCustomerAddress ()
@@ -109,7 +116,7 @@ public function testDeleteDefaultShippingCustomerAddress()
109
116
* @magentoApiDataFixture Magento/Customer/_files/customer.php
110
117
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
111
118
*
112
- * @expectedException \ Exception
119
+ * @expectedException Exception
113
120
* @expectedExceptionMessage Customer Address 2 is set as default billing address and can not be deleted
114
121
*/
115
122
public function testDeleteDefaultBillingCustomerAddress ()
@@ -134,7 +141,7 @@ public function testDeleteDefaultBillingCustomerAddress()
134
141
/**
135
142
* @magentoApiDataFixture Magento/Customer/_files/customer.php
136
143
*
137
- * @expectedException \ Exception
144
+ * @expectedException Exception
138
145
* @expectedExceptionMessage Could not find a address with ID "9999"
139
146
*/
140
147
public function testDeleteNonExistCustomerAddress ()
@@ -150,6 +157,120 @@ public function testDeleteNonExistCustomerAddress()
150
157
$ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password ));
151
158
}
152
159
160
+ /**
161
+ * Delete address with missing ID input.
162
+ *
163
+ * @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
164
+ * @expectedException Exception
165
+ * @expectedExceptionMessage Syntax Error: Expected Name, found )
166
+ * @throws Exception
167
+ */
168
+ public function testDeleteCustomerAddressWithMissingData ()
169
+ {
170
+ $ userName = 'customer@example.com ' ;
171
+ $ password = 'password ' ;
172
+ $ mutation
173
+ = <<<MUTATION
174
+ mutation {
175
+ deleteCustomerAddress()
176
+ }
177
+ MUTATION ;
178
+ $ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password ));
179
+ }
180
+
181
+ /**
182
+ * Delete address with incorrect ID input type.
183
+ *
184
+ * @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
185
+ * @expectedException Exception
186
+ * @expectedExceptionMessage Expected type Int!, found "".
187
+ * @throws Exception
188
+ */
189
+ public function testDeleteCustomerAddressWithIncorrectIdType ()
190
+ {
191
+ $ this ->markTestSkipped (
192
+ 'Type validation returns wrong message https://github.com/magento/graphql-ce/issues/735 '
193
+ );
194
+ $ userName = 'customer@example.com ' ;
195
+ $ password = 'password ' ;
196
+ $ mutation
197
+ = <<<MUTATION
198
+ mutation {
199
+ deleteCustomerAddress(id: "string")
200
+ }
201
+ MUTATION ;
202
+ $ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password ));
203
+ }
204
+
205
+ /**
206
+ * @magentoApiDataFixture Magento/Customer/_files/two_customers.php
207
+ * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
208
+ *
209
+ * @expectedException Exception
210
+ * @expectedExceptionMessage Current customer does not have permission to address with ID "2"
211
+ */
212
+ public function testDeleteAnotherCustomerAddress ()
213
+ {
214
+ $ userName = 'customer_two@example.com ' ;
215
+ $ password = 'password ' ;
216
+ $ addressId = 2 ;
217
+
218
+ $ mutation
219
+ = <<<MUTATION
220
+ mutation {
221
+ deleteCustomerAddress(id: {$ addressId })
222
+ }
223
+ MUTATION ;
224
+ $ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password ));
225
+ }
226
+
227
+ /**
228
+ * @magentoApiDataFixture Magento/Customer/_files/inactive_customer.php
229
+ * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
230
+ * @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
231
+ *
232
+ * @expectedException Exception
233
+ * @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily.
234
+ */
235
+ public function testDeleteInactiveCustomerAddress ()
236
+ {
237
+ $ userName = 'customer@needAconfirmation.com ' ;
238
+ $ password = 'password ' ;
239
+ $ addressId = 2 ;
240
+
241
+ $ mutation
242
+ = <<<MUTATION
243
+ mutation {
244
+ deleteCustomerAddress(id: {$ addressId })
245
+ }
246
+ MUTATION ;
247
+ $ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password ));
248
+ }
249
+
250
+ /**
251
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
252
+ * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
253
+ *
254
+ * @expectedException Exception
255
+ * @expectedExceptionMessage The account is locked
256
+ */
257
+ public function testDeleteCustomerAddressIfAccountIsLocked ()
258
+ {
259
+ $ userName = 'customer@example.com ' ;
260
+ $ password = 'password ' ;
261
+ $ addressId = 2 ;
262
+
263
+ $ this ->lockCustomer ->execute (1 );
264
+
265
+ $ mutation
266
+ = <<<MUTATION
267
+ mutation {
268
+ deleteCustomerAddress(id: {$ addressId })
269
+ }
270
+ MUTATION ;
271
+ $ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password ));
272
+ }
273
+
153
274
/**
154
275
* @param string $email
155
276
* @param string $password
0 commit comments