1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<?php
Prado::using('System.Data.ActiveRecord.TActiveRecord');
require_once(dirname(__FILE__).'/records/UserRecord.php');
/**
* @package System.Data.ActiveRecord
*/
class UserRecordTest extends PHPUnit_Framework_TestCase
{
function setup()
{
$conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest');
TActiveRecordManager::getInstance()->setDbConnection($conn);
}
function testFindByPk()
{
$user1 = UserRecord::finder()->findByPk('admin');
$this->assertNotNull($user1);
}
function test_same_data_returns_different_instance()
{
$user1 = UserRecord::finder()->findByPk('admin');
$this->assertNotNull($user1);
$user2 = UserRecord::finder()->findByPk('admin');
$this->assertFalse($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->assertEquals($user->$prop,$check->$prop);
}
}
|