8
8
namespace Magento \GraphQl \Customer ;
9
9
10
10
use Magento \TestFramework \TestCase \GraphQlAbstract ;
11
- use PHPUnit \Framework \TestResult ;
12
11
13
12
/**
14
- * Class GenerateCustomerTokenTest
15
- * @package Magento\GraphQl\Customer
13
+ * API-functional tests cases for generateCustomerToken mutation
16
14
*/
17
15
class GenerateCustomerTokenTest extends GraphQlAbstract
18
16
{
@@ -23,87 +21,95 @@ class GenerateCustomerTokenTest extends GraphQlAbstract
23
21
*/
24
22
public function testGenerateCustomerValidToken ()
25
23
{
26
- $ userName = 'customer@example.com ' ;
24
+ $ email = 'customer@example.com ' ;
27
25
$ password = 'password ' ;
28
26
29
- $ mutation
30
- = <<<MUTATION
31
- mutation {
32
- generateCustomerToken(
33
- email: " {$ userName }"
34
- password: " {$ password }"
35
- ) {
36
- token
37
- }
38
- }
39
- MUTATION ;
27
+ $ mutation = $ this ->getQuery ($ email , $ password );
40
28
41
29
$ response = $ this ->graphQlMutation ($ mutation );
42
30
$ this ->assertArrayHasKey ('generateCustomerToken ' , $ response );
43
31
$ this ->assertInternalType ('array ' , $ response ['generateCustomerToken ' ]);
44
32
}
45
33
46
34
/**
47
- * Verify customer with invalid credentials
35
+ * Test customer with invalid data.
36
+ *
37
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
38
+ * @expectedException \Exception
39
+ *
40
+ * @dataProvider dataProviderInvalidCustomerInfo
41
+ * @param string $email
42
+ * @param string $password
43
+ * @param string $message
48
44
*/
49
- public function testGenerateCustomerTokenWithInvalidCredentials ( )
45
+ public function testGenerateCustomerTokenInvalidData ( string $ email , string $ password , string $ message )
50
46
{
51
- $ userName = 'customer@example.com ' ;
52
- $ password = 'bad-password ' ;
53
-
54
- $ mutation
55
- = <<<MUTATION
56
- mutation {
57
- generateCustomerToken(
58
- email: " {$ userName }"
59
- password: " {$ password }"
60
- ) {
61
- token
62
- }
63
- }
64
- MUTATION ;
65
-
66
- $ this ->expectException (\Exception::class);
67
- $ this ->expectExceptionMessage ('GraphQL response contains errors: The account sign-in ' . ' ' .
68
- 'was incorrect or your account is disabled temporarily. Please wait and try again later. ' );
47
+ $ mutation = $ this ->getQuery ($ email , $ password );
48
+ $ this ->expectExceptionMessage ($ message );
69
49
$ this ->graphQlMutation ($ mutation );
70
50
}
71
51
72
52
/**
73
- * Verify customer with empty email
53
+ * Test customer token regeneration.
54
+ *
55
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
74
56
*/
75
- public function testGenerateCustomerTokenWithEmptyEmail ()
57
+ public function testRegenerateCustomerToken ()
76
58
{
77
- $ email = '' ;
78
- $ password = 'bad- password ' ;
59
+ $ email = 'customer@example.com ' ;
60
+ $ password = 'password ' ;
79
61
80
- $ mutation
81
- = <<<MUTATION
82
- mutation {
83
- generateCustomerToken(
84
- email: " {$ email }"
85
- password: " {$ password }"
86
- ) {
87
- token
88
- }
89
- }
90
- MUTATION ;
62
+ $ mutation = $ this ->getQuery ($ email , $ password );
91
63
92
- $ this ->expectException (\Exception::class);
93
- $ this ->expectExceptionMessage ('GraphQL response contains errors: Specify the "email" value. ' );
94
- $ this ->graphQlMutation ($ mutation );
64
+ $ response1 = $ this ->graphQlMutation ($ mutation );
65
+ $ token1 = $ response1 ['generateCustomerToken ' ]['token ' ];
66
+
67
+ $ response2 = $ this ->graphQlMutation ($ mutation );
68
+ $ token2 = $ response2 ['generateCustomerToken ' ]['token ' ];
69
+
70
+ $ this ->assertNotEquals ($ token1 , $ token2 , 'Tokens should not be identical! ' );
95
71
}
96
72
97
73
/**
98
- * Verify customer with empty password
74
+ * @return array
99
75
*/
100
- public function testGenerateCustomerTokenWithEmptyPassword ()
76
+ public function dataProviderInvalidCustomerInfo (): array
101
77
{
102
- $ email = 'customer@example.com ' ;
103
- $ password = '' ;
78
+ return [
79
+ 'invalid_email ' => [
80
+ 'invalid_email@example.com ' ,
81
+ 'password ' ,
82
+ 'The account sign-in was incorrect or your account is disabled temporarily. ' .
83
+ 'Please wait and try again later. '
84
+ ],
85
+ 'empty_email ' => [
86
+ '' ,
87
+ 'password ' ,
88
+ 'Specify the "email" value. '
89
+ ],
90
+ 'invalid_password ' => [
91
+ 'customer@example.com ' ,
92
+ 'invalid_password ' ,
93
+ 'The account sign-in was incorrect or your account is disabled temporarily. ' .
94
+ 'Please wait and try again later. '
95
+ ],
96
+ 'empty_password ' => [
97
+ 'customer@example.com ' ,
98
+ '' ,
99
+ 'Specify the "password" value. '
100
+
101
+ ]
102
+ ];
103
+ }
104
104
105
- $ mutation
106
- = <<<MUTATION
105
+ /**
106
+ * @param string $email
107
+ * @param string $password
108
+ * @return string
109
+ */
110
+ private function getQuery (string $ email , string $ password ) : string
111
+ {
112
+ return <<<MUTATION
107
113
mutation {
108
114
generateCustomerToken(
109
115
email: " {$ email }"
@@ -113,9 +119,5 @@ public function testGenerateCustomerTokenWithEmptyPassword()
113
119
}
114
120
}
115
121
MUTATION ;
116
-
117
- $ this ->expectException (\Exception::class);
118
- $ this ->expectExceptionMessage ('GraphQL response contains errors: Specify the "password" value. ' );
119
- $ this ->graphQlMutation ($ mutation );
120
122
}
121
123
}
0 commit comments