added numerous database components
[gwvp.git] / unittests / sqlitedb.php
1 <?php
2 $lib_base = "../gwvplib/";
3
4 // initial http file
5 $WEB_ROOT_FS = realpath(dirname(__FILE__));
6 $BASE_URL = dirname($_SERVER["PHP_SELF"]);
7
8 global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_name, $db_username, $db_password;
9
10 // add gwvplib as if it were a path in ../gwvplib
11 if(file_exists($lib_base)) {
12         $path = realpath($lib_base);
13         set_include_path(get_include_path().PATH_SEPARATOR.$path);
14 }
15
16 require_once("gwvplib.php");
17 global $db_type, $db_url;
18
19 $db_type = "sqlite";
20 $db_url = "/tmp/unittestdb.db";
21
22 gwvp_dbCreateSQLiteStructure("$db_url");
23
24 gwvp_ConnectDB();
25
26 // function gwvp_createUser($email, $fullname, $password, $nick, $desc, $status)
27 // test users creation
28 gwvp_createUser("test@test.com", "test user", "password", "nick", "desc", "0");
29 gwvp_createUser("test2@test.com", "test2 user", "password", "nick2", "desc2", "0");
30 $users = gwvp_getUsers();
31 echo "Users\n";
32 echo "\tCreate test@test.com\n";
33 if($users[0]["email"] != "test@test.com") {
34         echo "\t\tUser 0 isnt correct: ".$users[0]["email"]."\n";
35 } else {
36         echo "\t\tUser 0 correct\n";
37 }
38 if($users[1]["email"] != "test2@test.com") {
39         echo "\t\tUser 1 isnt correct: ".$users[0]["email"]."\n";
40 } else {
41         echo "\t\tUser 1 correct\n";
42 }
43 echo "\tCheck User It\n";
44 $uid1 = gwvp_getUserId("test@test.com");
45 $uid2 = gwvp_getUserId("test2@test.com");
46 if($uid1 != 1) {
47         echo "\t\tUser 1 id not correct\n";
48 } else {
49         echo "\t\tUser 1 id correct\n";
50 }
51 if($uid2 != 2) {
52         echo "\t\tUser 2 id not correct\n";
53 } else {
54         echo "\t\tUser 2 id correct\n";
55 }
56
57 echo "\tDelete test@test.com\n";
58 gwvp_deleteUser("test@test.com");
59 $users = gwvp_getUsers();
60 if($users[0]["email"] != "test2@test.com") {
61         echo "\t\tUser 0 isnt correct: ".$users[0]["email"]."\n";
62 } else {
63         echo "\t\tUser 0 is correct\n";
64 }
65
66 // test group creation
67 // function gwvp_createGroup($group_name, $is_admin, $owner_id)
68 echo "\n\nGroups\n";
69 echo "\tCreate testgroups\n";
70 gwvp_createGroup("testgroup", true, "1");
71 gwvp_createGroup("testgroup2", true, "1");
72 $groups = gwvp_getGroups();
73 if($groups[0]["name"] != "testgroup") {
74         echo "\t\tGroup 0 isnt correct: ".$groups[0]["name"]."\n";
75 } else {
76         echo "\t\tGroup 0 correct\n";
77 }
78 if($groups[1]["name"] != "testgroup2") {
79         echo "\t\tGroup 1 isnt correct: ".$groups[1]["name"]."\n";
80 } else {
81         echo "\t\tGroup 1 correct\n";
82 }
83 echo "\tCheck group id\n";
84 $gid1 = gwvp_getGroupId("testgroup");
85 $gid2 = gwvp_getGroupId("testgroup2");
86 if($gid1 != 1) {
87         echo "\t\tGroup 1 ID not correct\n";
88 } else {
89         echo "\t\tGroup 1 ID correct\n";
90 }
91 if($gid2 != 2) {
92         echo "\t\tGroup 2 ID not correct\n";
93 } else {
94         echo "\t\tGroup 2 ID correct\n";
95 }
96
97 echo "\tNow delete group\n";
98 gwvp_deleteGroup("testgroup");
99 $groups = gwvp_getGroups();
100 if($groups[0]["name"] != "testgroup2") {
101         echo "\t\tGroup 0 isnt correct: ".$groups[0]["name"]."\n";
102 } else {
103         echo "\t\tGroup 0 correct\n";
104 }
105
106 unlink($db_url);
107 ?>