Search in sources :

Example 1 with RegistrationPage

use of org.xwiki.test.ui.po.RegistrationPage in project xwiki-platform by xwiki.

the class InvitationTest method testAcceptInvitation.

/**
 * This test proves that:
 * 1. The accept invitation link sent in the email will work.
 * 2. A user can accept an invitation and be directed to the registration form and can register and login.
 * 3. An invitation once accepted cannot be accepted again nor declined.
 * 4. An invitation once accepted can still be reported as spam.
 */
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testAcceptInvitation() throws Exception {
    TestUtils.Session admin = getUtil().getSession();
    try {
        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, "InvitedMember", "WeakPassword", "WeakPassword", null);
        rp.clickRegister();
        Assert.assertTrue("There were failure messages when registering.", rp.getValidationFailureMessages().isEmpty());
        getDriver().get(getUtil().getURLToLoginAs("InvitedMember", "WeakPassword"));
        Assert.assertTrue("Failed to log user in after registering from invitation.", rp.isAuthenticated());
        // Now switch to guest again and try to accept the invitation again.
        getUtil().forceGuestUser();
        guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.ACCEPT);
        Assert.assertTrue("After the invitation was accepted a user was allowed to accept it again.", guestPage.getMessage().equals("This invitation has already been accepted and the " + "offer is no longer valid."));
        // Try to decline the invitation.
        guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.DECLINE);
        Assert.assertTrue("After the invitation was accepted a user was allowed to decline it.", guestPage.getMessage().equals("This invitation has already been accepted and " + "now cannot be declined."));
        // Prove that the message can still be reported as spam
        guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.REPORT);
        Assert.assertTrue("After the invitation was accepted it now cannot be reported as spam.", guestPage.getMessage().equals(""));
    } finally {
        stopGreenMail();
        getUtil().setSession(admin);
    }
}
Also used : InvitationGuestActionsPage(org.xwiki.invitation.test.po.InvitationGuestActionsPage) RegistrationPage(org.xwiki.test.ui.po.RegistrationPage) TestUtils(org.xwiki.test.ui.TestUtils) MimeMessage(javax.mail.internet.MimeMessage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test)

Example 2 with RegistrationPage

use of org.xwiki.test.ui.po.RegistrationPage in project xwiki-platform by xwiki.

the class InvitationTest method testAcceptInvitationToClosedWiki.

/**
 * This test proves that:
 * 1. A guest cannot register if register permission is removed from XWikiPreferences.
 * 2. Upon receiving an email invitation the guest can register even without register permission.
 */
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
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(0).getSelectElement(By.name("XWiki.XWikiGlobalRights_0_levels")).select("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(0).getSelectElement(By.name("XWiki.XWikiGlobalRights_0_levels")).unSelect("register");
        oep.clickSaveAndContinue();
    }
}
Also used : InvitationGuestActionsPage(org.xwiki.invitation.test.po.InvitationGuestActionsPage) RegistrationPage(org.xwiki.test.ui.po.RegistrationPage) TestUtils(org.xwiki.test.ui.TestUtils) MimeMessage(javax.mail.internet.MimeMessage) ObjectEditPage(org.xwiki.test.ui.po.editor.ObjectEditPage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test)

Aggregations

MimeMessage (javax.mail.internet.MimeMessage)2 Test (org.junit.Test)2 InvitationGuestActionsPage (org.xwiki.invitation.test.po.InvitationGuestActionsPage)2 AbstractTest (org.xwiki.test.ui.AbstractTest)2 TestUtils (org.xwiki.test.ui.TestUtils)2 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)2 RegistrationPage (org.xwiki.test.ui.po.RegistrationPage)2 ObjectEditPage (org.xwiki.test.ui.po.editor.ObjectEditPage)1