7
7
8
8
namespace Magento \GraphQl \SendFriend ;
9
9
10
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
10
11
use Magento \SendFriend \Model \SendFriend ;
11
12
use Magento \SendFriend \Model \SendFriendFactory ;
12
13
use Magento \TestFramework \Helper \Bootstrap ;
@@ -22,52 +23,32 @@ class SendFriendTest extends GraphQlAbstract
22
23
* @var SendFriendFactory
23
24
*/
24
25
private $ sendFriendFactory ;
26
+ /**
27
+ * @var ProductRepositoryInterface
28
+ */
29
+ private $ productRepository ;
25
30
26
31
protected function setUp ()
27
32
{
28
33
$ this ->sendFriendFactory = Bootstrap::getObjectManager ()->get (SendFriendFactory::class);
34
+ $ this ->productRepository = Bootstrap::getObjectManager ()->get (ProductRepositoryInterface::class);
29
35
}
30
36
31
37
/**
32
- * @magentoApiDataFixture Magento/Catalog/_files/product_simple .php
38
+ * @magentoApiDataFixture Magento/GraphQl/ Catalog/_files/simple_product .php
33
39
*/
34
40
public function testSendFriend ()
35
41
{
36
- $ query =
37
- <<<QUERY
38
- mutation {
39
- sendEmailToFriend(
40
- input: {
41
- product_id: 1
42
- sender: {
43
- name: "Name"
44
- email: "e@mail.com"
45
- message: "Lorem Ipsum"
46
- }
47
- recipients: [
48
- {
42
+ $ productId = (int )$ this ->productRepository ->get ('simple_product ' )->getId ();
43
+ $ recipients = '{
49
44
name: "Recipient Name 1"
50
45
email:"recipient1@mail.com"
51
46
},
52
47
{
53
48
name: "Recipient Name 2"
54
49
email:"recipient2@mail.com"
55
- }
56
- ]
57
- }
58
- ) {
59
- sender {
60
- name
61
- email
62
- message
63
- }
64
- recipients {
65
- name
66
- email
67
- }
68
- }
69
- }
70
- QUERY ;
50
+ } ' ;
51
+ $ query = $ this ->getQuery ($ productId , $ recipients );
71
52
72
53
$ response = $ this ->graphQlMutation ($ query );
73
54
self ::assertEquals ('Name ' , $ response ['sendEmailToFriend ' ]['sender ' ]['name ' ]);
@@ -81,41 +62,17 @@ public function testSendFriend()
81
62
82
63
public function testSendWithoutExistProduct ()
83
64
{
84
- $ query =
85
- <<<QUERY
86
- mutation {
87
- sendEmailToFriend(
88
- input: {
89
- product_id: 2018
90
- sender: {
91
- name: "Name"
92
- email: "e@mail.com"
93
- message: "Lorem Ipsum"
94
- }
95
- recipients: [
96
- {
65
+ $ productId = 2018 ;
66
+ $ recipients = '{
97
67
name: "Recipient Name 1"
98
68
email:"recipient1@mail.com"
99
69
},
100
70
{
101
71
name: "Recipient Name 2"
102
72
email:"recipient2@mail.com"
103
- }
104
- ]
105
- }
106
- ) {
107
- sender {
108
- name
109
- email
110
- message
111
- }
112
- recipients {
113
- name
114
- email
115
- }
116
- }
117
- }
118
- QUERY ;
73
+ } ' ;
74
+ $ query = $ this ->getQuery ($ productId , $ recipients );
75
+
119
76
$ this ->expectException (\Exception::class);
120
77
$ this ->expectExceptionMessage (
121
78
'The product that was requested doesn \'t exist. Verify the product and try again. '
@@ -124,26 +81,15 @@ public function testSendWithoutExistProduct()
124
81
}
125
82
126
83
/**
127
- * @magentoApiDataFixture Magento/Catalog/_files/product_simple .php
84
+ * @magentoApiDataFixture Magento/GraphQl/ Catalog/_files/simple_product .php
128
85
*/
129
86
public function testMaxSendEmailToFriend ()
130
87
{
131
88
/** @var SendFriend $sendFriend */
132
89
$ sendFriend = $ this ->sendFriendFactory ->create ();
133
90
134
- $ query =
135
- <<<QUERY
136
- mutation {
137
- sendEmailToFriend(
138
- input: {
139
- product_id: 1
140
- sender: {
141
- name: "Name"
142
- email: "e@mail.com"
143
- message: "Lorem Ipsum"
144
- }
145
- recipients: [
146
- {
91
+ $ productId = (int )$ this ->productRepository ->get ('simple_product ' )->getId ();
92
+ $ recipients = '{
147
93
name: "Recipient Name 1"
148
94
email:"recipient1@mail.com"
149
95
},
@@ -166,22 +112,10 @@ public function testMaxSendEmailToFriend()
166
112
{
167
113
name: "Recipient Name 1"
168
114
email:"recipient1@mail.com"
169
- }
170
- ]
171
- }
172
- ) {
173
- sender {
174
- name
175
- email
176
- message
177
- }
178
- recipients {
179
- name
180
- email
181
- }
182
- }
183
- }
184
- QUERY ;
115
+ } ' ;
116
+
117
+ $ query = $ this ->getQuery ($ productId , $ recipients );
118
+
185
119
$ this ->expectException (\Exception::class);
186
120
$ this ->expectExceptionMessage ("No more than {$ sendFriend ->getMaxRecipients ()} emails can be sent at a time. " );
187
121
$ this ->graphQlMutation ($ query );
@@ -221,7 +155,7 @@ public function testErrors(string $input, string $errorMessage)
221
155
}
222
156
223
157
/**
224
- * @magentoApiDataFixture Magento/Catalog/_files/product_simple .php
158
+ * @magentoApiDataFixture Magento/GraphQl/ Catalog/_files/simple_product .php
225
159
* TODO: use magentoApiConfigFixture (to be merged https://github.com/magento/graphql-ce/pull/351)
226
160
* @magentoApiDataFixture Magento/SendFriend/Fixtures/sendfriend_configuration.php
227
161
*/
@@ -231,42 +165,17 @@ public function testLimitMessagesPerHour()
231
165
/** @var SendFriend $sendFriend */
232
166
$ sendFriend = $ this ->sendFriendFactory ->create ();
233
167
234
- $ query =
235
- <<<QUERY
236
- mutation {
237
- sendEmailToFriend(
238
- input: {
239
- product_id: 1
240
- sender: {
241
- name: "Name"
242
- email: "e@mail.com"
243
- message: "Lorem Ipsum"
244
- }
245
- recipients: [
246
- {
168
+ $ productId = (int )$ this ->productRepository ->get ('simple_product ' )->getId ();
169
+ $ recipients = '{
247
170
name: "Recipient Name 1"
248
171
email:"recipient1@mail.com"
249
172
},
250
- {
173
+ {
251
174
name: "Recipient Name 2"
252
175
email:"recipient2@mail.com"
253
- }
176
+ } ' ;
177
+ $ query = $ this ->getQuery ($ productId , $ recipients );
254
178
255
- ]
256
- }
257
- ) {
258
- sender {
259
- name
260
- email
261
- message
262
- }
263
- recipients {
264
- name
265
- email
266
- }
267
- }
268
- }
269
- QUERY ;
270
179
$ this ->expectException (\Exception::class);
271
180
$ this ->expectExceptionMessage (
272
181
"You can't send messages more than {$ sendFriend ->getMaxSendsToFriend ()} times an hour. "
@@ -278,6 +187,49 @@ public function testLimitMessagesPerHour()
278
187
}
279
188
}
280
189
190
+ /**
191
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
192
+ */
193
+ public function testSendProductWithoutSenderEmail ()
194
+ {
195
+ $ productId = (int )$ this ->productRepository ->get ('simple_product ' )->getId ();
196
+ $ recipients = '{
197
+ name: "Recipient Name 1"
198
+ email:""
199
+ } ' ;
200
+ $ query = $ this ->getQuery ($ productId , $ recipients );
201
+
202
+ $ this ->expectException (\Exception::class);
203
+ $ this ->expectExceptionMessage ('GraphQL response contains errors: Please provide Email for all of recipients. ' );
204
+ $ this ->graphQlMutation ($ query );
205
+ }
206
+
207
+ /**
208
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product_without_visibility.php
209
+ */
210
+ public function testSendProductWithoutVisibility ()
211
+ {
212
+ $ productId = (int )$ this ->productRepository ->get ('simple_product_without_visibility ' )->getId ();
213
+ $ recipients = '{
214
+ name: "Recipient Name 1"
215
+ email:"recipient1@mail.com"
216
+ },
217
+ {
218
+ name: "Recipient Name 2"
219
+ email:"recipient2@mail.com"
220
+ } ' ;
221
+ $ query = $ this ->getQuery ($ productId , $ recipients );
222
+
223
+ $ response = $ this ->graphQlMutation ($ query );
224
+ self ::assertEquals ('Name ' , $ response ['sendEmailToFriend ' ]['sender ' ]['name ' ]);
225
+ self ::assertEquals ('e@mail.com ' , $ response ['sendEmailToFriend ' ]['sender ' ]['email ' ]);
226
+ self ::assertEquals ('Lorem Ipsum ' , $ response ['sendEmailToFriend ' ]['sender ' ]['message ' ]);
227
+ self ::assertEquals ('Recipient Name 1 ' , $ response ['sendEmailToFriend ' ]['recipients ' ][0 ]['name ' ]);
228
+ self ::assertEquals ('recipient1@mail.com ' , $ response ['sendEmailToFriend ' ]['recipients ' ][0 ]['email ' ]);
229
+ self ::assertEquals ('Recipient Name 2 ' , $ response ['sendEmailToFriend ' ]['recipients ' ][1 ]['name ' ]);
230
+ self ::assertEquals ('recipient2@mail.com ' , $ response ['sendEmailToFriend ' ]['recipients ' ][1 ]['email ' ]);
231
+ }
232
+
281
233
/**
282
234
* @return array
283
235
*/
@@ -358,4 +310,38 @@ public function sendFriendsErrorsDataProvider()
358
310
]
359
311
];
360
312
}
313
+
314
+ /**
315
+ * @param int $productId
316
+ * @param string $recipients
317
+ * @return string
318
+ */
319
+ private function getQuery (int $ productId , string $ recipients ): string
320
+ {
321
+ return <<<QUERY
322
+ mutation {
323
+ sendEmailToFriend(
324
+ input: {
325
+ product_id: {$ productId }
326
+ sender: {
327
+ name: "Name"
328
+ email: "e@mail.com"
329
+ message: "Lorem Ipsum"
330
+ }
331
+ recipients: [ {$ recipients }]
332
+ }
333
+ ) {
334
+ sender {
335
+ name
336
+ email
337
+ message
338
+ }
339
+ recipients {
340
+ name
341
+ email
342
+ }
343
+ }
344
+ }
345
+ QUERY ;
346
+ }
361
347
}
0 commit comments