7
7
8
8
namespace Magento \GraphQl \SendFriend ;
9
9
10
- use Magento \Framework \DataObjectFactory ;
11
10
use Magento \SendFriend \Model \SendFriend ;
12
11
use Magento \SendFriend \Model \SendFriendFactory ;
13
12
use Magento \TestFramework \Helper \Bootstrap ;
@@ -27,7 +26,7 @@ protected function setUp()
27
26
}
28
27
29
28
/**
30
- * @magentoApiDataFixture Magento/SendFriend /_files/product_simple.php
29
+ * @magentoApiDataFixture Magento/Catalog /_files/product_simple.php
31
30
*/
32
31
public function testSendFriend ()
33
32
{
@@ -122,7 +121,7 @@ public function testSendWithoutExistProduct()
122
121
}
123
122
124
123
/**
125
- * @magentoApiDataFixture Magento/SendFriend /_files/product_simple.php
124
+ * @magentoApiDataFixture Magento/Catalog /_files/product_simple.php
126
125
*/
127
126
public function testMaxSendEmailToFriend ()
128
127
{
@@ -186,31 +185,19 @@ public function testMaxSendEmailToFriend()
186
185
}
187
186
188
187
/**
189
- * @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
188
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
189
+ * @dataProvider sendFriendsErrorsDataProvider
190
+ * @param string $input
191
+ * @param string $errorMessage
190
192
*/
191
- public function testSendWithoutRecipientName ( )
193
+ public function testErrors ( string $ input , string $ errorMessage )
192
194
{
193
195
$ query =
194
196
<<<QUERY
195
197
mutation {
196
198
sendEmailToFriend(
197
199
input: {
198
- product_id: 1
199
- sender: {
200
- name: "Name"
201
- email: "e@mail.com"
202
- message: "Lorem Ipsum"
203
- }
204
- recipients: [
205
- {
206
- name: ""
207
- email:"recipient1@mail.com"
208
- },
209
- {
210
- name: ""
211
- email:"recipient2@mail.com"
212
- }
213
- ]
200
+ $ input
214
201
}
215
202
) {
216
203
sender {
@@ -226,37 +213,44 @@ public function testSendWithoutRecipientName()
226
213
}
227
214
QUERY ;
228
215
$ this ->expectException (\Exception::class);
229
- $ this ->expectExceptionMessage (' Please provide Name for all of recipients. ' );
216
+ $ this ->expectExceptionMessage ($ errorMessage );
230
217
$ this ->graphQlQuery ($ query );
231
218
}
232
219
233
220
/**
234
- * @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
221
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
222
+ * TODO: use magentoApiConfigFixture (to be merged https://github.com/magento/graphql-ce/pull/351)
223
+ * @magentoApiDataFixture Magento/SendFriend/Fixtures/sendfriend_configuration.php
235
224
*/
236
- public function testSendWithoutRecipientEmail ()
225
+ public function testLimitMessagesPerHour ()
237
226
{
227
+
228
+ /** @var SendFriend $sendFriend */
229
+ $ sendFriend = $ this ->sendFriendFactory ->create ();
230
+
238
231
$ query =
239
232
<<<QUERY
240
233
mutation {
241
234
sendEmailToFriend(
242
235
input: {
243
- product_id: 1
236
+ product_id: 1
244
237
sender: {
245
238
name: "Name"
246
239
email: "e@mail.com"
247
240
message: "Lorem Ipsum"
248
- }
241
+ }
249
242
recipients: [
250
- {
243
+ {
251
244
name: "Recipient Name 1"
252
- email:""
245
+ email:"recipient1@mail.com "
253
246
},
254
- {
247
+ {
255
248
name: "Recipient Name 2"
256
- email:""
257
- }
249
+ email:"recipient2@mail.com"
250
+ }
251
+
258
252
]
259
- }
253
+ }
260
254
) {
261
255
sender {
262
256
name
@@ -271,115 +265,63 @@ public function testSendWithoutRecipientEmail()
271
265
}
272
266
QUERY ;
273
267
$ this ->expectException (\Exception::class);
274
- $ this ->expectExceptionMessage ('Please provide Email for all of recipients. ' );
275
- $ this ->graphQlQuery ($ query );
268
+ $ this ->expectExceptionMessage (
269
+ "You can't send messages more than {$ sendFriend ->getMaxSendsToFriend ()} times an hour. "
270
+ );
271
+
272
+ for ($ i = 0 ; $ i <= $ sendFriend ->getMaxSendsToFriend () + 1 ; $ i ++) {
273
+ $ this ->graphQlQuery ($ query );
274
+ }
276
275
}
277
276
278
277
/**
279
- * @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
278
+ * @return array
280
279
*/
281
- public function testSendWithoutSenderName ()
280
+ public function sendFriendsErrorsDataProvider ()
282
281
{
283
- $ query =
284
- <<<QUERY
285
- mutation {
286
- sendEmailToFriend(
287
- input: {
288
- product_id: 1
289
- sender: {
290
- name: ""
282
+ return [
283
+ [
284
+ 'product_id: 1
285
+ sender: {
286
+ name: "Name"
291
287
email: "e@mail.com"
292
288
message: "Lorem Ipsum"
293
289
}
294
290
recipients: [
295
291
{
296
- name: "Recipient Name 1 "
292
+ name: ""
297
293
email:"recipient1@mail.com"
298
294
},
299
295
{
300
- name: "Recipient Name 2 "
296
+ name: ""
301
297
email:"recipient2@mail.com"
302
298
}
303
- ]
304
- }
305
- ) {
306
- sender {
307
- name
308
- email
309
- message
310
- }
311
- recipients {
312
- name
313
- email
314
- }
315
- }
316
- }
317
- QUERY ;
318
- $ this ->expectException (\Exception::class);
319
- $ this ->expectExceptionMessage ('Please provide Name of sender. ' );
320
- $ this ->graphQlQuery ($ query );
321
- }
322
-
323
- /**
324
- * @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
325
- */
326
- public function testSendWithoutSenderEmail ()
327
- {
328
- $ query =
329
- <<<QUERY
330
- mutation {
331
- sendEmailToFriend(
332
- input: {
333
- product_id: 1
299
+ ] ' , 'Please provide Name for all of recipients. '
300
+ ],
301
+ [
302
+ 'product_id: 1
334
303
sender: {
335
304
name: "Name"
336
- email: ""
305
+ email: "e@mail.com "
337
306
message: "Lorem Ipsum"
338
307
}
339
308
recipients: [
340
309
{
341
310
name: "Recipient Name 1"
342
- email:"recipient1@mail.com "
311
+ email:""
343
312
},
344
313
{
345
314
name: "Recipient Name 2"
346
- email:"recipient2@mail.com "
315
+ email:""
347
316
}
348
- ]
349
- }
350
- ) {
351
- sender {
352
- name
353
- email
354
- message
355
- }
356
- recipients {
357
- name
358
- email
359
- }
360
- }
361
- }
362
- QUERY ;
363
- $ this ->expectException (\Exception::class);
364
- $ this ->expectExceptionMessage ('Please provide Email of sender. ' );
365
- $ this ->graphQlQuery ($ query );
366
- }
367
-
368
- /**
369
- * @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
370
- */
371
- public function testSendWithoutSenderMessage ()
372
- {
373
- $ query =
374
- <<<QUERY
375
- mutation {
376
- sendEmailToFriend(
377
- input: {
378
- product_id: 1
317
+ ] ' , 'Please provide Email for all of recipients. '
318
+ ],
319
+ [
320
+ 'product_id: 1
379
321
sender: {
380
- name: "Name "
322
+ name: ""
381
323
email: "e@mail.com"
382
- message: ""
324
+ message: "Lorem Ipsum "
383
325
}
384
326
recipients: [
385
327
{
@@ -390,79 +332,26 @@ public function testSendWithoutSenderMessage()
390
332
name: "Recipient Name 2"
391
333
email:"recipient2@mail.com"
392
334
}
393
- ]
394
- }
395
- ) {
396
- sender {
397
- name
398
- email
399
- message
400
- }
401
- recipients {
402
- name
403
- email
404
- }
405
- }
406
- }
407
- QUERY ;
408
- $ this ->expectException (\Exception::class);
409
- $ this ->expectExceptionMessage ('Please provide Message. ' );
410
- $ this ->graphQlQuery ($ query );
411
- }
412
-
413
- /**
414
- * @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
415
- * @magentoApiDataFixture Magento/SendFriend/Fixtures/sendfriend_configuration.php
416
- */
417
- public function testLimitMessagesPerHour ()
418
- {
419
-
420
- /** @var SendFriend $sendFriend */
421
- $ sendFriend = $ this ->sendFriendFactory ->create ();
422
-
423
- $ query =
424
- <<<QUERY
425
- mutation {
426
- sendEmailToFriend(
427
- input: {
428
- product_id: 1
335
+ ] ' , 'Please provide Name of sender. '
336
+ ],
337
+ [
338
+ 'product_id: 1
429
339
sender: {
430
340
name: "Name"
431
341
email: "e@mail.com"
432
- message: "Lorem Ipsum "
433
- }
342
+ message: ""
343
+ }
434
344
recipients: [
435
- {
345
+ {
436
346
name: "Recipient Name 1"
437
347
email:"recipient1@mail.com"
438
348
},
439
- {
349
+ {
440
350
name: "Recipient Name 2"
441
351
email:"recipient2@mail.com"
442
- }
443
-
444
- ]
445
- }
446
- ) {
447
- sender {
448
- name
449
- email
450
- message
451
- }
452
- recipients {
453
- name
454
- email
455
- }
456
- }
457
- }
458
- QUERY ;
459
- $ this ->expectException (\Exception::class);
460
- $ this ->expectExceptionMessage (
461
- "You can't send messages more than {$ sendFriend ->getMaxSendsToFriend ()} times an hour. "
462
- );
463
-
464
- for ($ i = 0 ; $ i <= $ sendFriend ->getMaxSendsToFriend () + 1 ; $ i ++) {
465
- $ this ->graphQlQuery ($ query );
466
- }
352
+ }
353
+ ] ' , 'Please provide Message. '
354
+ ]
355
+ ];
467
356
}
468
357
}
0 commit comments