Package org.xwiki.test.ui

Source Code of org.xwiki.test.ui.DeletePageTest

/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.test.ui;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.xwiki.test.ui.framework.AbstractAdminAuthenticatedTest;
import org.xwiki.test.ui.framework.elements.DeleteConfirmationPage;
import org.xwiki.test.ui.framework.elements.DeletePage;
import org.xwiki.test.ui.framework.elements.ViewPage;
import org.xwiki.test.ui.xe.elements.HomePage;

/**
* Tests the Delete button present in the top level menu.
*
* @version $Id$
* @since 3.0M3
*/
public class DeletePageTest extends AbstractAdminAuthenticatedTest
{
    private ViewPage viewPage;

    private static final String LOGGED_USERNAME = "Administrator";

    private static final String CONFIRMATION = "The document has been deleted.";

    private static final String DELETE_ACTION = "delete";

    private static final String SPACE_VALUE = "Test";

    private static final String PAGE_VALUE = "DeletePageTest";

    private static final String PAGE_CONTENT = "This page is used for testing delete functionality";

    private static final String PAGE_TITLE = "Page title that will be deleted";

    @Before
    public void setUp()
    {
        super.setUp();

        // Create a new Page that will be deleted
        this.viewPage = getUtil().createPage(SPACE_VALUE, PAGE_VALUE, PAGE_CONTENT, PAGE_TITLE);
    }

    @Test
    public void testDeleteOkWhenConfirming()
    {
        DeletePage deletePage = this.viewPage.delete();
        // This tests for regression of XWIKI-1388
        Assert.assertNotNull("The interface should not show the user as logged out while deleting page",
            this.viewPage.getCurrentUser());
        DeleteConfirmationPage deleteConfirmationPage = deletePage.confirm();
        Assert.assertEquals(LOGGED_USERNAME, deleteConfirmationPage.getPageDeleter());
        Assert.assertEquals(CONFIRMATION, deleteConfirmationPage.getConfirmationMessage());
    }

    /**
     * Verify that we can delete a page without showing the confirmation dialog box and that we can redirect to any page
     * we want when the delete is done.
     */
    @Test
    public void testDeletePageCanSkipConfirmationAndDoARedirect()
    {
        HomePage homePage = new HomePage();
        getUtil().gotoPage(SPACE_VALUE, PAGE_VALUE, DELETE_ACTION,
            "confirm=1&xredirect=" + homePage.getURL());
        Assert.assertTrue(homePage.isOnHomePage());
    }

    /**
     * Verify that we can skip the default delete result page and instead redirect to any page we want.
     */
    @Test
    public void testDeletePageCanDoRedirect()
    {
        HomePage homePage = new HomePage();
        getUtil().gotoPage(SPACE_VALUE, PAGE_VALUE, DELETE_ACTION, "xredirect=" + homePage.getURL());
        WebElement yesButton = getDriver().findElement(By.xpath("//input[@value='yes']"));
        yesButton.click();
        Assert.assertTrue(homePage.isOnHomePage());
    }

    /**
     * Verify that hitting cancel on the delete confirmation dialog box goes back to the page being deleted.
     */
    @Test
    public void testDeletePageGoesToOriginalPageWhenCancelled()
    {
        DeletePage deletePage = this.viewPage.delete();
        deletePage.cancel();
        Assert.assertTrue(getDriver().getCurrentUrl().equals(getUtil().getURL(SPACE_VALUE, PAGE_VALUE)));
    }

    @Test
    public void testDeletePageIsImpossibleWhenNoDeleteRights()
    {
        // Logs out to be guest and not have the right to delete
        this.viewPage.logout();
        Assert.assertFalse(this.viewPage.canDelete());
    }
}
TOP

Related Classes of org.xwiki.test.ui.DeletePageTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.