diff options
author | tof <> | 2007-06-15 11:24:56 +0000 |
---|---|---|
committer | tof <> | 2007-06-15 11:24:56 +0000 |
commit | 64418ade2e1e87f835e9ba25c393d359f0c99487 (patch) | |
tree | 766130c35e8d1b069a2b18f6e4f0bc14d6b6cb06 /tests/unit/Security/TAuthManagerTest.php | |
parent | 5221bdcec986254d443018a5ad8d1dc25ca55226 (diff) |
Implement unit tests for TUser, TUserManager
Start implement unit tests for TAuthManager (still incomplete)
Diffstat (limited to 'tests/unit/Security/TAuthManagerTest.php')
-rw-r--r-- | tests/unit/Security/TAuthManagerTest.php | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/tests/unit/Security/TAuthManagerTest.php b/tests/unit/Security/TAuthManagerTest.php index 6e3c05a9..7e628a61 100644 --- a/tests/unit/Security/TAuthManagerTest.php +++ b/tests/unit/Security/TAuthManagerTest.php @@ -2,32 +2,82 @@ 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() { - throw new PHPUnit_Framework_IncompleteTestError(); + $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() { - throw new PHPUnit_Framework_IncompleteTestError(); + $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() { - throw new PHPUnit_Framework_IncompleteTestError(); + $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() { |