1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.ui

File PreviewTest.java

 

Code metrics

0
27
2
1
105
56
2
0.07
13.5
2
1

Classes

Class Line # Actions
PreviewTest 41 27 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.test.ui;
21   
22    import static org.junit.Assert.*;
23   
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.model.reference.LocalDocumentReference;
27    import org.xwiki.test.ui.po.InlinePage;
28    import org.xwiki.test.ui.po.editor.ClassEditPage;
29    import org.xwiki.test.ui.po.editor.ObjectEditPage;
30    import org.xwiki.test.ui.po.editor.ObjectEditPane;
31    import org.xwiki.test.ui.po.editor.PreviewEditPage;
32    import org.xwiki.test.ui.po.editor.PreviewableEditPage;
33    import org.xwiki.test.ui.po.editor.WikiEditPage;
34   
35    /**
36    * Various tests for verifying the preview mode of a page.
37    *
38    * @version $Id: c70c8017675185dc2b5c0bb6b86266a97c350d48 $
39    * @since 5.2
40    */
 
41    public class PreviewTest extends AbstractTest
42    {
43    @Rule
44    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
45   
46    /**
47    * @see "XWIKI-2490: Preview doesn't work when the document content has script requiring programming rights"
48    */
 
49  1 toggle @Test
50    public void previewWithProgrammingRights()
51    {
52  1 WikiEditPage wikiEditPage = WikiEditPage.gotoPage(getTestClassName(), getTestMethodName());
53  1 wikiEditPage.setContent("{{velocity}}$xwiki.hasAccessLevel('programming')"
54    + " $tdoc.author $tdoc.contentAuthor $tdoc.creator{{/velocity}}");
55  1 PreviewEditPage previewPage = wikiEditPage.clickPreview();
56  1 assertEquals("true XWiki.Admin XWiki.Admin XWiki.Admin", previewPage.getContent());
57    }
58   
59    /**
60    * @see "XWIKI-9527: Sheets are not applied on preview action if the document is new"
61    */
 
62  1 toggle @Test
63    public void previewWithSheet() throws Exception
64    {
65    // Create the class.
66  1 getUtil().rest().deletePage(getTestClassName(), getTestMethodName() + "Class");
67  1 ClassEditPage classEditor = ClassEditPage.gotoPage(getTestClassName(), getTestMethodName() + "Class");
68  1 classEditor.addProperty("color", "String");
69   
70    // Create the sheet.
71  1 getUtil().rest().savePage(new LocalDocumentReference(getTestClassName(), getTestMethodName() + "Sheet"),
72    "{{velocity}}$doc.display('color'){{/velocity}}", "");
73   
74    // Bind the class to the sheet.
75  1 ObjectEditPage objectEditor = ObjectEditPage.gotoPage(getTestClassName(), getTestMethodName() + "Class");
76  1 ObjectEditPane objectEditPane = objectEditor.addObject("XWiki.ClassSheetBinding");
77  1 objectEditPane.setFieldValue(objectEditPane.byPropertyName("sheet"), getTestClassName() + "."
78    + getTestMethodName() + "Sheet");
79  1 objectEditor.clickSaveAndContinue();
80   
81    // Create the template.
82  1 String classFullName = getTestClassName() + "." + getTestMethodName() + "Class";
83  1 getUtil().rest().deletePage(getTestClassName(), getTestMethodName() + "Template");
84  1 objectEditor = ObjectEditPage.gotoPage(getTestClassName(), getTestMethodName() + "Template");
85  1 objectEditPane = objectEditor.addObject(classFullName);
86  1 objectEditPane.setFieldValue(objectEditPane.byPropertyName("color"), "red");
87  1 objectEditor.clickSaveAndContinue();
88   
89    // Create the test instance.
90  1 getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
91  1 getUtil().gotoPage(getTestClassName(), getTestMethodName(), "edit",
92    "template=" + getTestClassName() + "." + getTestMethodName() + "Template");
93  1 objectEditPane = new ObjectEditPane(new InlinePage().getForm(), classFullName, 0);
94  1 objectEditPane.setFieldValue(objectEditPane.byPropertyName("color"), "green");
95   
96    // Test the preview when the page is not yet saved.
97  1 PreviewableEditPage editPage = new PreviewableEditPage();
98  1 PreviewEditPage previewPage = editPage.clickPreview();
99  1 assertEquals("green", previewPage.getContent());
100   
101    // Test the preview after the page is saved.
102  1 previewPage.clickBackToEdit().clickSaveAndView().editInline().clickPreview();
103  1 assertEquals("green", previewPage.getContent());
104    }
105    }