User page code for user/group admin
[gwvp.git] / unittests / sqlitedb.php
index 21de42a..c5c0d37 100644 (file)
@@ -17,9 +17,9 @@ require_once("gwvplib.php");
 global $db_type, $db_url;
 
 $db_type = "sqlite";
-$db_url = "/tmp/unittestdb.db";
+$db_name = "/tmp/unittestdb.db";
 
-gwvp_dbCreateSQLiteStructure("$db_url");
+gwvp_dbCreateSQLiteStructure("$db_name");
 
 gwvp_ConnectDB();
 
@@ -27,6 +27,7 @@ gwvp_ConnectDB();
 // 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");
+gwvp_createUser("test3@test.com", "test2 user", "password", "nick2", "desc2", "0");
 $users = gwvp_getUsers();
 echo "Users\n";
 echo "\tCreate test@test.com\n";
@@ -67,8 +68,9 @@ if($users[0]["email"] != "test2@test.com") {
 // 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");
+gwvp_createGroup("testgroup", true, "3");
+gwvp_createGroup("testgroup2", false, "3");
+gwvp_createGroup("testgroup3", true, "2");
 $groups = gwvp_getGroups();
 if($groups[0]["name"] != "testgroup") {
        echo "\t\tGroup 0 isnt correct: ".$groups[0]["name"]."\n";
@@ -103,5 +105,89 @@ if($groups[0]["name"] != "testgroup2") {
        echo "\t\tGroup 0 correct\n";
 }
 
-unlink($db_url);
+
+// setup some user permissions to groups
+echo "\n\nGroup Memberships\n";
+echo "\tAdd to groups\n";
+if(!gwvp_addGroupMember("test2@test.com", "testgroup2")) {
+       echo "\t\tadd test2@test.com to testgroup2 failed\n";
+} else {
+       echo "\t\tadd test2@test.com to testgroup2 ok\n";
+}
+if(!gwvp_addGroupMember("test3@test.com", "testgroup3")) {
+       echo "\t\tadd test3@test.com to testgroup3 failed\n";
+} else {
+       echo "\t\tadd test2@test.com to testgroup2 ok\n";
+}
+
+echo "\tTest Group Membership\n";
+// function gwvp_IsGroupMember($email, $groupname)
+if(!gwvp_isGroupMember("test2@test.com", "testgroup2")) {
+       echo "\t\ttest2@test.com in testgorup2 FAILED\n";
+} else {
+       echo "\t\ttest2@test.com in testgroup2 ok\n";
+}
+if(!gwvp_isGroupMember("test3@test.com", "testgroup3")) {
+       echo "\t\ttest2@test.com in testgorup2 FAILED\n";
+} else {
+       echo "\t\ttest3@test.com in testgroup3 ok\n";
+}
+if(gwvp_isGroupMember("test2@test.com", "testgroup3")) {
+       echo "\t\ttest2@test.com in testgorup3 FAILED\n";
+} else {
+       echo "\t\ttest2@test.com in testgroup3 ok\n";
+}
+if(gwvp_isGroupMember("test3@test.com", "testgroup2")) {
+       echo "\t\ttest3@test.com in testgorup2 FAILED\n";
+} else {
+       echo "\t\ttest3@test.com in testgroup2 ok\n";
+}
+
+echo "\tTest Admin Role\n";
+if(gwvp_IsUserAdmin("test2@test.com")) {
+       echo "\t\tUser test2@test.com reported admin FAILED\n";
+} else {
+       echo "\t\tUset test2@test.com reported as not admin, ok\n";
+}
+if(!gwvp_IsUserAdmin("test3@test.com")) {
+       echo "\t\tUser test3@test.com reported not admin FAILED\n";
+} else {
+       echo "\t\tUset test3@test.com reported as admin, ok\n";
+}
+
+echo "\ttest group memberships\n";
+gwvp_createGroup("testgroup4", false, "1");
+gwvp_createGroup("testgroup5", true, "1");
+gwvp_addGroupMember("test3@test.com", "testgroup4");
+gwvp_addGroupMember("test3@test.com", "testgroup5");
+gwvp_addGroupMember("test2@test.com", "testgroup5");
+$groupstest2 = gwvp_getGroupsForUser("test2@test.com");
+$groupstest3 = gwvp_getGroupsForUser("test3@test.com");
+echo "\t\tGroups for test2 should be testgroup2, testgroup5 - ";
+if($groupstest2[0] != "testgroup2"||$groupstest2[1] != "testgroup5") {
+       echo "FAILED!\n";
+} else {
+       echo "ok\n";
+}
+echo "\t\tGroups for test3 should be testgroup3, testgroup4, testgroup5 - ";
+if($groupstest3[0] != "testgroup3"||$groupstest3[1] != "testgroup4"||$groupstest3[2] != "testgroup5") {
+       echo "FAILED!\n";
+} else {
+       echo "ok\n";
+}
+
+echo "\tTest Group Ownership\n";
+if(gwvp_groupOwner("testgroup2") != "test3@test.com") {
+       echo "\t\tTest owner of testgroup2 = test3@test.com - FAILED!\n";
+} else {
+       echo "\t\tTest owner of testgroup2 = test3@test.com - ok!\n";
+}
+if(gwvp_groupOwner("testgroup3") != "test2@test.com") {
+       echo "\t\tTest owner of testgroup3 = test2@test.com - FAILED!\n";
+} else {
+       echo "\t\tTest owner of testgroup3 = test2@test.com - ok!\n";
+}
+
+
+unlink($db_name);
 ?>
\ No newline at end of file