forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersAuthComponentTest.php
More file actions
126 lines (114 loc) · 3.86 KB
/
Copy pathUsersAuthComponentTest.php
File metadata and controls
126 lines (114 loc) · 3.86 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
<?php
/**
* Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Users\Test\TestCase\Controller\Component;
use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Database\Exception;
use Cake\Network\Session;
use Cake\ORM\Entity;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
use Cake\Utility\Security;
use Users\Controller\Component\UsersAuthComponent;
use Users\Exception\MissingEmailException;
use Users\Exception\UserNotFoundException;
/**
* Users\Controller\Component\UsersAuthComponent Test Case
*/
class UsersAuthComponentTest extends TestCase
{
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'plugin.users.users',
];
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->backupUsersConfig = Configure::read('Users');
Router::scope('/', function ($routes) {
$routes->fallbacks('InflectedRoute');
});
Router::plugin('Users', function ($routes) {
$routes->fallbacks('InflectedRoute');
});
Router::scope('/auth', function ($routes) {
$routes->connect(
'/*',
['plugin' => 'Users', 'controller' => 'Users', 'action' => 'opauthInit']
);
});
Router::connect('/a/validate/*', [
'admin' => false,
'plugin' => 'Users',
'controller' => 'SocialAccounts',
'action' => 'resendValidation'
]);
Security::salt('YJfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi');
Configure::write('App.namespace', 'Users');
$this->request = $this->getMock('Cake\Network\Request', ['is', 'method']);
$this->request->expects($this->any())->method('is')->will($this->returnValue(true));
$this->response = $this->getMock('Cake\Network\Response', ['stop']);
$this->Controller = new Controller($this->request, $this->response);
$this->Registry = $this->Controller->components();
$this->Controller->UsersAuth = new UsersAuthComponent($this->Registry);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
$_SESSION = [];
unset($this->Controller, $this->UsersAuth);
Configure::write('Users', $this->backupUsersConfig);
}
/**
* Test initialize
*
*/
public function testInitialize()
{
$this->Registry->unload('Auth');
$this->Controller->UsersAuth = new UsersAuthComponent($this->Registry);
$this->assertInstanceOf('Users\Controller\Component\UsersAuthComponent', $this->Controller->UsersAuth);
}
/**
* Test initialize with not rememberMe component needed
*
*/
public function testInitializeNoRequiredRememberMe()
{
Configure::write('Users.RememberMe.active', false);
$class = 'Users\Controller\Component\UsersAuthComponent';
$this->Controller->UsersAuth = $this->getMockBuilder($class)
->setMethods(['_loadRememberMe', '_initAuth', '_loadSocialLogin', '_attachPermissionChecker'])
->disableOriginalConstructor()
->getMock();
$this->Controller->UsersAuth->expects($this->once())
->method('_initAuth');
$this->Controller->UsersAuth->expects($this->once())
->method('_loadSocialLogin');
$this->Controller->UsersAuth->expects($this->never())
->method('_loadRememberMe');
$this->Controller->UsersAuth->initialize([]);
}
}