diff options
author | wei <> | 2006-12-04 02:42:57 +0000 |
---|---|---|
committer | wei <> | 2006-12-04 02:42:57 +0000 |
commit | 562979c4a8fe47952edf7986d4144624e41630f7 (patch) | |
tree | b79c3fd28e1aedb40d04e148da4b0763c928a3a5 /tests/simple_unit/ActiveRecord/UserRecordTestCase.php | |
parent | 91fe694c8755aa2d05743946a3681be7232420b6 (diff) |
add unit tests for active record and sqlmap
Diffstat (limited to 'tests/simple_unit/ActiveRecord/UserRecordTestCase.php')
-rw-r--r-- | tests/simple_unit/ActiveRecord/UserRecordTestCase.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/simple_unit/ActiveRecord/UserRecordTestCase.php b/tests/simple_unit/ActiveRecord/UserRecordTestCase.php new file mode 100644 index 00000000..483dc42f --- /dev/null +++ b/tests/simple_unit/ActiveRecord/UserRecordTestCase.php @@ -0,0 +1,67 @@ +<?php +
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/UserRecord.php');
+
+class UserRecordTestCase extends UnitTestCase
+{
+ function setup()
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ TActiveRecordManager::getInstance()->setDbConnection($conn);
+ }
+
+ function testFindByPk()
+ {
+ $user1 = UserRecord::finder()->findByPk('admin');
+ $this->assertNotNull($user1);
+ }
+
+ function test_same_data_returns_same_object()
+ {
+ $user1 = UserRecord::finder()->findByPk('admin');
+ $this->assertNotNull($user1);
+
+ $user2 = UserRecord::finder()->findByPk('admin');
+ $this->assertTrue($user1===$user2);
+ }
+
+ function testFindByPk_returns_null()
+ {
+ $user = UserRecord::finder()->findByPk('me');
+ $this->assertNull($user);
+ }
+
+ function test_Create_new_user_returns_true()
+ {
+ $user = new UserRecord;
+ $user->username = 'hello';
+ $user->password = md5('asd');
+ $user->email = 'asdasd';
+ $user->first_name = 'wei';
+ $user->last_name = 'zhuo';
+
+ $this->assertTrue($user->save());
+
+ $user->password = md5('more');
+
+ $this->assertTrue($user->save());
+
+ $check = UserRecord::finder()->findByPk('hello');
+
+ $this->assertSameUser($user, $check);
+
+ $this->assertTrue($user->delete());
+ }
+
+ function assertSameUser($user,$check)
+ {
+ $props = array('username', 'password', 'email', 'first_name', 'last_name', 'job_title',
+ 'work_phone', 'work_fax', 'active', 'department_id', 'salutation',
+ 'hint_question', 'hint_answer');
+ foreach($props as $prop)
+ $this->assertEqual($user->$prop,$check->$prop);
+ }
+}
+
+?>
\ No newline at end of file |