@@ -72,19 +72,9 @@ public function testShouldDenyIfUserHasNoPermission()
72
72
$ this ->assertEquals ('Not enough permission. ' , $ result ->getMessage ());
73
73
}
74
74
75
- public function testRequiredFieldsPermissions ()
75
+ public function testShouldRequireFirstNameField ()
76
76
{
77
- // create user and logged in
78
- $ user = User::create (array (
79
- 'first_name ' => 'darryl ' ,
80
-
81
- 'password ' => 'pass$darryl ' ,
82
- 'permissions ' => array (
83
- 'superuser ' => 1
84
- )
85
- ));
86
-
87
- $ this ->application ['auth ' ]->loginUsingId ($ user ->id );
77
+ $ this ->createUserAndLoggedIn (array ('superuser ' => 1 ));
88
78
89
79
// dummy request, required first name
90
80
$ request = Request::create ('' ,'GET ' ,array (
@@ -105,6 +95,11 @@ public function testRequiredFieldsPermissions()
105
95
$ this ->assertFalse ($ result ->isSuccessful (), 'Transaction should not be successful. ' );
106
96
$ this ->assertEquals (400 , $ result ->getStatusCode (), 'Status code should be 400 ' );
107
97
$ this ->assertEquals ('The first name field is required. ' , $ result ->getMessage ());
98
+ }
99
+
100
+ public function testShouldRequireLastName ()
101
+ {
102
+ $ this ->createUserAndLoggedIn (array ('superuser ' => 1 ));
108
103
109
104
// dummy request, required email
110
105
$ request = Request::create ('' ,'GET ' ,array (
@@ -124,13 +119,18 @@ public function testRequiredFieldsPermissions()
124
119
125
120
$ this ->assertFalse ($ result ->isSuccessful (), 'Transaction should not be successful. ' );
126
121
$ this ->assertEquals (400 , $ result ->getStatusCode (), 'Status code should be 400 ' );
127
- $ this ->assertEquals ('The email field is required. ' , $ result ->getMessage ());
122
+ $ this ->assertEquals ('The last name field is required. ' , $ result ->getMessage ());
123
+ }
124
+
125
+ public function testShouldRequireEmail ()
126
+ {
127
+ $ this ->createUserAndLoggedIn (array ('superuser ' => 1 ));
128
128
129
- // dummy request, required valid email
129
+ // dummy request, required email
130
130
$ request = Request::create ('' ,'GET ' ,array (
131
131
'firstName ' => 'John ' ,
132
- 'lastName ' => '' ,
133
- 'email ' => 'some invalid email ' ,
132
+ 'lastName ' => 'Doe ' ,
133
+ 'email ' => '' ,
134
134
'password ' => '' ,
135
135
'permissions ' => '' ,
136
136
'groups ' => array (),
@@ -144,13 +144,18 @@ public function testRequiredFieldsPermissions()
144
144
145
145
$ this ->assertFalse ($ result ->isSuccessful (), 'Transaction should not be successful. ' );
146
146
$ this ->assertEquals (400 , $ result ->getStatusCode (), 'Status code should be 400 ' );
147
- $ this ->assertEquals ('The email must be a valid email address. ' , $ result ->getMessage ());
147
+ $ this ->assertEquals ('The email field is required. ' , $ result ->getMessage ());
148
+ }
149
+
150
+ public function testShouldRequireEmailToBeUnique ()
151
+ {
152
+ $ this ->createUserAndLoggedIn (array ('superuser ' => 1 ));
148
153
149
- // dummy request, required unique email
154
+ // dummy request, required email
150
155
$ request = Request::create ('' ,'GET ' ,array (
151
156
'firstName ' => 'John ' ,
152
- 'lastName ' => '' ,
153
- 'email ' =>
'[email protected] ' ,
// this email is already used aboved
157
+ 'lastName ' => 'Doe ' ,
158
+ 'email ' =>
'[email protected] ' ,
// existing email
154
159
'password ' => '' ,
155
160
'permissions ' => '' ,
156
161
'groups ' => array (),
@@ -280,4 +285,17 @@ public function testShouldAssociateTheUserToTheGroupIfThereIsAnyProvided()
280
285
$ this ->assertTrue ($ createdUser ->inGroup ($ artist ), 'User should be in artist group ' );
281
286
$ this ->assertFalse ($ createdUser ->inGroup ($ moderator ), 'User should not be in moderator group ' );
282
287
}
288
+
289
+ protected function createUserAndLoggedIn ($ permissions )
290
+ {
291
+ // create user and logged in
292
+ $ user = User::create (array (
293
+ 'first_name ' => 'darryl ' ,
294
+
295
+ 'password ' => 'pass$darryl ' ,
296
+ 'permissions ' => $ permissions
297
+ ));
298
+
299
+ $ this ->application ['auth ' ]->loginUsingId ($ user ->id );
300
+ }
283
301
}
0 commit comments