]> WPIA git - gigi.git/blobdiff - tests/club/wpia/gigi/pages/account/TestMyDetailsEdit.java
fix: ensure no blanks are entered between name parts and hyphens
[gigi.git] / tests / club / wpia / gigi / pages / account / TestMyDetailsEdit.java
index 7f2a811ff3fecc68f05177433e0508cf40afd4ed..eed6b77116e4e00c075e5edf763059447fc7cc6e 100644 (file)
@@ -17,9 +17,8 @@ import club.wpia.gigi.GigiApiException;
 import club.wpia.gigi.dbObjects.Group;
 import club.wpia.gigi.dbObjects.Name;
 import club.wpia.gigi.dbObjects.NamePart;
-import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
-import club.wpia.gigi.pages.account.MyDetails;
+import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.testUtils.ManagedTest;
 
 public class TestMyDetailsEdit extends ManagedTest {
@@ -83,11 +82,19 @@ public class TestMyDetailsEdit extends ManagedTest {
         assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "day=1&month=1&year=test&action=updateDoB", 0));
     }
 
+    /**
+     * Tests that changing the date of birth to a too recent one results in an
+     * error.
+     * 
+     * @throws IOException
+     *             when web interactions fail.
+     * @see club.wpia.gigi.TestCalendarUtil#testIsOfAge()
+     */
     @Test
     public void testChangeTooYoung() throws IOException {
         Calendar c = GregorianCalendar.getInstance();
         c.add(Calendar.YEAR, -User.MINIMUM_AGE);
-        c.add(Calendar.DAY_OF_MONTH, +1);
+        c.add(Calendar.DAY_OF_MONTH, +2);
         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));
     }
 
@@ -95,7 +102,7 @@ public class TestMyDetailsEdit extends ManagedTest {
     public void testChangeTooOld() throws IOException {
         Calendar c = GregorianCalendar.getInstance();
         c.add(Calendar.YEAR, -User.MAXIMUM_PLAUSIBLE_AGE);
-        c.add(Calendar.DAY_OF_MONTH, -1);
+        c.add(Calendar.DAY_OF_MONTH, -2);
         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));
     }
 
@@ -140,4 +147,78 @@ public class TestMyDetailsEdit extends ManagedTest {
         // test add invalid group
         assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "action=addGroup&groupToModify=non-existing", 0));
     }
+
+    @Test
+    public void testHyphen() throws IOException {
+
+        String fn = "Hans-Dieter";
+        String fnc = fn;
+        String ln = "Müller-Schmitz";
+        String lnc = ln;
+        testAddName(fn, ln, fnc, lnc);
+
+        fn = "Hans-   Dieter";
+        ln = "Müller-    Schmitz";
+        testAddName(fn, ln, fnc, lnc);
+
+        fn = "Hans    -Dieter";
+        ln = "Müller    -Schmitz";
+        testAddName(fn, ln, fnc, lnc);
+
+        fn = "Hans    -     Dieter";
+        ln = "Müller   -   Schmitz";
+        testAddName(fn, ln, fnc, lnc);
+
+        String[] hyphen = {
+                "\u002d", "\u058a", "\u05be", "\u1806", "\u2010", "\u2011", "\u2012", "\u2013", "\u2014", "\u2015", "\u2e3a", "\u2e3b", "\ufe58", "\ufe63", "\uff0d"
+        };
+
+        for (int i = 0; i < hyphen.length; i++) {
+            fn = "Hans    " + hyphen[i] + "     Dieter";
+            ln = "Müller   " + hyphen[i] + "   Schmitz";
+            testAddName(fn, ln, fnc, lnc);
+        }
+    }
+
+    @Test
+    public void testBlanks() throws IOException {
+
+        String fn = "Hans";
+        String fnc = fn;
+        String ln = "Müller";
+        String lnc = ln;
+        testAddName(fn, ln, fnc, lnc);
+
+        fn = "Hans  ";
+        ln = "Müller  ";
+        testAddName(fn, ln, fnc, lnc);
+
+        fn = "    Hans";
+        ln = "    Müller";
+        testAddName(fn, ln, fnc, lnc);
+
+        fn = "Hans    Dieter";
+        ln = "Müller    Schmitz";
+        testAddName(fn, ln, fnc, lnc, 4);
+
+        fn = "Hans    Dieter   ";
+        ln = "    Müller    Schmitz";
+        testAddName(fn, ln, fnc, lnc, 4);
+    }
+
+    public void testAddName(String fn, String ln, String fnc, String lnc) throws IOException {
+        testAddName(fn, ln, fnc, lnc, 2);
+    }
+
+    public void testAddName(String fn, String ln, String fnc, String lnc, int partLength) throws IOException {
+        int startn = User.getById(id).getNames().length;
+        assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "action=addName&name-type=western&fname=" + fn + "&lname=" + ln, 0));
+        User u = User.getById(id);
+
+        NamePart[] parts = u.getNames()[startn].getParts();
+        assertThat(Arrays.asList(parts), CoreMatchers.hasItem(new NamePart(NamePartType.FIRST_NAME, fnc)));
+        assertThat(Arrays.asList(parts), CoreMatchers.hasItem(new NamePart(NamePartType.LAST_NAME, lnc)));
+        assertEquals(partLength, parts.length);
+        assertEquals(startn + 1, User.getById(id).getNames().length);
+    }
 }