From: Felix Dörre Date: Fri, 6 Nov 2015 15:20:14 +0000 (+0100) Subject: add: testCase for SE-log X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=5a260b7273d4a3f72a40b0b5fa3cb87469b51e61 add: testCase for SE-log --- diff --git a/tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java b/tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java index 39e7c5de..4d70f777 100644 --- a/tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java +++ b/tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java @@ -12,6 +12,7 @@ import java.util.regex.Pattern; import org.cacert.gigi.dbObjects.Group; import org.cacert.gigi.pages.account.MyDetails; +import org.cacert.gigi.pages.account.UserHistory; import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage; import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage; import org.cacert.gigi.testUtils.ClientTest; @@ -65,6 +66,65 @@ public class TestSEAdminPageDetails extends ClientTest { } + @Test + public void testUserDetailsEditToLog() throws MalformedURLException, IOException { + String email = createUniqueName() + "@example.com"; + String fname = "Först"; + String lname = "Secönd"; + int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD); + String clientCookie = login(email, TEST_PASSWORD); + + assertEquals(0, logCountAdmin(id)); + assertEquals(0, logCountUser(clientCookie)); + // chaniging both leads to 2 entries + assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti&lname=Hansel&mname=&suffix=&dobd=1&dobm=2&doby=2000&detailupdate", 0)); + assertEquals(2, logCountAdmin(id)); + assertEquals(2, logCountUser(clientCookie)); + + // Sending same data keeps same + assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti&lname=Hansel&mname=&suffix=&dobd=1&dobm=2&doby=2000&detailupdate", 0)); + assertEquals(2, logCountAdmin(id)); + assertEquals(2, logCountUser(clientCookie)); + + // changing one leads to one entry + assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti2&lname=Hansel&mname=&suffix=&dobd=1&dobm=2&doby=2000&detailupdate", 0)); + assertEquals(3, logCountAdmin(id)); + assertEquals(3, logCountUser(clientCookie)); + + // changing one leads to one entry + assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti2&lname=Hansel&mname=&suffix=&dobd=2&dobm=2&doby=2000&detailupdate", 0)); + assertEquals(4, logCountAdmin(id)); + assertEquals(4, logCountUser(clientCookie)); + + // changing none -> no entry + assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti2&lname=Hansel&mname=&suffix=&dobd=2&dobm=2&doby=2000&detailupdate", 0)); + assertEquals(4, logCountAdmin(id)); + assertEquals(4, logCountUser(clientCookie)); + + } + + private int logCountAdmin(int id) throws IOException { + return getLogEntryCount(IOUtils.readURL(get(UserHistory.SUPPORT_PATH.replace("*", Integer.toString(id)), 0))); + } + + private int logCountUser(String cookie) throws IOException { + return getLogEntryCount(IOUtils.readURL(get(cookie, UserHistory.PATH, 0))); + } + + private int getLogEntryCount(String readURL) { + String s = "Support actions"; + int start = readURL.indexOf(s); + int end = readURL.indexOf("", start); + String logs = readURL.substring(start + s.length(), end); + int i = 0; + int c = -1; + while (i != -1) { + i = logs.indexOf("", i + 1); + c++; + } + return c; + } + private String getFname(String res) { Pattern p = Pattern.compile(""); Matcher m = p.matcher(res);