Package org.xwiki.test.ui

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

/*
* 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 static org.junit.Assert.*;

import org.junit.Test;
import org.xwiki.test.ui.po.InlinePage;
import org.xwiki.test.ui.po.editor.ClassEditPage;
import org.xwiki.test.ui.po.editor.ObjectEditPage;
import org.xwiki.test.ui.po.editor.ObjectEditPane;
import org.xwiki.test.ui.po.editor.PreviewEditPage;
import org.xwiki.test.ui.po.editor.PreviewableEditPage;
import org.xwiki.test.ui.po.editor.WikiEditPage;

/**
* Various tests for verifying the preview mode of a page.
*
* @version $Id: b9a8d651a70497935a3424548d619d3725e70982 $
* @since 5.2
*/
public class PreviewTest extends AbstractAdminAuthenticatedTest
{
    /**
     * @see "XWIKI-2490: Preview doesn't work when the document content has script requiring programming rights"
     */
    @Test
    public void previewWithProgrammingRights()
    {
        WikiEditPage wikiEditPage = WikiEditPage.gotoPage(getTestClassName(), getTestMethodName());
        wikiEditPage.setContent("{{velocity}}$xwiki.hasAccessLevel('programming')"
            + " $tdoc.author $tdoc.contentAuthor $tdoc.creator{{/velocity}}");
        PreviewEditPage previewPage = wikiEditPage.clickPreview();
        assertEquals("true XWiki.Admin XWiki.Admin XWiki.Admin", previewPage.getContent());
    }

    /**
     * @see "XWIKI-9527: Sheets are not applied on preview action if the document is new"
     */
    @Test
    public void previewWithSheet()
    {
        // Create the class.
        getUtil().deletePage(getTestClassName(), getTestMethodName() + "Class");
        ClassEditPage classEditor = ClassEditPage.gotoPage(getTestClassName(), getTestMethodName() + "Class");
        classEditor.addProperty("color", "String");

        // Create the sheet.
        getUtil().createPage(getTestClassName(), getTestMethodName() + "Sheet",
            "{{velocity}}$doc.display('color'){{/velocity}}", "");

        // Bind the class to the sheet.
        ObjectEditPage objectEditor = ObjectEditPage.gotoPage(getTestClassName(), getTestMethodName() + "Class");
        ObjectEditPane objectEditPane = objectEditor.addObject("XWiki.ClassSheetBinding");
        objectEditPane.setFieldValue(objectEditPane.byPropertyName("sheet"), getTestClassName() + "."
            + getTestMethodName() + "Sheet");
        objectEditor.clickSaveAndContinue();

        // Create the template.
        String classFullName = getTestClassName() + "." + getTestMethodName() + "Class";
        getUtil().deletePage(getTestClassName(), getTestMethodName() + "Template");
        objectEditor = ObjectEditPage.gotoPage(getTestClassName(), getTestMethodName() + "Template");
        objectEditPane = objectEditor.addObject(classFullName);
        objectEditPane.setFieldValue(objectEditPane.byPropertyName("color"), "red");
        objectEditor.clickSaveAndContinue();

        // Create the test instance.
        getUtil().deletePage(getTestClassName(), getTestMethodName());
        getUtil().gotoPage(getTestClassName(), getTestMethodName(), "edit",
            "template=" + getTestClassName() + "." + getTestMethodName() + "Template");
        objectEditPane = new ObjectEditPane(new InlinePage().getForm(), classFullName, 0);
        objectEditPane.setFieldValue(objectEditPane.byPropertyName("color"), "green");

        // Test the preview when the page is not yet saved.
        PreviewableEditPage editPage = new PreviewableEditPage();
        PreviewEditPage previewPage = editPage.clickPreview();
        assertEquals("green", previewPage.getContent());

        // Test the preview after the page is saved.
        previewPage.clickBackToEdit().clickSaveAndView().editInline().clickPreview();
        assertEquals("green", previewPage.getContent());
    }
}
TOP

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

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.