X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Faccount%2FTestMyDetailsEdit.java;h=835978489e864f8dfaa86c2dd5499ce7c0a1511a;hp=6917a1418b2d9d94a1d7adace4f3c5c4ba9fdf8d;hb=0b86fb147b4a61f315770fa5bba4466ca18ddfa8;hpb=9def69bd08ea69eb27786d5b34f00e154e09e9f3 diff --git a/tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java b/tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java index 6917a141..83597848 100644 --- a/tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java +++ b/tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java @@ -3,12 +3,15 @@ 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; +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; @@ -31,7 +34,7 @@ public class TestMyDetailsEdit extends ManagedTest { public void testAddName() throws IOException { int startn = User.getById(id).getNames().length; String newName = createUniqueName(); - assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "fname=" + newName + "&lname=Hansel&action=addName", 0)); + assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "name-type=western&fname=" + newName + "&lname=Hansel&action=addName", 0)); User u = User.getById(id); NamePart[] parts = u.getNames()[startn].getParts(); @@ -77,4 +80,62 @@ public class TestMyDetailsEdit extends ManagedTest { public void testChangeDOBInvalid() throws IOException { assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "day=1&month=1&year=test&action=updateDoB", 0)); } + + @Test + public void testChangeTooYoung() throws IOException { + Calendar c = GregorianCalendar.getInstance(); + c.add(Calendar.YEAR, -User.MINIMUM_AGE); + 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 testChangeTooOld() throws IOException { + Calendar c = GregorianCalendar.getInstance(); + c.add(Calendar.YEAR, -User.MAXIMUM_PLAUSIBLE_AGE); + 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)); + } }