forked from habari/tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_queryrecord.php
208 lines (182 loc) · 5.71 KB
/
test_queryrecord.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
include 'bootstrap.php';
/**
* class to get fields/newfields to test logic
*/
class TestQueryRecord extends QueryRecord
{
public function get_fields()
{
return $this->fields;
}
public function get_newfields()
{
return $this->newfields;
}
}
/**
* Test class for QueryRecord.
*/
class QueryRecordTest extends UnitTestCase
{
protected $queryrecord;
protected $test_data = array(
'foo' => 'bar',
'id' => 1,
'long' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi posuere tellus
eget ipsum euismod sagittis. Phasellus id purus metus, nec placerat purus. Cras
porttitor mollis dapibus. Ut laoreet dui tellus, vel pulvinar sapien. Nulla vitae sem
ut ligula condimentum auctor sed vitae turpis. Sed id nibh in elit tincidunt aliquet.
Duis pulvinar dolor et nisi tempus condimentum. Pellentesque habitant morbi tristique
senectus et netus et malesuada fames ac turpis egestas. Class aptent taciti sociosqu ad
litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque posuere blandit
elit, eu aliquam eros bibendum nec. Ut non porttitor sem. Pellentesque habitant morbi
tristique senectus et netus et malesuada fames ac turpis egestas. Nunc lorem lorem,
accumsan eu semper sit amet, mollis a justo",
'bool' => FALSE,
'null' => NULL,
);
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setup()
{
$this->queryrecord = new QueryRecord( $this->test_data );
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function teardown()
{
unset( $this->queryrecord );
}
public function test__get()
{
foreach ( $this->test_data as $key => $val ) {
$this->assert_equal( $val, $this->queryrecord->$key );
}
}
public function test__set()
{
$setqueryrecord = new QueryRecord();
foreach ( $this->test_data as $key => $val ) {
$setqueryrecord->$key = $val;
}
// test contruct and __set match
foreach ( $this->test_data as $key => $val ) {
$this->assert_equal( $this->queryrecord->$key, $setqueryrecord->$key );
}
// test __set matches
foreach ( $this->test_data as $key => $val ) {
$this->assert_equal( $val, $setqueryrecord->$key );
}
}
public function test__isset() {
foreach ( $this->test_data as $key => $val ) {
switch ($key) {
case 'null':
$this->assert_false( isset( $this->queryrecord->$key ), "isset( '$key' )" );
break;
default:
$this->assert_true( isset( $this->queryrecord->$key ), "isset( '$key' )" );
break;
}
}
}
public function test_newfields__construct()
{
$testqueryrecord = new TestQueryRecord( $this->test_data );
$fields = $testqueryrecord->get_fields();
$newfields = $testqueryrecord->get_newfields();
$this->assert_equal( array(), $newfields );
// make sure new vals are in newfields
$new_val = 'newbar';
foreach ( array_keys( $this->test_data ) as $key ) {
$testqueryrecord->$key = $new_val;
}
$fields = $testqueryrecord->get_fields();
$newfields = $testqueryrecord->get_newfields();
foreach ( $this->test_data as $key => $val ) {
$this->assert_equal( $new_val, $newfields[$key] );
$this->assert_equal( $val, $fields[$key] );
}
// make sure brand new field goes in newfield
$testqueryrecord->pony = 'ponies';
$fields = $testqueryrecord->get_fields();
$newfields = $testqueryrecord->get_newfields();
$this->assert_true( isset( $newfields['pony'] ) );
$this->assert_equal( 'ponies', $newfields['pony'] );
$this->assert_true( !isset( $fields['pony'] ) );
}
public function test_newfields__set()
{
$testqueryrecord = new TestQueryRecord;
foreach ( $this->test_data as $key => $val ) {
$testqueryrecord->$key = $val;
}
$fields = $testqueryrecord->get_fields();
$newfields = $testqueryrecord->get_newfields();
$this->assert_equal( array(), $newfields );
// make sure new vals are in newfields
$new_val = 'newbar';
foreach ( array_keys( $this->test_data ) as $key ) {
$testqueryrecord->$key = $new_val;
}
$fields = $testqueryrecord->get_fields();
$newfields = $testqueryrecord->get_newfields();
foreach ( $this->test_data as $key => $val ) {
$this->assert_equal( $new_val, $newfields[$key] );
$this->assert_equal( $val, $fields[$key] );
}
// make sure brand new field goes in newfield
$testqueryrecord->pony = 'ponies';
$fields = $testqueryrecord->get_fields();
$newfields = $testqueryrecord->get_newfields();
$this->assert_true( isset( $newfields['pony'] ) );
$this->assert_equal( 'ponies', $newfields['pony'] );
$this->assert_true( !isset( $fields['pony'] ) );
}
public function test_exclude_fields()
{
$fields = array( 'id', 'null' );
$this->queryrecord->exclude_fields( $fields );
$excluded = $this->queryrecord->list_excluded_fields();
foreach ( $fields as $field ) {
$this->assert_true( isset( $excluded[$field] ) );
}
$field = 'id';
$this->queryrecord->exclude_fields( $field );
$excluded = $this->queryrecord->list_excluded_fields();
$this->assert_true( isset( $excluded[$field] ) );
}
public function test_to_array()
{
$this->assert_equal( $this->test_data, $this->queryrecord->to_array() );
}
public function test_get_url_args()
{
$this->assert_equal( $this->test_data, $this->queryrecord->get_url_args() );
}
/**
* @todo Implement test_insert().
*/
public function test_insert() {
$this->mark_test_incomplete();
}
/**
* @todo Implement testUpdate().
*/
public function test_update() {
$this->mark_test_incomplete();
}
/**
* @todo Implement test_delete().
*/
public function test_delete() {
$this->mark_test_incomplete();
}
}
QueryRecordTest::run_one( 'QueryRecordTest' );
?>