Moving the old code aside into the archive as i begin a new
[glcas.git] / archive / v1 / unittests / dbtest.php
diff --git a/archive/v1/unittests/dbtest.php b/archive/v1/unittests/dbtest.php
new file mode 100644 (file)
index 0000000..4310202
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+
+require_once("../lib/lib.php");
+
+db_createTable("table1", "data1", "data2", "data3", "data4");
+db_createTable("table2", "data1", "data2", "data3", "data4");
+db_createTable("table3", "data1", "data2", "data3", "data4");
+
+if(db_tableExists("table1")) echo "table 1 exists - correct\n";
+else echo "table 1 not exists - wrong\n";
+
+if(db_tableExists("table2")) echo "table 2 exists - correct\n";
+else echo "table 2 not exists - wrong\n";
+
+if(db_tableExists("table3")) echo "table 3 exists - correct\n";
+else echo "table 3 not exists - wrong\n";
+
+if(db_tableExists("table4")) echo "table 4 exists - wrong\n";
+else echo "table 4 not exists - correct\n";
+
+// now insert data test
+db_insertData("table1", "data1", "data2", "data3", "data4");
+
+// now try and do a gettables
+echo "tabs looks like:\n";
+$tabs = db_getTables();
+print_r($tabs);
+
+// now try a select
+$ret = db_selectData("table1", "data1", "data1");
+echo "did select 1 on table1 and got:\n";
+print_r($ret);
+if(isset($ret[0])) {
+       echo "looks correct\n";
+} else {
+       echo "looks wrong\n";
+}
+
+// now try a select
+$ret2 = db_selectData("table1", "1", "notdata1");
+echo "did select 2 on table1 and got:\n";
+print_r($ret2);
+if(isset($ret2[0])) {
+       echo "looks wrong\n";
+} else {
+       echo "looks correct\n";
+}
+
+// now do delete
+$ret = db_deleteData("table1", "1", "data1");
+
+// now try a select again
+$ret = db_selectData("table1", "1", "data1");
+echo "did select 1 on table1 and got:\n";
+print_r($ret);
+if(isset($ret[0])) {
+       echo "looks wrong\n";
+} else {
+       echo "looks correct\n";
+}
+
+// now delete the tables
+$ret = db_deleteTable("table1");
+$ret = db_deleteTable("table2");
+$ret = db_deleteTable("table3");
+
+if(db_tableExists("table1")) echo "table 1 exists - wrong\n";
+else echo "table 1 not exists - correct\n";
+
+if(db_tableExists("table2")) echo "table 2 exists - wrong\n";
+else echo "table 2 not exists - correct\n";
+
+if(db_tableExists("table3")) echo "table 3 exists - wrong\n";
+else echo "table 3 not exists - correct\n";
+
+?>
\ No newline at end of file