Skip to content

Commit 083f503

Browse files
committed
refs #add-tests-covering-typo add social authenticate tests covering typo
1 parent f70637d commit 083f503

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

src/Auth/SocialAuthenticate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(ComponentRegistry $registry, array $config = [])
7171
}
7272
$oauthConfig['providers'] = $providers;
7373
Configure::write('OAuth2', $oauthConfig);
74-
$config = $this->normalizeConfig(array_merge($config, $oauthConfig), $enabledNoOAuth2Provider);
74+
$config = $this->normalizeConfig(Hash::merge($config, $oauthConfig), $enabledNoOAuth2Provider);
7575
parent::__construct($registry, $config);
7676
}
7777

tests/TestCase/Auth/SocialAuthenticateTest.php

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CakeDC\Users\Test\TestCase\Auth;
1313

14+
use CakeDC\Users\Auth\SocialAuthenticate;
1415
use CakeDC\Users\Controller\Component\UsersAuthComponent;
1516
use CakeDC\Users\Exception\AccountNotActiveException;
1617
use CakeDC\Users\Exception\MissingEmailException;
@@ -64,7 +65,7 @@ public function setUp()
6465

6566
$this->Request = $request;
6667
$this->SocialAuthenticate = $this->_getSocialAuthenticateMockMethods(['_authenticate', '_getProviderName',
67-
'_mapUser', '_socialLogin', 'dispatchEvent', '_validateConfig', '_getController']);
68+
'_mapUser', '_socialLogin', 'dispatchEvent', '_validateConfig', '_getController']);
6869

6970
$this->SocialAuthenticate->expects($this->any())
7071
->method('_getController')
@@ -95,6 +96,57 @@ protected function _getSocialAuthenticateMockMethods($methods)
9596
->getMock();
9697
}
9798

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+
98150
/**
99151
* Test getUser
100152
*
@@ -109,9 +161,9 @@ public function testGetUserAuth($rawData, $mapper)
109161
->with(UsersAuthComponent::EVENT_AFTER_REGISTER, compact('user'));
110162

111163
$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));
115167

116168
$this->SocialAuthenticate->expects($this->once())
117169
->method('_getProviderName')
@@ -186,11 +238,11 @@ public function testGetUserSessionData()
186238
{
187239
$user = ['username' => 'username', 'email' => '[email protected]'];
188240
$this->SocialAuthenticate = $this->_getSocialAuthenticateMockMethods(['_authenticate',
189-
'_getProviderName', '_mapUser', '_touch', '_validateConfig' ]);
241+
'_getProviderName', '_mapUser', '_touch', '_validateConfig']);
190242

191243
$session = $this->getMockBuilder('Cake\Network\Session')
192-
->setMethods(['read', 'delete'])
193-
->getMock();
244+
->setMethods(['read', 'delete'])
245+
->getMock();
194246
$session->expects($this->once())
195247
->method('read')
196248
->with('Users.social')
@@ -201,8 +253,8 @@ public function testGetUserSessionData()
201253
->with('Users.social');
202254

203255
$this->Request = $this->getMockBuilder('Cake\Network\Request')
204-
->setMethods(['session'])
205-
->getMock();
256+
->setMethods(['session'])
257+
->getMock();
206258
$this->Request->expects($this->any())
207259
->method('session')
208260
->will($this->returnValue($session));
@@ -432,7 +484,7 @@ public function testMapUser($data, $mappedData)
432484
public function providerMapper()
433485
{
434486
return [
435-
[
487+
[
436488
'rawData' => [
437489
'id' => 'my-facebook-id',
438490
'name' => 'My name.',
@@ -463,7 +515,7 @@ public function providerMapper()
463515
],
464516
'provider' => 'Facebook'
465517
],
466-
]
518+
]
467519

468520
];
469521
}
@@ -493,7 +545,7 @@ public function testNormalizeConfig($data, $oauth2, $callTimes, $enabledNoOAuth2
493545
{
494546
Configure::write('OAuth2', $oauth2);
495547
$this->SocialAuthenticate = $this->_getSocialAuthenticateMockMethods(['_authenticate',
496-
'_getProviderName', '_mapUser', '_touch', '_validateConfig', '_normalizeConfig' ]);
548+
'_getProviderName', '_mapUser', '_touch', '_validateConfig', '_normalizeConfig']);
497549

498550
$this->SocialAuthenticate->expects($this->exactly($callTimes))
499551
->method('_normalizeConfig');

0 commit comments

Comments
 (0)