2 $lib_base = "../gwvplib/";
5 $WEB_ROOT_FS = realpath(dirname(__FILE__));
6 $BASE_URL = dirname($_SERVER["PHP_SELF"]);
8 global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_name, $db_username, $db_password;
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);
16 require_once("gwvplib.php");
17 global $db_type, $db_url;
20 $db_name = "/tmp/unittestdb.db";
22 gwvp_dbCreateSQLiteStructure("$db_name");
26 // function gwvp_createUser($email, $fullname, $password, $username, $desc, $status)
27 // test users creation
28 gwvp_createUser("test@test.com", "test user", "password", "username", "desc", "0");
29 gwvp_createUser("test2@test.com", "test2 user", "password", "username2", "desc2", "0");
30 gwvp_createUser("test3@test.com", "test2 user", "password", "usernme3", "desc2", "0");
31 $users = gwvp_getUsers();
33 echo "\tCreate test@test.com\n";
34 if($users[0]["email"] != "test@test.com") {
35 echo "\t\tUser 0 isnt correct: ".$users[0]["email"]."\n";
37 echo "\t\tUser 0 correct\n";
39 if($users[1]["email"] != "test2@test.com") {
40 echo "\t\tUser 1 isnt correct: ".$users[0]["email"]."\n";
42 echo "\t\tUser 1 correct\n";
44 echo "\tCheck User It\n";
45 $uid1 = gwvp_getUserId("test@test.com");
46 $uid2 = gwvp_getUserId("test2@test.com");
48 echo "\t\tUser 1 id not correct\n";
50 echo "\t\tUser 1 id correct\n";
53 echo "\t\tUser 2 id not correct\n";
55 echo "\t\tUser 2 id correct\n";
58 echo "\tDelete test@test.com\n";
59 gwvp_deleteUser("test@test.com");
60 $users = gwvp_getUsers();
61 if($users[0]["email"] != "test2@test.com") {
62 echo "\t\tUser 0 isnt correct: ".$users[0]["email"]."\n";
64 echo "\t\tUser 0 is correct\n";
67 // test group creation
68 // function gwvp_createGroup($group_name, $is_admin, $owner_id)
70 echo "\tCreate testgroups\n";
71 gwvp_createGroup("testgroup", true, "3");
72 gwvp_createGroup("testgroup2", false, "3");
73 gwvp_createGroup("testgroup3", true, "2");
74 $groups = gwvp_getGroups();
75 if($groups[0]["name"] != "testgroup") {
76 echo "\t\tGroup 0 isnt correct: ".$groups[0]["name"]."\n";
78 echo "\t\tGroup 0 correct\n";
80 if($groups[1]["name"] != "testgroup2") {
81 echo "\t\tGroup 1 isnt correct: ".$groups[1]["name"]."\n";
83 echo "\t\tGroup 1 correct\n";
85 echo "\tCheck group id\n";
86 $gid1 = gwvp_getGroupId("testgroup");
87 $gid2 = gwvp_getGroupId("testgroup2");
89 echo "\t\tGroup 1 ID not correct\n";
91 echo "\t\tGroup 1 ID correct\n";
94 echo "\t\tGroup 2 ID not correct\n";
96 echo "\t\tGroup 2 ID correct\n";
99 echo "\tNow delete group\n";
100 gwvp_deleteGroup("testgroup");
101 $groups = gwvp_getGroups();
102 if($groups[0]["name"] != "testgroup2") {
103 echo "\t\tGroup 0 isnt correct: ".$groups[0]["name"]."\n";
105 echo "\t\tGroup 0 correct\n";
109 // setup some user permissions to groups
110 echo "\n\nGroup Memberships\n";
111 echo "\tAdd to groups\n";
112 if(!gwvp_addGroupMember("test2@test.com", "testgroup2")) {
113 echo "\t\tadd test2@test.com to testgroup2 failed\n";
115 echo "\t\tadd test2@test.com to testgroup2 ok\n";
117 if(!gwvp_addGroupMember("test3@test.com", "testgroup3")) {
118 echo "\t\tadd test3@test.com to testgroup3 failed\n";
120 echo "\t\tadd test2@test.com to testgroup2 ok\n";
123 echo "\tTest Group Membership\n";
124 // function gwvp_IsGroupMember($email, $groupname)
125 if(!gwvp_isGroupMember("test2@test.com", "testgroup2")) {
126 echo "\t\ttest2@test.com in testgorup2 FAILED\n";
128 echo "\t\ttest2@test.com in testgroup2 ok\n";
130 if(!gwvp_isGroupMember("test3@test.com", "testgroup3")) {
131 echo "\t\ttest2@test.com in testgorup2 FAILED\n";
133 echo "\t\ttest3@test.com in testgroup3 ok\n";
135 if(gwvp_isGroupMember("test2@test.com", "testgroup3")) {
136 echo "\t\ttest2@test.com in testgorup3 FAILED\n";
138 echo "\t\ttest2@test.com in testgroup3 ok\n";
140 if(gwvp_isGroupMember("test3@test.com", "testgroup2")) {
141 echo "\t\ttest3@test.com in testgorup2 FAILED\n";
143 echo "\t\ttest3@test.com in testgroup2 ok\n";
146 echo "\tTest Admin Role\n";
147 if(gwvp_IsUserAdmin("test2@test.com")) {
148 echo "\t\tUser test2@test.com reported admin FAILED\n";
150 echo "\t\tUset test2@test.com reported as not admin, ok\n";
152 if(!gwvp_IsUserAdmin("test3@test.com")) {
153 echo "\t\tUser test3@test.com reported not admin FAILED\n";
155 echo "\t\tUset test3@test.com reported as admin, ok\n";
158 echo "\ttest group memberships\n";
159 gwvp_createGroup("testgroup4", false, "1");
160 gwvp_createGroup("testgroup5", true, "1");
161 gwvp_addGroupMember("test3@test.com", "testgroup4");
162 gwvp_addGroupMember("test3@test.com", "testgroup5");
163 gwvp_addGroupMember("test2@test.com", "testgroup5");
164 $groupstest2 = gwvp_getGroupsForUser("test2@test.com");
165 $groupstest3 = gwvp_getGroupsForUser("test3@test.com");
166 echo "\t\tGroups for test2 should be testgroup2, testgroup5 - ";
167 if($groupstest2[0] != "testgroup2"||$groupstest2[1] != "testgroup5") {
172 echo "\t\tGroups for test3 should be testgroup3, testgroup4, testgroup5 - ";
173 if($groupstest3[0] != "testgroup3"||$groupstest3[1] != "testgroup4"||$groupstest3[2] != "testgroup5") {
179 echo "\tTest Group Ownership\n";
180 if(gwvp_groupOwner("testgroup2") != "test3@test.com") {
181 echo "\t\tTest owner of testgroup2 = test3@test.com - FAILED!\n";
183 echo "\t\tTest owner of testgroup2 = test3@test.com - ok!\n";
185 if(gwvp_groupOwner("testgroup3") != "test2@test.com") {
186 echo "\t\tTest owner of testgroup3 = test2@test.com - FAILED!\n";
188 echo "\t\tTest owner of testgroup3 = test2@test.com - ok!\n";