added numerous database components
[gwvp.git] / unittests / sqlitedb.php
diff --git a/unittests/sqlitedb.php b/unittests/sqlitedb.php
new file mode 100644 (file)
index 0000000..21de42a
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+$lib_base = "../gwvplib/";
+
+// initial http file
+$WEB_ROOT_FS = realpath(dirname(__FILE__));
+$BASE_URL = dirname($_SERVER["PHP_SELF"]);
+
+global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_name, $db_username, $db_password;
+
+// add gwvplib as if it were a path in ../gwvplib
+if(file_exists($lib_base)) {
+       $path = realpath($lib_base);
+       set_include_path(get_include_path().PATH_SEPARATOR.$path);
+}
+
+require_once("gwvplib.php");
+global $db_type, $db_url;
+
+$db_type = "sqlite";
+$db_url = "/tmp/unittestdb.db";
+
+gwvp_dbCreateSQLiteStructure("$db_url");
+
+gwvp_ConnectDB();
+
+// function gwvp_createUser($email, $fullname, $password, $nick, $desc, $status)
+// test users creation
+gwvp_createUser("test@test.com", "test user", "password", "nick", "desc", "0");
+gwvp_createUser("test2@test.com", "test2 user", "password", "nick2", "desc2", "0");
+$users = gwvp_getUsers();
+echo "Users\n";
+echo "\tCreate test@test.com\n";
+if($users[0]["email"] != "test@test.com") {
+       echo "\t\tUser 0 isnt correct: ".$users[0]["email"]."\n";
+} else {
+       echo "\t\tUser 0 correct\n";
+}
+if($users[1]["email"] != "test2@test.com") {
+       echo "\t\tUser 1 isnt correct: ".$users[0]["email"]."\n";
+} else {
+       echo "\t\tUser 1 correct\n";
+}
+echo "\tCheck User It\n";
+$uid1 = gwvp_getUserId("test@test.com");
+$uid2 = gwvp_getUserId("test2@test.com");
+if($uid1 != 1) {
+       echo "\t\tUser 1 id not correct\n";
+} else {
+       echo "\t\tUser 1 id correct\n";
+}
+if($uid2 != 2) {
+       echo "\t\tUser 2 id not correct\n";
+} else {
+       echo "\t\tUser 2 id correct\n";
+}
+
+echo "\tDelete test@test.com\n";
+gwvp_deleteUser("test@test.com");
+$users = gwvp_getUsers();
+if($users[0]["email"] != "test2@test.com") {
+       echo "\t\tUser 0 isnt correct: ".$users[0]["email"]."\n";
+} else {
+       echo "\t\tUser 0 is correct\n";
+}
+
+// test group creation
+// function gwvp_createGroup($group_name, $is_admin, $owner_id)
+echo "\n\nGroups\n";
+echo "\tCreate testgroups\n";
+gwvp_createGroup("testgroup", true, "1");
+gwvp_createGroup("testgroup2", true, "1");
+$groups = gwvp_getGroups();
+if($groups[0]["name"] != "testgroup") {
+       echo "\t\tGroup 0 isnt correct: ".$groups[0]["name"]."\n";
+} else {
+       echo "\t\tGroup 0 correct\n";
+}
+if($groups[1]["name"] != "testgroup2") {
+       echo "\t\tGroup 1 isnt correct: ".$groups[1]["name"]."\n";
+} else {
+       echo "\t\tGroup 1 correct\n";
+}
+echo "\tCheck group id\n";
+$gid1 = gwvp_getGroupId("testgroup");
+$gid2 = gwvp_getGroupId("testgroup2");
+if($gid1 != 1) {
+       echo "\t\tGroup 1 ID not correct\n";
+} else {
+       echo "\t\tGroup 1 ID correct\n";
+}
+if($gid2 != 2) {
+       echo "\t\tGroup 2 ID not correct\n";
+} else {
+       echo "\t\tGroup 2 ID correct\n";
+}
+
+echo "\tNow delete group\n";
+gwvp_deleteGroup("testgroup");
+$groups = gwvp_getGroups();
+if($groups[0]["name"] != "testgroup2") {
+       echo "\t\tGroup 0 isnt correct: ".$groups[0]["name"]."\n";
+} else {
+       echo "\t\tGroup 0 correct\n";
+}
+
+unlink($db_url);
+?>
\ No newline at end of file