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

File EditInlineTest.java

 

Code metrics

0
64
5
1
170
89
5
0.08
12.8
5
1

Classes

Class Line # Actions
EditInlineTest 34 64 0% 5 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.wysiwyg;
21   
22    import java.util.Date;
23   
24    import org.junit.Test;
25    import org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase;
26   
27    import static org.junit.Assert.*;
28   
29    /**
30    * Functional tests for in-line editing using the WYSIWYG editor.
31    *
32    * @version $Id: 3118020fb224c3167e9e6f3610a1b7401c78fc10 $
33    */
 
34    public class EditInlineTest extends AbstractWysiwygTestCase
35    {
36    /**
37    * Tests if a property whose name contains the underscore character can be edited properly.
38    *
39    * @see XWIKI-4746: GWT-editor wont render field's content if it has underscores in it's name.
40    */
 
41  1 toggle @Test
42    public void testEditPropertyWithUnderscore()
43    {
44  1 StringBuffer spaceName = new StringBuffer(this.getClass().getSimpleName());
45  1 spaceName.insert(spaceName.length() / 2, "_0_");
46   
47  1 StringBuffer pageName = new StringBuffer(getTestMethodName());
48  1 pageName.insert(pageName.length() / 2, "_17_");
49   
50    // Create a class with a property that has '_' in its name.
51  1 open(spaceName.toString(), pageName.toString(), "edit", "editor=class");
52  1 String propertyName = "my_1_property";
53  1 addWysiwygProperty(propertyName);
54  1 clickEditSaveAndContinue();
55   
56    // Create an object of the previously created class.
57  1 open(spaceName.toString(), pageName.toString(), "edit", "editor=object");
58  1 addObject(pageName.toString());
59  1 String propertyValue = String.valueOf(new Date().getTime());
60  1 setFieldValue(spaceName + "." + pageName + "_0_" + propertyName, propertyValue);
61  1 clickEditSaveAndContinue();
62   
63    // Display the object.
64  1 open(spaceName.toString(), pageName.toString(), "edit", "editor=wiki");
65  1 setFieldValue("content", display(pageName.toString(), propertyName));
66  1 clickEditSaveAndView();
67  1 assertTextPresent(propertyValue);
68   
69    // Edit the object in-line.
70  1 open(spaceName.toString(), pageName.toString(), "edit", "editor=inline");
71  1 waitForEditorToLoad();
72  1 assertEquals(propertyValue, getRichTextArea().getText());
73   
74    // Change the property value.
75  1 propertyValue = new StringBuffer(propertyValue).reverse().toString();
76  1 setContent(propertyValue);
77  1 clickEditSaveAndView();
78  1 assertTextPresent(propertyValue);
79    }
80   
81    /**
82    * Tests if the initial content of the editor is taken from the template when creating a new document from a
83    * template.
84    *
85    * @see XWIKI-4814: WYSIWYG does not preserve TextArea property values when creating a new document from a class
86    * template
87    */
 
88  1 toggle @Test
89    public void testEditorInitialContentWhenCreatingDocumentFromTemplate()
90    {
91  1 String spaceName = this.getClass().getSimpleName();
92  1 String pageName = getTestMethodName();
93  1 String className = pageName + "Class";
94  1 String templateName = pageName + "Template";
95  1 String sheetName = pageName + "Sheet";
96  1 String propertyName = "myproperty";
97   
98    // Create the class.
99  1 deletePage(spaceName, className);
100  1 open(spaceName, className, "edit", "editor=class");
101  1 addWysiwygProperty(propertyName);
102  1 clickEditSaveAndContinue();
103   
104    // Create the sheet.
105  1 deletePage(spaceName, sheetName);
106  1 open(spaceName, sheetName, "edit", "editor=wiki");
107  1 setFieldValue("content", display(className, propertyName));
108  1 clickEditSaveAndContinue();
109   
110    // Create the template.
111    // Add the object.
112  1 deletePage(spaceName, templateName);
113  1 open(spaceName, templateName, "edit", "editor=object");
114  1 addObject(className);
115  1 String propertyValue = String.valueOf(new Date().getTime());
116  1 setFieldValue(spaceName + "." + className + "_0_" + propertyName, propertyValue);
117  1 clickEditSaveAndContinue();
118    // Include the sheet.
119  1 open(spaceName, templateName, "edit", "editor=wiki");
120  1 setFieldValue("content", "{{include document=\"" + sheetName + "\"/}}");
121  1 clickEditSaveAndView();
122  1 assertTextPresent(propertyValue);
123   
124    // Create a new page from template.
125  1 open(spaceName, pageName, "edit", "editor=inline&template=" + templateName);
126  1 waitForEditorToLoad();
127  1 assertEquals(propertyValue, getRichTextArea().getText());
128    }
129   
130    /**
131    * Adds a {@code TextArea} property with the specified name and sets its preferred editor to WYSIWYG.
132    *
133    * @param propertyName the name of the property to add
134    */
 
135  2 toggle private void addWysiwygProperty(String propertyName)
136    {
137  2 setFieldValue("propname", propertyName);
138  2 getSelenium().select("proptype", "TextArea");
139  2 clickEditAddProperty();
140    // Expand the added XClass property to modify its 'editor' meta property.
141  2 getSelenium().click("xproperty_" + propertyName);
142  2 getSelenium().select(propertyName + "_editor", "Wysiwyg");
143    }
144   
145    /**
146    * Adds an object of the specified class to the current page.
147    *
148    * @param className the class name
149    */
 
150  2 toggle private void addObject(String className)
151    {
152  2 getSelenium().select("classname", className);
153  2 clickEditAddObject();
154    }
155   
156    /**
157    * @param className the name of a XWiki class
158    * @param propertyName which property of the specified class to display
159    * @return the code to display the specified property
160    */
 
161  2 toggle private String display(String className, String propertyName)
162    {
163  2 StringBuffer code = new StringBuffer();
164  2 code.append("{{velocity}}\n");
165  2 code.append("$doc.use(\"" + className + "\")\n");
166  2 code.append("$doc.display(\"" + propertyName + "\")\n");
167  2 code.append("{{/velocity}}");
168  2 return code.toString();
169    }
170    }