]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java
upd: cleanup SQL statements to make them statically verifiable.
[gigi.git] / tests / org / cacert / gigi / pages / account / TestMyDetailsEdit.java
index e2b8b9ab0bb122460ab97af46d2434aa7731e6c5..835978489e864f8dfaa86c2dd5499ce7c0a1511a 100644 (file)
@@ -3,6 +3,7 @@ package org.cacert.gigi.pages.account;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
+import java.net.URLEncoder;
 import java.sql.Date;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -10,6 +11,7 @@ import java.util.GregorianCalendar;
 import java.util.TimeZone;
 
 import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.Name;
 import org.cacert.gigi.dbObjects.NamePart;
 import org.cacert.gigi.dbObjects.NamePart.NamePartType;
@@ -94,4 +96,46 @@ public class TestMyDetailsEdit extends ManagedTest {
         c.add(Calendar.DAY_OF_MONTH, -1);
         assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "day=" + c.get(Calendar.DAY_OF_MONTH) + "&month=" + (c.get(Calendar.MONTH) + 1) + "&year=" + c.get(Calendar.YEAR) + "&action=updateDoB", 0));
     }
+
+    @Test
+    public void testChangeResidenceCountry() throws IOException {
+        assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "residenceCountry=DE&action=updateResidenceCountry", 0));
+        User user = User.getById(id);
+        assertEquals("DE", user.getResidenceCountry().getCode());
+    }
+
+    @Test
+    public void testChangeResidenceCountryToNull() throws IOException {
+        User user = User.getById(id);
+        assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "residenceCountry=invalid&action=updateResidenceCountry", 0));
+        assertEquals(null, user.getResidenceCountry());
+    }
+
+    @Test
+    public void testModifyUserGroup() throws IOException {
+        User user = User.getById(id);
+        // test add group
+        assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "action=addGroup&groupToModify=" + URLEncoder.encode(Group.LOCATE_AGENT.getDBName(), "UTF-8"), 0));
+
+        user = User.getById(id);
+        user.refreshGroups();
+        assertTrue(user.isInGroup(Group.LOCATE_AGENT));
+
+        // test remove group
+        assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "action=removeGroup&groupToModify=" + URLEncoder.encode(Group.LOCATE_AGENT.getDBName(), "UTF-8"), 0));
+
+        user = User.getById(id);
+        user.refreshGroups();
+        assertFalse(user.isInGroup(Group.LOCATE_AGENT));
+
+        // test add group that only support can add
+        assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "action=addGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDBName(), "UTF-8"), 0));
+
+        user = User.getById(id);
+        user.refreshGroups();
+        assertFalse(user.isInGroup(Group.SUPPORTER));
+
+        // test add invalid group
+        assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "action=addGroup&groupToModify=non-existing", 0));
+    }
 }