forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocialTraitTest.php
More file actions
138 lines (125 loc) · 4.63 KB
/
Copy pathSocialTraitTest.php
File metadata and controls
138 lines (125 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2018, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Test\TestCase\Controller\Traits;
use Authentication\Authenticator\Result;
use Authentication\Authenticator\SessionAuthenticator;
use Authentication\Identifier\IdentifierCollection;
use CakeDC\Auth\Authentication\Failure;
use CakeDC\Auth\Authenticator\FormAuthenticator;
use CakeDC\Users\Authenticator\SocialAuthenticator;
use CakeDC\Users\Controller\Component\LoginComponent;
use Cake\Controller\ComponentRegistry;
use Cake\Event\Event;
use Cake\Http\Response;
use Cake\Http\ServerRequest;
class SocialTraitTest extends BaseTraitTest
{
/**
* setup
*
* @return void
*/
public function setUp()
{
$this->traitClassName = 'CakeDC\Users\Controller\Traits\SocialTrait';
$this->traitMockMethods = ['dispatchEvent', 'isStopped', 'redirect', 'getUsersTable', 'set'];
parent::setUp();
$request = new ServerRequest();
$this->Trait = $this->getMockBuilder('CakeDC\Users\Controller\Traits\SocialTrait')
->setMethods(['dispatchEvent', 'redirect', 'set', 'loadComponent', 'getRequest'])
->getMockForTrait();
$this->Trait->request = $request;
}
/**
* tearDown
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
}
/**
* test socialLogin success
*
* @return void
*/
public function testSocialEmailSuccess()
{
$identifiers = new IdentifierCollection([
'CakeDC/Users.Social'
]);
$FormAuth = new FormAuthenticator($identifiers);
$SessionAuth = new SessionAuthenticator($identifiers);
$sessionFailure = new Failure(
$SessionAuth,
new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND)
);
$formFailure = new Failure(
$FormAuth,
new Result(null, Result::FAILURE_CREDENTIALS_MISSING, [
'Password' => []
])
);
$failures = [$sessionFailure, $formFailure];
$this->_mockDispatchEvent(new Event('event'));
$this->Trait->request = $this->getMockBuilder('Cake\Http\ServerRequest')
->setMethods(['is'])
->getMock();
$this->Trait->request->expects($this->any())
->method('is')
->with('post')
->will($this->returnValue(true));
$this->_mockFlash();
$this->_mockAuthentication(['id' => 1], $failures);
$this->Trait->Flash->expects($this->never())
->method('error');
$this->Trait->expects($this->once())
->method('redirect')
->with($this->successLoginRedirect)
->will($this->returnValue(new Response()));
$this->Trait->expects($this->any())
->method('getRequest')
->will($this->returnValue($this->Trait->request));
$registry = new ComponentRegistry();
$config = [
'component' => 'CakeDC/Users.Login',
'defaultMessage' => __d('cake_d_c/users', 'Could not proceed with social account. Please try again'),
'messages' => [
SocialAuthenticator::FAILURE_USER_NOT_ACTIVE => __d(
'cake_d_c/users',
'Your user has not been validated yet. Please check your inbox for instructions'
),
SocialAuthenticator::FAILURE_ACCOUNT_NOT_ACTIVE => __d(
'cake_d_c/users',
'Your social account has not been validated yet. Please check your inbox for instructions'
)
],
'targetAuthenticator' => SocialAuthenticator::class
];
$Login = $this->getMockBuilder(LoginComponent::class)
->setMethods(['getController'])
->setConstructorArgs([$registry, $config])
->getMock();
$Login->expects($this->any())
->method('getController')
->will($this->returnValue($this->Trait));
$this->Trait->expects($this->any())
->method('loadComponent')
->with(
$this->equalTo('CakeDC/Users.Login'),
$this->equalTo($config)
)
->will($this->returnValue($Login));
$result = $this->Trait->socialEmail();
$this->assertInstanceOf(Response::class, $result);
}
}