summaryrefslogtreecommitdiff
path: root/tests/unit/Security/TUserTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/Security/TUserTest.php')
-rw-r--r--tests/unit/Security/TUserTest.php76
1 files changed, 66 insertions, 10 deletions
diff --git a/tests/unit/Security/TUserTest.php b/tests/unit/Security/TUserTest.php
index 67ac6eb4..597fac97 100644
--- a/tests/unit/Security/TUserTest.php
+++ b/tests/unit/Security/TUserTest.php
@@ -2,56 +2,112 @@
require_once dirname(__FILE__).'/../phpunit.php';
Prado::using('System.Security.TUser');
+Prado::using('System.Security.TUserManager');
/**
* @package System.Security
*/
class TUserTest extends PHPUnit_Framework_TestCase {
+ public static $app=null;
+ public static $mgr=null;
public function setUp() {
+ if(self::$app === null) {
+ self::$app = new TApplication(dirname(__FILE__).'/app');
+ prado::setPathofAlias('App', dirname(__FILE__));
+ }
+
+ if (self::$mgr===null) {
+ $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::$mgr=new TUserManager();
+ self::$mgr->init($config);
+ }
}
public function tearDown() {
}
public function testConstruct() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $user = new TUser (self::$mgr);
+ self::assertEquals('Guest', $user->getName());
+ self::assertEquals(self::$mgr, $user->getManager());
}
public function testManager() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $user = new TUser (self::$mgr);
+ self::assertEquals(self::$mgr, $user->getManager());
}
public function testName() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $user = new TUser (self::$mgr);
+ $user->setName('joe');
+ self::assertEquals('joe', $user->getName());
}
public function testIsGuest() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $user = new TUser (self::$mgr);
+ $user->setName('John');
+ $user->setIsGuest(false);
+ $user->setRoles('Administrator, Writer');
+ self::assertFalse($user->getIsGuest());
+ $user->setIsGuest(true);
+ self::assertTrue($user->getIsGuest());
+ self::assertEquals(array(),$user->getRoles());
}
public function testRoles() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $user=new TUser(self::$mgr);
+ $user->setRoles(array('Administrator','Writer'));
+ self::assertEquals(array('Administrator','Writer'), $user->getRoles());
+ $user->setRoles('Reader,User');
+ self::assertEquals(array('Reader','User'), $user->getRoles());
}
public function testIsInRole() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $user=new TUser(self::$mgr);
+ $user->setRoles(array('Administrator','Writer'));
+ // Roles are case insensitive
+ self::assertTrue($user->IsInRole('writer'));
+ self::assertTrue($user->IsInRole('Writer'));
+ self::assertFalse($user->isInRole('Reader'));
}
public function testSaveToString() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $user = new TUser (self::$mgr);
+ $user->setName('John');
+ $user->setIsGuest(false);
+ $user->setRoles('Administrator, Writer');
+ // State array should now be :
+ $assumedState=array ('Name' => 'John', 'IsGuest' => false, 'Roles' => array ('Administrator', 'Writer'));
+ self::assertEquals(serialize($assumedState), $user->saveToString());
}
public function testLoadFromString() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $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();
}
-
+ */
+
public function testStateChanged() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $user = new TUser (self::$mgr);
+ $user->setName('John');
+ self::assertTrue($user->getStateChanged());
+ $user->setStateChanged(false);
+ self::assertFalse($user->getStateChanged());
}
}