From 64418ade2e1e87f835e9ba25c393d359f0c99487 Mon Sep 17 00:00:00 2001 From: tof <> Date: Fri, 15 Jun 2007 11:24:56 +0000 Subject: Implement unit tests for TUser, TUserManager Start implement unit tests for TAuthManager (still incomplete) --- tests/unit/Security/TAuthManagerTest.php | 56 ++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) (limited to 'tests/unit/Security/TAuthManagerTest.php') 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(''); + 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() { -- cgit v1.2.3