forked from rmcdaniel/angular-codeigniter-seed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnitTest.php
70 lines (58 loc) · 1.83 KB
/
UnitTest.php
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
<?php
class UnitTest extends PHPUnit_Framework_TestCase
{
private $CI;
private function login($email = '[email protected]', $password = 'password123')
{
$_POST['email'] = $email;
$_POST['password'] = $password;
$this->CI->User = load_controller('User');
return json_decode($this->CI->User->login())->output;
}
private function register($email = '[email protected]', $password = 'password123')
{
$_POST['email'] = $email;
$_POST['password'] = $password;
$this->CI->User = load_controller('User');
return json_decode($this->CI->User->register())->output;
}
private function permissions($resource = 'administrator')
{
$output = $this->login();
$_POST['token'] = $output->token;
$_POST['resource'] = $resource;
return json_decode($this->CI->User->permissions())->output;
}
public function setUp()
{
$this->CI = &get_instance();
$this->CI->CLI = load_controller('CLI');
$this->CI->CLI->install();
$this->CI->CLI->add('administrator', '[email protected]', 'password123');
}
public function testLoginSuccess()
{
$this->assertTrue($this->login()->status);
}
public function testLoginFail()
{
$this->assertFalse($this->login('')->status);
$this->assertFalse($this->login('[email protected]', 'password456')->status);
}
public function testRegisterSuccess()
{
$this->assertTrue($this->register()->status);
}
public function testRegisterFail()
{
$this->assertFalse($this->register('')->status);
}
public function testPermissionsSuccess()
{
$this->assertTrue($this->permissions()->status);
}
public function testPermissionsFail()
{
$this->assertFalse($this->permissions('')->status);
}
}