summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristian Schneider2007-10-11 15:18:41 +0000
committerChristian Schneider2007-10-11 15:18:41 +0000
commit3f122785bcbad2d685a2e9042c3f9efaffe59f9a (patch)
treedc6bb2ca9e6cc7bdb003899aa4dd35a5fefc84c0 /tests
parentc18587994161c9125497400ec18a8cac9d9974e0 (diff)
downloaditools-3f122785bcbad2d685a2e9042c3f9efaffe59f9a.tar.gz
itools-3f122785bcbad2d685a2e9042c3f9efaffe59f9a.tar.bz2
itools-3f122785bcbad2d685a2e9042c3f9efaffe59f9a.zip
Removed deprecated manual settings of fields for update() and added basic tests
Diffstat (limited to 'tests')
-rwxr-xr-xtests/it_dbi.t94
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/it_dbi.t b/tests/it_dbi.t
new file mode 100755
index 0000000..8ef8cab
--- /dev/null
+++ b/tests/it_dbi.t
@@ -0,0 +1,94 @@
+#!/www/server/bin/php -qC
+<?php
+
+# Tests for it_dbi.class
+
+require 'searchlib/search_test.class';
+
+# Initialize DB
+$db = array('db' => "lib_search_ch");
+$dbi = new it_dbi($db);
+$dbi->query('create temporary table it_dbi_test (
+ ID int not null auto_increment,
+ x int,
+ foo varchar(42),
+ primary key(ID)
+);');
+
+$record = new it_dbi($db + array('table' => "it_dbi_test"));
+
+$record->insert(array('x' => 42, 'foo' => null));
+$record->insert(array('foo' => "bar"));
+$record->insert(array('x' => 64738, 'foo' => "q'uux"));
+
+is(
+ $record->ID,
+ 3,
+ "auto_increment"
+);
+
+$record->read(1);
+is(
+ array($record->_key, $record->x, $record->foo),
+ array(1, 42, null),
+ "read"
+);
+
+$record->select(array('x' => 64738));
+is(
+ array($record->_key, $record->x, $record->foo),
+ array(3, 64738, "q'uux"),
+ "select"
+);
+
+$record->update(array('x' => 17));
+is(
+ array($record->_key, $record->x, $record->foo),
+ array(3, 17, "q'uux"),
+ "update"
+);
+
+$record->update(array('-x' => 'RAND() * 10'));
+isnt(
+ array($record->_key, $record->x, $record->foo),
+ array(3, 17, "q'uux"),
+ "update"
+);
+
+$rand = $record->x;
+is (
+ $record->_set(array('x' => $rand, 'foo' => "bar")),
+ "SET foo='bar'",
+ 'update: _set optimization'
+);
+
+$record->update(array('foo' => "bar"));
+$record->select(array('foo' => "bar"));
+$record->iterate();
+is(
+ array($record->_key, $record->x, $record->foo),
+ array(2, null, "bar"),
+ "iterate record 2"
+);
+$record->update(array('foo' => "qux"));
+$record->iterate();
+is(
+ array($record->_key, $record->x, $record->foo),
+ array(3, $rand, "bar"),
+ "iterate record 3"
+);
+$record->update(array('foo' => "quux"));
+
+$record->read(2);
+is(
+ array($record->_key, $record->x, $record->foo),
+ array(2, null, "qux"),
+ "iterate update record 2"
+);
+
+$record->read(3);
+is(
+ array($record->_key, $record->x, $record->foo),
+ array(3, $rand, "quux"),
+ "iterate update record 3"
+);