diff options
author | Christian Schneider | 2007-10-11 15:18:41 +0000 |
---|---|---|
committer | Christian Schneider | 2007-10-11 15:18:41 +0000 |
commit | 3f122785bcbad2d685a2e9042c3f9efaffe59f9a (patch) | |
tree | dc6bb2ca9e6cc7bdb003899aa4dd35a5fefc84c0 /tests | |
parent | c18587994161c9125497400ec18a8cac9d9974e0 (diff) | |
download | itools-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-x | tests/it_dbi.t | 94 |
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" +); |