forked from mapasculturais/mapasculturais
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthTest.php
More file actions
87 lines (65 loc) · 3.38 KB
/
Copy pathAuthTest.php
File metadata and controls
87 lines (65 loc) · 3.38 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
<?php
require_once __DIR__.'/bootstrap.php';
/**
* Description of TestAuthentication
*
* @author rafael
*/
class AuthTest extends MapasCulturais_TestCase{
function testAuthentication(){
$this->user = null;
$app = $this->app;
// guest user
$this->assertFalse($app->auth->isUserAuthenticated(), 'Asserting that the user is not authenticated.');
$this->assertTrue($app->user->is('guest'), 'Asserting that the user is guest.');
// superadmin
$this->user = 'superAdmin';
$this->assertTrue($app->auth->isUserAuthenticated(), 'Asserting that the user is authenticated.');
$this->assertFalse($app->user->is('guest'), 'Asserting that the user is not guest.');
$this->assertTrue($app->user->is('admin'), 'Asserting that the user is admin.');
$this->assertTrue($app->user->is('superAdmin'), 'Asserting that the user is superAdmin.');
$app->auth->logout();
// guest user
$this->assertFalse($app->auth->isUserAuthenticated(), 'Asserting that the user is not authenticated.');
$this->assertTrue($app->user->is('guest'), 'Asserting that the user is guest.');
}
function testSuperAdminAuthentication(){
$this->user = 'superAdmin';
$this->assertTrue($this->app->user->is('superAdmin'), 'Asserting that the user is super admin.');
}
function testAdminAuthentication(){
$this->user = 'admin';
$this->assertTrue($this->app->user->is('admin'), 'Asserting that the user is admin.');
$this->assertFalse($this->app->user->is('superAdmin'), 'Asserting that the user is not super admin.');
}
function testNormalAuthentication(){
$this->user = 'normal';
$this->assertFalse($this->app->user->is('guest'), 'Asserting that the user is not guest.');
$this->assertFalse($this->app->user->is('staff'), 'Asserting that the user is not admin.');
$this->assertFalse($this->app->user->is('admin'), 'Asserting that the user is not admin.');
$this->assertFalse($this->app->user->is('superAdmin'), 'Asserting that the user is not super admin.');
}
function testStaffAuthentication(){
$this->user = 'staff';
$this->assertTrue($this->app->user->is('staff'), 'Asserting that the user is staff.');
$this->assertFalse($this->app->user->is('admin'), 'Asserting that the user is not admin.');
$this->assertFalse($this->app->user->is('superAdmin'), 'Asserting that the user is not super admin.');
}
function testRequireAuthentication(){
$this->user = null;
$app = $this->app;
$this->assertEquals('200', $app->response->status(), 'Asserting response status code is 200');
try{
$app->auth->requireAuthentication();
} catch (\Exception $e){}
$this->assertEquals('401', $app->response->status(), 'Asserting response status code is 401');
$app->response->status(200);
$this->assertEquals('200', $app->response->status(), 'Asserting response status code is 200');
try{
$app->controller("space")->requireAuthentication();
} catch (\Exception $e){}
$this->assertEquals('401', $app->response->status(), 'Asserting response status code is 401');
$app->response->status(200);
$this->assertEquals('200', $app->response->status(), 'Asserting response status code is 200');
}
}