summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNathan Gass2020-09-03 10:39:29 +0200
committerNathan Gass2020-09-03 10:39:29 +0200
commite48afecf380719f48257ab2b6d964d57c931a7ae (patch)
tree4ba44c93e7f130baf33d14c544397c5bd34aac04 /test
parent7c1f8a89cff2ef27658196cf4391f7535ce3bf60 (diff)
downloaditools-e48afecf380719f48257ab2b6d964d57c931a7ae.tar.gz
itools-e48afecf380719f48257ab2b6d964d57c931a7ae.tar.bz2
itools-e48afecf380719f48257ab2b6d964d57c931a7ae.zip
add options to run tests on postgressql, adapt create table statements to used db, avoid dependency on specific table in db
Diffstat (limited to 'test')
-rwxr-xr-xtest/it_dbi.t45
1 files changed, 31 insertions, 14 deletions
diff --git a/test/it_dbi.t b/test/it_dbi.t
index 4b0c9a8..8528a86 100755
--- a/test/it_dbi.t
+++ b/test/it_dbi.t
@@ -3,19 +3,35 @@
# Tests for it_dbi.class
+$opts = it::getopt("
+ Usage: it_dbi.t [OPTIONS]
+ --db=S DB to use [lib_search_ch]
+ --user=S User
+ --pw=S Password
+ --subclass=S Subclass to test [it_dbi]
+");
+
# Initialize DB
-$db = ['db' => "lib_search_ch", 'safety' => 0];
-$dbi = new it_dbi($db);
-$dbi->query('create temporary table it_dbi_test (
- ID int not null auto_increment,
+$db = it::filter_keys($opts, 'db,user,pw');# + ['safety' => 0];
+$dbi = new $opts['subclass']($db);
+
+$opts['subclass']::createclasses();
+$tables = $dbi->tables();
+ok(count($tables) > 0, 'there are some existing tables in the db');
+ok(new $tables[0], 'classes for tables exist');
+
+$autoid = $opts['subclass'] == 'it_dbi_postgres' ? '"ID" Serial' : 'ID int not null auto_increment';
+$dyncols = $opts['subclass'] == 'it_dbi_postgres' ? 'dyncols JSONB' : 'dyncols JSON';
+$primarykey = $dbi->escape_name('ID');
+$dbi->query("create temporary table it_dbi_test (
+ $autoid,
x int,
foo varchar(42),
- dyncols JSON,
- primary key(ID)
-);');
-it_dbi::createclass(['table' => "it_dbi_test", 'forcecreate' => true]);
+ $dyncols,
+ primary key($primarykey)
+);");
+$opts['subclass']::createclass(['table' => "it_dbi_test", 'forcecreate' => true]);
-ok(new T_sl_accesscount, 'classes for tables exist');
$record = new it_dbi_test;
$record->insert(['x' => 42, 'foo' => null]);
@@ -283,14 +299,15 @@ $record->select(['foo' => "\xc3\x28"]);
# Test field localization feature
-$dbi->query('create temporary table it_dbi_testlocalized (
- ID int not null auto_increment,
+$dbi->query("create temporary table it_dbi_testlocalized (
+ $autoid,
foobar_de varchar(42),
foobar_fr varchar(42),
- primary key(ID)
-);');
+ primary key($primarykey)
+);");
+
-$record = new it_dbi($db + ['table' => "it_dbi_testlocalized"]);
+$record = new $opts['subclass']($db + ['table' => "it_dbi_testlocalized"]);
$record->insert(['foobar_de' => "deutsch", 'foobar_fr' => "franz"]);
$record->insert(['foobar_de' => "deutsch2", 'foobar_fr' => "franz2"]);