Skip to content

Commit a3f111b

Browse files
committed
update tests
1 parent ed4594a commit a3f111b

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

tests.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,62 @@ function createTable ($name, $data) {
9393
$db->rawQuery($q);
9494
}
9595

96+
// rawQuery test
9697
foreach ($tables as $name => $fields) {
9798
$db->rawQuery("DROP TABLE ".$prefix.$name);
9899
createTable ($prefix.$name, $fields);
99100
}
100101

101-
102+
// insert test with autoincrement
102103
foreach ($data as $name => $datas) {
103104
foreach ($datas as $d) {
104105
$id = $db->insert($name, $d);
105106
if ($id)
106107
$d['id'] = $id;
107108
else {
108109
echo "failed to insert: ".$db->getLastQuery() ."\n". $db->getLastError();
110+
exit;
109111
}
110112
}
111113
}
112114

115+
// bad insert test
116+
$badUser = Array ('login' => null,
117+
'customerId' => 10,
118+
'firstName' => 'John',
119+
'lastName' => 'Doe',
120+
'password' => 'test',
121+
'createdAt' => $db->now(),
122+
'expires' => $db->now('+1Y'),
123+
'loginCount' => $db->inc()
124+
);
125+
$id = $db->insert ("users", $badUser);
126+
if ($id) {
127+
echo "bad insert test failed";
128+
exit;
129+
}
130+
131+
// insert without autoincrement
132+
$q = "create table {$prefix}test (id int(10), name varchar(10));";
133+
$db->rawQuery($q);
134+
$id = $db->insert ("test", Array ("id" => 1, "name" => "testname"));
135+
if (!$id) {
136+
echo "insert without autoincrement failed";
137+
exit;
138+
}
139+
$db->get("test");
140+
if ($db->count != 1) {
141+
echo "insert without autoincrement failed -- wrong insert count";
142+
exit;
143+
}
144+
113145
$db->orderBy("id","asc");
114146
$users = $db->get("users");
115147
if ($db->count != 3) {
116148
echo "Invalid total insert count";
117149
exit;
118150
}
151+
119152
$db->where ("active", true);
120153
$users = $db->get("users");
121154
if ($db->count != 1) {
@@ -246,8 +279,8 @@ function createTable ($name, $data) {
246279

247280
$db2 = $db->copy();
248281
$db2->where ("userId", $usersQ);
249-
$res = $db2->getOne ("products", "count(id) as cnt");
250-
if ($res['cnt'] != 2) {
282+
$cnt = $db2->getValue ("products", "count(id)");
283+
if ($cnt != 2) {
251284
echo "Invalid select result with subquery";
252285
exit;
253286
}
@@ -259,6 +292,10 @@ function createTable ($name, $data) {
259292
exit;
260293
}
261294
$db->delete("products");
295+
296+
$q = "drop table {$prefix}test;";
297+
$db->rawQuery($q);
298+
262299
echo "All done";
263300

264301
//print_r($db->rawQuery("CALL simpleproc(?)",Array("test")));

0 commit comments

Comments
 (0)