summaryrefslogtreecommitdiff
path: root/tests/unit/Security/TAuthManagerTest.php
blob: 7e628a615f7d9b1d06e317e2e8a9697f83b5be43 (plain)
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
<?php
require_once dirname(__FILE__).'/../phpunit.php';

Prado::using('System.Security.TAuthManager');
Prado::using('System.Security.TUserManager');
Prado::using('System.Xml.TXmlDocument');

/**
 * @package System.Security
 */
class TAuthManagerTest extends PHPUnit_Framework_TestCase {
	
	public static $app = null;
	public static $usrMgr = null;

	public function setUp() {
		ini_set('session.use_cookies',0);
		ini_set('session.cache_limiter', 'none');
		if(self::$app === null) {
			self::$app = new TApplication(dirname(__FILE__).'/app');
		}
		
		// Make a fake user manager module
		if (self::$usrMgr === null) {
			self::$usrMgr=new TUserManager ();
			$config=new TXmlDocument('1.0','utf8');
			$config->loadFromString('<users><user name="Joe" password="demo"/><user name="John" password="demo" /><role name="Administrator" users="John" /><role name="Writer" users="Joe,John" /></users>');
			self::$usrMgr->init($config);
			self::$app->setModule('users', self::$usrMgr);
		}
	}

	public function tearDown() {
	}

	public function testInit() {
		$authManager=new TAuthManager ();
		// Catch exception with null usermgr
		try {
			$authManager->init(null);
			self::fail ('Expected TConfigurationException not thrown');
		} catch (TConfigurationException $e) {}
		
		$authManager->setUserManager('users');
		$authManager->init (null);
		self::assertEquals(self::$usrMgr, $authManager->getUserManager());
	}
	
	public function testUserManager() {
		$authManager=new TAuthManager ();
		$authManager->setUserManager('users');
		$authManager->init(null);
		self::assertEquals(self::$usrMgr, $authManager->getUserManager());
		
		// test change
		try {
			$authManager->setUserManager('invalid');
			self::fail ('Expected TInvalidOperationException not thrown');
		} catch (TInvalidOperationException $e) {}
		
	}
	
	public function testLoginPage() {
		$authManager=new TAuthManager ();
		$authManager->setUserManager('users');
		$authManager->init(null);
		$authManager->setLoginPage ('LoginPage');
		self::assertEquals('LoginPage', $authManager->getLoginPage());
	}
	
	public function testDoAuthentication() {
		throw new PHPUnit_Framework_IncompleteTestError();
		// Not yet finished, Session won't start because of headers :( :(

		$authManager=new TAuthManager ();
		$authManager->setUserManager('users');
		$authManager->init(null);
		$authManager->setLoginPage ('LoginPage');
		self::$app->raiseEvent ('onAuthentication', self::$app, null);
		
	}
	
	public function testDoAuthorization() {
		throw new PHPUnit_Framework_IncompleteTestError();
	}
	
	public function testLeave() {
		throw new PHPUnit_Framework_IncompleteTestError();
	}
	
	public function testReturnUrl() {
		throw new PHPUnit_Framework_IncompleteTestError();
	}
	
	public function testOnAuthenticate() {
		throw new PHPUnit_Framework_IncompleteTestError();
	}
	
	public function testOnAuthorize() {
		throw new PHPUnit_Framework_IncompleteTestError();
	}
	
	public function testUpdateSessionUser() {
		throw new PHPUnit_Framework_IncompleteTestError();
	}
	
	public function testLogin() {
		throw new PHPUnit_Framework_IncompleteTestError();
	}
	
	public function testLogout() {
		throw new PHPUnit_Framework_IncompleteTestError();
	}

}

?>