forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSuperuserAuthorizeTest.php
More file actions
93 lines (83 loc) · 2.5 KB
/
Copy pathSuperuserAuthorizeTest.php
File metadata and controls
93 lines (83 loc) · 2.5 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
<?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 CakeDC\Users\Test\TestCase\Auth;
use CakeDC\Users\Auth\SuperuserAuthorize;
use Cake\Controller\ComponentRegistry;
use Cake\Controller\Controller;
use Cake\Event\EventManager;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\TestSuite\TestCase;
class SuperuserAuthorizeTest extends TestCase
{
/**
* @var SuperuserAuthorize
*/
protected $superuserAuthorize;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$request = new Request();
$response = new Response();
$this->controller = $this->getMock(
'Cake\Controller\Controller',
null,
[$request, $response]
);
$registry = new ComponentRegistry($this->controller);
$this->superuserAuthorize = new SuperuserAuthorize($registry);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
public function tearDown()
{
unset($this->superuserAuthorize, $this->controller);
}
/**
* @covers CakeDC\Users\Auth\SuperuserAuthorize::authorize
*/
public function testAuthorizeIsSuperuser()
{
$user = [
'is_superuser' => true,
];
$request = new Request();
$result = $this->superuserAuthorize->authorize($user, $request);
$this->assertTrue($result);
}
/**
* @covers CakeDC\Users\Auth\SuperuserAuthorize::authorize
*/
public function testAuthorizeIsNotSuperuser()
{
$user = [
'is_superuser' => false,
];
$request = new Request();
$result = $this->superuserAuthorize->authorize($user, $request);
$this->assertFalse($result);
}
/**
* @covers CakeDC\Users\Auth\SuperuserAuthorize::authorize
*/
public function testAuthorizeWeirdUser()
{
$request = new Request();
$user = 'non array';
$result = $this->superuserAuthorize->authorize($user, $request);
$this->assertFalse($result);
}
}