public void testAcceptInvitationToClosedWiki() throws Exception
{
TestUtils.Session admin = getUtil().getSession();
try {
// First we ban anon from registering.
ObjectEditPage oep = ObjectEditPage.gotoPage("XWiki", "XWikiPreferences");
oep.getObjectsOfClass("XWiki.XWikiGlobalRights").get(2)
.getSelectElement(By.name("XWiki.XWikiGlobalRights_2_levels")).unSelect("register");
oep.clickSaveAndContinue();
// now prove anon cannot register
getUtil().forceGuestUser();
RegistrationPage.gotoPage();
getUtil().assertOnPage(getUtil().getURL("XWiki", "XWikiLogin", "login"));
// Now we try sending and accepting an invitation.
getUtil().setSession(admin);
setSenderPage(InvitationSenderPage.gotoPage());
getSenderPage().fillInDefaultValues();
startGreenMail();
getSenderPage().send();
getGreenMail().waitForIncomingEmail(10000, 1);
MimeMessage[] messages = getGreenMail().getReceivedMessages();
String htmlMessage = getMessageContent(messages[0]).get("htmlPart");
Assert.assertTrue("New invitation is not listed as pending in the footer.",
getSenderPage().getFooter().myPendingInvitations() == 1);
// Now switch to guest.
getUtil().forceGuestUser();
InvitationGuestActionsPage guestPage =
InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.ACCEPT);
Assert.assertTrue("There was an error message when accepting the invitation message:\n"
+ guestPage.getMessage(),
guestPage.getMessage().equals(""));
// Register a new user.
RegistrationPage rp = new RegistrationPage();
rp.fillRegisterForm(null, null, "AnotherInvitedMember", "WeakPassword", "WeakPassword", null);
rp.clickRegister();
Assert.assertTrue("There were failure messages when registering.",
rp.getValidationFailureMessages().isEmpty());
getDriver().get(getUtil().getURLToLoginAs("AnotherInvitedMember", "WeakPassword"));
Assert.assertTrue("Failed to log user in after registering from invitation.", rp.isAuthenticated());
} finally {
stopGreenMail();
getUtil().setSession(admin);
// Better open the wiki back up again.
ObjectEditPage oep = ObjectEditPage.gotoPage("XWiki", "XWikiPreferences");
oep.getObjectsOfClass("XWiki.XWikiGlobalRights").get(2)
.getSelectElement(By.name("XWiki.XWikiGlobalRights_2_levels")).select("register");
oep.clickSaveAndContinue();
}
}