From 9733613002b664ec9cbdc6dec9d6fd57ee901f1e Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Wed, 15 Jan 2014 19:05:25 +0100 Subject: Removed ?> from tests --- tests/unit/Security/AllTests.php | 7 +++--- tests/unit/Security/TAuthManagerTest.php | 35 +++++++++++++------------- tests/unit/Security/TAuthorizationRuleTest.php | 15 ++++++----- tests/unit/Security/TSecurityManagerTest.php | 31 +++++++++++------------ tests/unit/Security/TUserManagerTest.php | 31 +++++++++++------------ tests/unit/Security/TUserTest.php | 21 ++++++++-------- 6 files changed, 67 insertions(+), 73 deletions(-) (limited to 'tests/unit/Security') diff --git a/tests/unit/Security/AllTests.php b/tests/unit/Security/AllTests.php index 40316719..e71307a9 100644 --- a/tests/unit/Security/AllTests.php +++ b/tests/unit/Security/AllTests.php @@ -14,16 +14,16 @@ class Security_AllTests { public static function main() { PHPUnit_TextUI_TestRunner::run(self::suite()); } - + public static function suite() { $suite = new PHPUnit_Framework_TestSuite('System.Security'); - + $suite->addTestSuite('TAuthManagerTest'); $suite->addTestSuite('TAuthorizationRuleTest'); $suite->addTestSuite('TSecurityManagerTest'); $suite->addTestSuite('TUserManagerTest'); $suite->addTestSuite('TUserTest'); - + return $suite; } } @@ -31,4 +31,3 @@ class Security_AllTests { if(PHPUnit_MAIN_METHOD == 'Security_AllTests::main') { Security_AllTests::main(); } -?> diff --git a/tests/unit/Security/TAuthManagerTest.php b/tests/unit/Security/TAuthManagerTest.php index 03244a22..3b8b9305 100644 --- a/tests/unit/Security/TAuthManagerTest.php +++ b/tests/unit/Security/TAuthManagerTest.php @@ -8,7 +8,7 @@ Prado::using('System.Xml.TXmlDocument'); * @package System.Security */ class TAuthManagerTest extends PHPUnit_Framework_TestCase { - + public static $app = null; public static $usrMgr = null; @@ -18,7 +18,7 @@ class TAuthManagerTest extends PHPUnit_Framework_TestCase { 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 (); @@ -39,26 +39,26 @@ class TAuthManagerTest extends PHPUnit_Framework_TestCase { $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'); @@ -66,7 +66,7 @@ class TAuthManagerTest extends PHPUnit_Framework_TestCase { $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 :( :( @@ -76,41 +76,40 @@ class TAuthManagerTest extends PHPUnit_Framework_TestCase { $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(); } } -?> diff --git a/tests/unit/Security/TAuthorizationRuleTest.php b/tests/unit/Security/TAuthorizationRuleTest.php index 5d5f2d97..5bfa6c2c 100644 --- a/tests/unit/Security/TAuthorizationRuleTest.php +++ b/tests/unit/Security/TAuthorizationRuleTest.php @@ -16,35 +16,34 @@ class TAuthorizationRuleTest extends PHPUnit_Framework_TestCase { public function testConstruct() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testAction() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testUsers() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testRoles() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testVerb() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testGuestApplied() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testEveryoneApplied() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testIsUserAllowed() { throw new PHPUnit_Framework_IncompleteTestError(); } } -?> diff --git a/tests/unit/Security/TSecurityManagerTest.php b/tests/unit/Security/TSecurityManagerTest.php index 09c261cf..9c319a5a 100644 --- a/tests/unit/Security/TSecurityManagerTest.php +++ b/tests/unit/Security/TSecurityManagerTest.php @@ -22,39 +22,39 @@ class TSecurityManagerTest extends PHPUnit_Framework_TestCase { $sec->init(null); self::assertEquals ($sec, self::$app->getSecurityManager()); } - + public function testValidationKey() { $sec=new TSecurityManager (); $sec->init (null); // Random validation key $valkey=$sec->getValidationKey (); self::assertEquals($valkey, self::$app->getGlobalState(TSecurityManager::STATE_VALIDATION_KEY)); - + $sec->setValidationKey ('aKey'); self::assertEquals('aKey',$sec->getValidationKey()); - + try { $sec->setValidationKey (''); self::fail ('Expected TInvalidDataValueException not thrown'); } catch (TInvalidDataValueException $e) {} } - + public function testEncryptionKey() { $sec=new TSecurityManager (); $sec->init (null); // Random encryption key $valkey=$sec->getEncryptionKey (); self::assertEquals($valkey, self::$app->getGlobalState(TSecurityManager::STATE_ENCRYPTION_KEY)); - + $sec->setEncryptionKey ('aKey'); self::assertEquals('aKey',$sec->getEncryptionKey()); - + try { $sec->setEncryptionKey (''); self::fail ('Expected TInvalidDataValueException not thrown'); } catch (TInvalidDataValueException $e) {} } - + public function testValidation() { $sec=new TSecurityManager (); $sec->init (null); @@ -67,7 +67,7 @@ class TSecurityManagerTest extends PHPUnit_Framework_TestCase { self::fail ('Expected TInvalidDataValueException not thrown'); } catch (TInvalidDataValueException $e) {} } - + public function testEncryption() { $sec=new TSecurityManager (); $sec->init (null); @@ -79,7 +79,7 @@ class TSecurityManagerTest extends PHPUnit_Framework_TestCase { self::assertEquals('NotExisting', $sec->getCryptAlgorithm()); } } - + public function testEncryptDecrypt() { $sec=new TSecurityManager (); $sec->init (null); @@ -101,13 +101,13 @@ class TSecurityManagerTest extends PHPUnit_Framework_TestCase { self::assertEquals($plainText,$decrypted); - // try change key + // try change key $sec->setEncryptionKey ('anotherKey'); self::assertNotEquals($plainText, $sec->decrypt($encrypted)); } } - - + + public function testHashData() { $sec=new TSecurityManager (); $sec->init (null); @@ -118,7 +118,7 @@ class TSecurityManagerTest extends PHPUnit_Framework_TestCase { self::assertEquals (54, strlen($hashed)); // The initial text should be after the initial hash self::assertEquals ('A text to hash', substr($hashed,40)); - + // Same tests with MD5 $sec->setValidationKey('AnotherKey'); $sec->setValidation('MD5'); @@ -128,7 +128,7 @@ class TSecurityManagerTest extends PHPUnit_Framework_TestCase { // The initial text should be after the initial hash self::assertEquals ('A text to hash', substr($hashed,32)); } - + public function testValidateData() { $sec=new TSecurityManager (); $sec->init (null); @@ -142,8 +142,7 @@ class TSecurityManagerTest extends PHPUnit_Framework_TestCase { // and a test without tampered data self::assertFalse($sec->validateData('bad')); } - + } -?> diff --git a/tests/unit/Security/TUserManagerTest.php b/tests/unit/Security/TUserManagerTest.php index edb7ea6f..91b9d0c6 100644 --- a/tests/unit/Security/TUserManagerTest.php +++ b/tests/unit/Security/TUserManagerTest.php @@ -6,18 +6,18 @@ Prado::using('System.Security.TUserManager'); * @package System.Security */ class TUserManagerTest extends PHPUnit_Framework_TestCase { - + public static $app=null; public static $config=null; - + public function setUp() { - + if(self::$app === null) { self::$app = new TApplication(dirname(__FILE__).'/app'); prado::setPathofAlias('App', dirname(__FILE__)); } - + if (self::$config === null) { // Simulate a config file self::$config=new TXmlDocument('1.0','utf8'); @@ -41,21 +41,21 @@ class TUserManagerTest extends PHPUnit_Framework_TestCase { $userManager->init (new TXmlDocument()); // Empty config self::assertEquals(array('joe'=>'demo','john'=>'demo', 'test' => 'test'), $userManager->getUsers()); unlink (dirname(__FILE__).'/users.xml'); - } + } } - + public function testUsers() { $userManager=new TUserManager (); $userManager->init (self::$config); self::assertEquals(array('joe'=>'demo','john'=>'demo', 'test' => 'test'), $userManager->getUsers()); } - + public function testRoles() { $userManager=new TUserManager (); $userManager->init (self::$config); self::assertEquals(array('joe'=>array ('Writer'), 'john'=>array ('Administrator','Writer'), 'test' => array ('Reader', 'User')), $userManager->getRoles()); } - + public function testUserFile() { $userManager=new TUserManager (); try { @@ -71,7 +71,7 @@ class TUserManagerTest extends PHPUnit_Framework_TestCase { self::assertEquals(dirname(__FILE__).'/users.xml', $userManager->getUserFile()); unlink (dirname(__FILE__).'/users.xml'); $userManager=null; - } + } $userManager=new TUserManager (); $userManager->init (self::$config); try { @@ -79,14 +79,14 @@ class TUserManagerTest extends PHPUnit_Framework_TestCase { self::fail ('Exception TInvalidOperationException not thrown'); } catch (TInvalidOperationException $e) {} } - + public function testGuestName() { $userManager=new TUserManager (); self::assertEquals('Guest', $userManager->getGuestName()); $userManager->setGuestName('Invite'); self::assertEquals('Invite', $userManager->getGuestName()); } - + public function testPasswordMode() { $userManager=new TUserManager (); $userManager->setPasswordMode('Clear'); @@ -99,9 +99,9 @@ class TUserManagerTest extends PHPUnit_Framework_TestCase { $userManager->setPasswordMode('Invalid'); self::fail ('Exception TInvalidDataValueException not thrown'); } catch (TInvalidDataValueException $e) {} - + } - + public function testValidateUser() { $userManager=new TUserManager (); $userManager->init (self::$config); @@ -109,7 +109,7 @@ class TUserManagerTest extends PHPUnit_Framework_TestCase { self::assertTrue($userManager->validateUser('Joe', 'demo')); self::assertFalse($userManager->validateUser('John', 'bad')); } - + public function testUser() { $userManager=new TUserManager (); $userManager->init (self::$config); @@ -123,7 +123,7 @@ class TUserManagerTest extends PHPUnit_Framework_TestCase { self::assertFalse($user->getIsGuest()); self::assertNull($userManager->getUser('badUser')); } - + public function testSwitchToGuest() { $userManager=new TUserManager (); $userManager->init (self::$config); @@ -134,4 +134,3 @@ class TUserManagerTest extends PHPUnit_Framework_TestCase { } -?> diff --git a/tests/unit/Security/TUserTest.php b/tests/unit/Security/TUserTest.php index 6fa337e0..3692b97c 100644 --- a/tests/unit/Security/TUserTest.php +++ b/tests/unit/Security/TUserTest.php @@ -32,18 +32,18 @@ class TUserTest extends PHPUnit_Framework_TestCase { self::assertEquals('Guest', $user->getName()); self::assertEquals(self::$mgr, $user->getManager()); } - + public function testManager() { $user = new TUser (self::$mgr); self::assertEquals(self::$mgr, $user->getManager()); } - + public function testName() { $user = new TUser (self::$mgr); $user->setName('joe'); self::assertEquals('joe', $user->getName()); } - + public function testIsGuest() { $user = new TUser (self::$mgr); $user->setName('John'); @@ -54,7 +54,7 @@ class TUserTest extends PHPUnit_Framework_TestCase { self::assertTrue($user->getIsGuest()); self::assertEquals(array(),$user->getRoles()); } - + public function testRoles() { $user=new TUser(self::$mgr); $user->setRoles(array('Administrator','Writer')); @@ -62,7 +62,7 @@ class TUserTest extends PHPUnit_Framework_TestCase { $user->setRoles('Reader,User'); self::assertEquals(array('Reader','User'), $user->getRoles()); } - + public function testIsInRole() { $user=new TUser(self::$mgr); $user->setRoles(array('Administrator','Writer')); @@ -71,7 +71,7 @@ class TUserTest extends PHPUnit_Framework_TestCase { self::assertTrue($user->IsInRole('Writer')); self::assertFalse($user->isInRole('Reader')); } - + public function testSaveToString() { $user = new TUser (self::$mgr); $user->setName('John'); @@ -81,20 +81,20 @@ class TUserTest extends PHPUnit_Framework_TestCase { $assumedState=array ('Name' => 'John', 'IsGuest' => false, 'Roles' => array ('Administrator', 'Writer')); self::assertEquals(serialize($assumedState), $user->saveToString()); } - + public function testLoadFromString() { $user = new TUser (self::$mgr); $user->setName('John'); $user->setIsGuest(false); $user->setRoles('Administrator, Writer'); $save=$user->saveToString(); - + $user2 = new TUser (self::$mgr); $user2->loadFromString($save); - + self::assertEquals($user, $user2); } - + /* getState & setState are protected methods, will be tested with other tests. public function testState() { throw new PHPUnit_Framework_IncompleteTestError(); @@ -111,4 +111,3 @@ class TUserTest extends PHPUnit_Framework_TestCase { } -?> -- cgit v1.2.3