8
8
namespace Magento \GraphQl \Customer ;
9
9
10
10
use Magento \Customer \Api \CustomerRepositoryInterface ;
11
- use Magento \Customer \ Model \ CustomerRegistry ;
11
+ use Magento \Framework \ Registry ;
12
12
use Magento \TestFramework \Helper \Bootstrap ;
13
13
use Magento \TestFramework \TestCase \GraphQlAbstract ;
14
14
15
+ /**
16
+ * Test for create customer functionallity
17
+ */
15
18
class CreateCustomerTest extends GraphQlAbstract
16
19
{
17
20
/**
18
- * @var CustomerRegistry
21
+ * @var Registry
19
22
*/
20
- private $ customerRegistry ;
23
+ private $ registry ;
21
24
22
25
/**
23
26
* @var CustomerRepositoryInterface
@@ -28,7 +31,7 @@ protected function setUp()
28
31
{
29
32
parent ::setUp ();
30
33
31
- $ this ->customerRegistry = Bootstrap::getObjectManager ()->get (CustomerRegistry ::class);
34
+ $ this ->registry = Bootstrap::getObjectManager ()->get (Registry ::class);
32
35
$ this ->customerRepository = Bootstrap::getObjectManager ()->get (CustomerRepositoryInterface::class);
33
36
}
34
37
@@ -40,7 +43,7 @@ public function testCreateCustomerAccountWithPassword()
40
43
$ newFirstname = 'Richard ' ;
41
44
$ newLastname = 'Rowe ' ;
42
45
$ currentPassword = 'test123# ' ;
43
- $ newEmail = 'customer_created ' . rand ( 1 , 2000000 ) . ' @example.com ' ;
46
+ $ newEmail = 'new_customer @example.com ' ;
44
47
45
48
$ query = <<<QUERY
46
49
mutation {
@@ -50,7 +53,7 @@ public function testCreateCustomerAccountWithPassword()
50
53
lastname: " {$ newLastname }"
51
54
email: " {$ newEmail }"
52
55
password: " {$ currentPassword }"
53
- is_subscribed: true
56
+ is_subscribed: true
54
57
}
55
58
) {
56
59
customer {
@@ -78,7 +81,7 @@ public function testCreateCustomerAccountWithoutPassword()
78
81
{
79
82
$ newFirstname = 'Richard ' ;
80
83
$ newLastname = 'Rowe ' ;
81
- $ newEmail = 'customer_created ' . rand ( 1 , 2000000 ) . ' @example.com ' ;
84
+ $ newEmail = 'new_customer @example.com ' ;
82
85
83
86
$ query = <<<QUERY
84
87
mutation {
@@ -87,7 +90,7 @@ public function testCreateCustomerAccountWithoutPassword()
87
90
firstname: " {$ newFirstname }"
88
91
lastname: " {$ newLastname }"
89
92
email: " {$ newEmail }"
90
- is_subscribed: true
93
+ is_subscribed: true
91
94
}
92
95
) {
93
96
customer {
@@ -151,7 +154,7 @@ public function testCreateCustomerIfEmailMissed()
151
154
firstname: " {$ newFirstname }"
152
155
lastname: " {$ newLastname }"
153
156
password: " {$ currentPassword }"
154
- is_subscribed: true
157
+ is_subscribed: true
155
158
}
156
159
) {
157
160
customer {
@@ -186,7 +189,7 @@ public function testCreateCustomerIfEmailIsNotValid()
186
189
lastname: " {$ newLastname }"
187
190
email: " {$ newEmail }"
188
191
password: " {$ currentPassword }"
189
- is_subscribed: true
192
+ is_subscribed: true
190
193
}
191
194
) {
192
195
customer {
@@ -211,7 +214,7 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput()
211
214
$ newFirstname = 'Richard ' ;
212
215
$ newLastname = 'Rowe ' ;
213
216
$ currentPassword = 'test123# ' ;
214
- $ newEmail = 'customer_created ' . rand ( 1 , 2000000 ) . ' @example.com ' ;
217
+ $ newEmail = 'new_customer @example.com ' ;
215
218
216
219
$ query = <<<QUERY
217
220
mutation {
@@ -222,7 +225,7 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput()
222
225
test123: "123test123"
223
226
email: " {$ newEmail }"
224
227
password: " {$ currentPassword }"
225
- is_subscribed: true
228
+ is_subscribed: true
226
229
}
227
230
) {
228
231
customer {
@@ -237,4 +240,21 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput()
237
240
QUERY ;
238
241
$ this ->graphQlQuery ($ query );
239
242
}
243
+
244
+ public function tearDown ()
245
+ {
246
+ $ newEmail = 'new_customer@example.com ' ;
247
+ try {
248
+ $ customer = $ this ->customerRepository ->get ($ newEmail );
249
+ } catch (\Exception $ exception ) {
250
+ return ;
251
+ }
252
+
253
+ $ this ->registry ->unregister ('isSecureArea ' );
254
+ $ this ->registry ->register ('isSecureArea ' , true );
255
+ $ this ->customerRepository ->delete ($ customer );
256
+ $ this ->registry ->unregister ('isSecureArea ' );
257
+ $ this ->registry ->register ('isSecureArea ' , false );
258
+ parent ::tearDown ();
259
+ }
240
260
}
0 commit comments