forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthFinderBehaviorTest.php
More file actions
104 lines (94 loc) · 2.52 KB
/
Copy pathAuthFinderBehaviorTest.php
File metadata and controls
104 lines (94 loc) · 2.52 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
<?php
/**
* Copyright 2010 - 2017, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2017, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Test\TestCase\Model\Behavior;
use CakeDC\Users\Exception\UserAlreadyActiveException;
use CakeDC\Users\Model\Behavior\AuthFinderBehavior;
use CakeDC\Users\Model\Table\UsersTable;
use Cake\Mailer\Email;
use Cake\ORM\TableRegistry;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
use Cake\Utility\Hash;
use InvalidArgumentException;
/**
* Test Case
*/
class AuthFinderBehaviorTest extends TestCase
{
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'plugin.CakeDC/Users.Users',
];
/**
* setup
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->table = TableRegistry::getTableLocator()->get('CakeDC/Users.Users');
$this->Behavior = new AuthFinderBehavior($this->table);
}
/**
* tearDown
*
* @return void
*/
public function tearDown()
{
unset($this->table, $this->Behavior);
parent::tearDown();
}
/**
* Test findActive method.
*
*/
public function testFindActive()
{
$actual = $this->table->find('active')->toArray();
$this->assertCount(8, $actual);
$this->assertCount(8, Hash::extract($actual, '{n}[active=1]'));
$this->assertCount(0, Hash::extract($actual, '{n}[active=0]'));
}
/**
* Test findAuth method.
*
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Missing 'username' in options data
*/
public function testFindAuthBadMethodCallException()
{
$user = $this->table->find('auth');
}
/**
* Test findAuth method.
*
* @expected
*/
public function testFindAuth()
{
$user = $this->table
->find('auth', ['username' => 'not-exist@email.com'])
->toArray();
$this->assertEmpty($user);
$user = $this->table
->find('auth', ['username' => 'user-2@test.com'])
->first()
->toArray();
$this->assertSame('00000000-0000-0000-0000-000000000002', Hash::get($user, 'id'));
$this->assertSame('user-2', Hash::get($user, 'username'));
}
}