11
11
12
12
namespace CakeDC \Users \Test \TestCase \Auth ;
13
13
14
+ use CakeDC \Users \Auth \SocialAuthenticate ;
14
15
use CakeDC \Users \Controller \Component \UsersAuthComponent ;
15
16
use CakeDC \Users \Exception \AccountNotActiveException ;
16
17
use CakeDC \Users \Exception \MissingEmailException ;
@@ -64,7 +65,7 @@ public function setUp()
64
65
65
66
$ this ->Request = $ request ;
66
67
$ this ->SocialAuthenticate = $ this ->_getSocialAuthenticateMockMethods (['_authenticate ' , '_getProviderName ' ,
67
- '_mapUser ' , '_socialLogin ' , 'dispatchEvent ' , '_validateConfig ' , '_getController ' ]);
68
+ '_mapUser ' , '_socialLogin ' , 'dispatchEvent ' , '_validateConfig ' , '_getController ' ]);
68
69
69
70
$ this ->SocialAuthenticate ->expects ($ this ->any ())
70
71
->method ('_getController ' )
@@ -95,6 +96,57 @@ protected function _getSocialAuthenticateMockMethods($methods)
95
96
->getMock ();
96
97
}
97
98
99
+ /**
100
+ * test
101
+ *
102
+ * @expectedException \CakeDC\Users\Auth\Exception\MissingProviderConfigurationException
103
+ */
104
+ public function testConstructorMissingConfig ()
105
+ {
106
+ $ socialAuthenticate = new SocialAuthenticate (new ComponentRegistry ($ this ->controller ));
107
+ }
108
+
109
+ /**
110
+ * test
111
+ *
112
+ */
113
+ public function testConstructor ()
114
+ {
115
+ $ socialAuthenticate = new SocialAuthenticate (new ComponentRegistry ($ this ->controller ), [
116
+ 'providers ' => [
117
+ 'facebook ' => [
118
+ 'className ' => 'League\OAuth2\Client\Provider\Facebook ' ,
119
+ 'options ' => [
120
+ 'graphApiVersion ' => 'v2.5 ' ,
121
+ 'redirectUri ' => 'http://example.com/auth/facebook ' ,
122
+ ]
123
+ ]
124
+ ]
125
+ ]);
126
+
127
+ $ this ->assertInstanceOf ('\CakeDC\Users\Auth\SocialAuthenticate ' , $ socialAuthenticate );
128
+ }
129
+
130
+ /**
131
+ * test
132
+ *
133
+ * @expectedException \CakeDC\Users\Auth\Exception\InvalidProviderException
134
+ */
135
+ public function testConstructorMissingProvider ()
136
+ {
137
+ $ socialAuthenticate = new SocialAuthenticate (new ComponentRegistry ($ this ->controller ), [
138
+ 'providers ' => [
139
+ 'facebook ' => [
140
+ 'className ' => 'missing ' ,
141
+ 'options ' => [
142
+ 'graphApiVersion ' => 'v2.5 ' ,
143
+ 'redirectUri ' => 'http://example.com/auth/facebook ' ,
144
+ ]
145
+ ]
146
+ ]
147
+ ]);
148
+ }
149
+
98
150
/**
99
151
* Test getUser
100
152
*
@@ -109,9 +161,9 @@ public function testGetUserAuth($rawData, $mapper)
109
161
->with (UsersAuthComponent::EVENT_AFTER_REGISTER , compact ('user ' ));
110
162
111
163
$ this ->SocialAuthenticate ->expects ($ this ->once ())
112
- ->method ('_authenticate ' )
113
- ->with ($ this ->Request )
114
- ->will ($ this ->returnValue ($ rawData ));
164
+ ->method ('_authenticate ' )
165
+ ->with ($ this ->Request )
166
+ ->will ($ this ->returnValue ($ rawData ));
115
167
116
168
$ this ->SocialAuthenticate ->expects ($ this ->once ())
117
169
->method ('_getProviderName ' )
@@ -186,11 +238,11 @@ public function testGetUserSessionData()
186
238
{
187
239
$ user = [
'username ' =>
'username ' ,
'email ' =>
'[email protected] ' ];
188
240
$ this ->SocialAuthenticate = $ this ->_getSocialAuthenticateMockMethods (['_authenticate ' ,
189
- '_getProviderName ' , '_mapUser ' , '_touch ' , '_validateConfig ' ]);
241
+ '_getProviderName ' , '_mapUser ' , '_touch ' , '_validateConfig ' ]);
190
242
191
243
$ session = $ this ->getMockBuilder ('Cake\Network\Session ' )
192
- ->setMethods (['read ' , 'delete ' ])
193
- ->getMock ();
244
+ ->setMethods (['read ' , 'delete ' ])
245
+ ->getMock ();
194
246
$ session ->expects ($ this ->once ())
195
247
->method ('read ' )
196
248
->with ('Users.social ' )
@@ -201,8 +253,8 @@ public function testGetUserSessionData()
201
253
->with ('Users.social ' );
202
254
203
255
$ this ->Request = $ this ->getMockBuilder ('Cake\Network\Request ' )
204
- ->setMethods (['session ' ])
205
- ->getMock ();
256
+ ->setMethods (['session ' ])
257
+ ->getMock ();
206
258
$ this ->Request ->expects ($ this ->any ())
207
259
->method ('session ' )
208
260
->will ($ this ->returnValue ($ session ));
@@ -432,7 +484,7 @@ public function testMapUser($data, $mappedData)
432
484
public function providerMapper ()
433
485
{
434
486
return [
435
- [
487
+ [
436
488
'rawData ' => [
437
489
'id ' => 'my-facebook-id ' ,
438
490
'name ' => 'My name. ' ,
@@ -463,7 +515,7 @@ public function providerMapper()
463
515
],
464
516
'provider ' => 'Facebook '
465
517
],
466
- ]
518
+ ]
467
519
468
520
];
469
521
}
@@ -493,7 +545,7 @@ public function testNormalizeConfig($data, $oauth2, $callTimes, $enabledNoOAuth2
493
545
{
494
546
Configure::write ('OAuth2 ' , $ oauth2 );
495
547
$ this ->SocialAuthenticate = $ this ->_getSocialAuthenticateMockMethods (['_authenticate ' ,
496
- '_getProviderName ' , '_mapUser ' , '_touch ' , '_validateConfig ' , '_normalizeConfig ' ]);
548
+ '_getProviderName ' , '_mapUser ' , '_touch ' , '_validateConfig ' , '_normalizeConfig ' ]);
497
549
498
550
$ this ->SocialAuthenticate ->expects ($ this ->exactly ($ callTimes ))
499
551
->method ('_normalizeConfig ' );
0 commit comments