-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_mongo_entity_auth.php
104 lines (73 loc) · 2.39 KB
/
test_mongo_entity_auth.php
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
class AuthEntity extends MongoEntity{
protected static $_mongo_port = 6904;
protected static $_mongo_database = 'projectx';
protected static $_mongo_user_name = 'joe';
protected static $_mongo_password = 'passwordForJoe';
}
class AuthEntityBad extends MongoEntity{
protected static $_mongo_port = 6904;
protected static $_mongo_database = 'projectx';
protected static $_mongo_user_name = 'blah';
protected static $_mongo_password = 'blah';
}
class TestAuthEntityAuth extends UnitTestCase{
function setUp(){
$coll = AuthEntity::loadCollection();
$coll->drop();
}
function teardown(){
$coll = AuthEntity::loadCollection();
$coll->drop();
}
function testCreateAuth(){
$data = new AuthEntity();
$data->a = 1;
$data->b = 2;
return ($this->assertTrue($data->save()) &&
$this->assertEqual($data->a, 1) &&
$this->assertEqual($data->b, 2) &&
$this->assertNotNull($data->id) );
}
function testLoadBasic(){
$data = new AuthEntity(array('a' => 1, 'b' => 2));
$this->assertTrue($data->save(true));
$data2 = new AuthEntity();
$data2->load_single();
return ($this->assertEqual($data2->a, $data->a) &&
$this->assertEqual($data->a, 1) &&
$this->assertEqual($data->b, 2) &&
$this->assertEqual($data2->b, $data->b));
}
function testCreateAuthBad(){
$data = new AuthEntityBad();
$data->a = 1;
$data->b = 2;
return ($this->assertFalse($data->save()));
}
function testLoadSpecific(){
$data = new AuthEntity(array('a' => 1, 'b' => 2));
$this->assertTrue($data->save(true));
$data2 = new AuthEntity(array('a' => 10, 'b' => 8));
$data2->save(true);
$id = $data2->id;
$data3 = new AuthEntity();
$data3->load_single($id);
return ($this->assertEqual($data2->a, 10) &&
$this->assertEqual($data2->b, 8) &&
$this->assertTrue($data2->a == $data3->a) &&
$this->assertTrue($data2->b == $data3->b));
}
function testLoadSpecificFields(){
$data = new AuthEntity(array('a' => 1, 'b' => 2, 'c' => 3));
$this->assertTrue($data->save());
$id = $data->id;
$load = new AuthEntity();
$load->load_single($id, array('a', 'b'));
return ( $this->assertEqual($load->a, $data->a) &&
$this->assertEqual($load->b, $data->b) &&
$this->assertNull($load->c) &&
$this->assertNotNull($data->c) );
}
}
?>