]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java
fix: typo in receive
[gigi.git] / tests / org / cacert / gigi / pages / admin / TestSEAdminPageDetails.java
index 3cb78b9a10b232b91de888fc500739de040366b9..edcd43442c2646bd3bf0811d99320bd9e802a0c6 100644 (file)
@@ -5,14 +5,18 @@ import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLConnection;
+import java.util.Locale;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.dbObjects.EmailAddress;
 import org.cacert.gigi.dbObjects.Group;
-import org.cacert.gigi.pages.account.MyDetails;
+import org.cacert.gigi.dbObjects.ObjectCache;
+import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.pages.account.History;
+import org.cacert.gigi.pages.account.MyDetails;
 import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage;
 import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage;
 import org.cacert.gigi.testUtils.ClientTest;
@@ -32,15 +36,39 @@ public class TestSEAdminPageDetails extends ClientTest {
         String fname = "Först";
         String lname = "Secönd";
         int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
-        URLConnection uc = new URL("https://" + getServerName() + SupportUserDetailsPage.PATH + id).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
+        URLConnection uc = get(SupportUserDetailsPage.PATH + id);
         uc.setDoOutput(true);
         String res = IOUtils.readURL(uc);
-        assertThat(res, containsString("<input type=\"text\" value=\"" + fname + "\" name=\"fname\">"));
-        assertThat(res, containsString("<input type=\"text\" value=\"" + lname + "\" name=\"lname\">"));
+        assertThat(res, containsString("type=\"text\" value=\"" + fname + "\" name=\"fname\">"));
+        assertThat(res, containsString("type=\"text\" value=\"" + lname + "\" name=\"lname\">"));
         assertThat(res, containsString(email));
     }
 
+    @Test
+    public void testUserDetailsEmail() throws MalformedURLException, IOException, GigiApiException {
+        String email = createUniqueName() + "@example.com";
+        String fname = "Först";
+        String lname = "Secönd";
+        int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
+        String email2 = createUniqueName() + "@example.com";
+        EmailAddress ea = new EmailAddress(User.getById(id), email2, Locale.ENGLISH);
+        getMailReceiver().receive().verify();
+        // Refresh email Object
+        ObjectCache.clearAllCaches();
+        ea = EmailAddress.getById(ea.getId());
+        assertTrue(ea.isVerified());
+
+        String res = IOUtils.readURL(get(SupportUserDetailsPage.PATH + id));
+        assertEquals(2, countRegex(res, Pattern.quote(email)));
+        assertEquals(1, countRegex(res, Pattern.quote(email2)));
+
+        User.getById(id).updateDefaultEmail(ea);
+        clearCaches();
+        res = IOUtils.readURL(get(SupportUserDetailsPage.PATH + id));
+        assertEquals(1, countRegex(res, Pattern.quote(email)));
+        assertEquals(2, countRegex(res, Pattern.quote(email2)));
+    }
+
     @Test
     public void testUserDetailsEdit() throws MalformedURLException, IOException {
         String email = createUniqueName() + "@example.com";
@@ -126,7 +154,7 @@ public class TestSEAdminPageDetails extends ClientTest {
     }
 
     private String getFname(String res) {
-        Pattern p = Pattern.compile("<input type=\"text\" name=\"fname\" value=\"([^\"]*)\">");
+        Pattern p = Pattern.compile("type=\"text\" name=\"fname\" value=\"([^\"]*)\">");
         Matcher m = p.matcher(res);
         if (m.find()) {
             return m.group(1);
@@ -135,7 +163,7 @@ public class TestSEAdminPageDetails extends ClientTest {
     }
 
     private String getFnamePlain(String res) {
-        Pattern p = Pattern.compile("\\s*<td width=\"125\">First Name: </td>\\s*<td width=\"125\">([^<]*)</td>");
+        Pattern p = Pattern.compile("\\s*<td[^>]*>First Name: </td>\\s*<td[^>]*>([^<]*)</td>");
         Matcher m = p.matcher(res);
         if (m.find()) {
             return m.group(1);