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

File AdministrationTest.java

 
testLockingAndUnlocking: [Is This Page Locked true] isn't present.
testCodeToExecuteNotInlineIfNoConfigurationClass: [//span[@class='xwikirenderingerror']] is present.
testCodeToExecuteNotInline: [//span[@class='xwikirenderingerror']] is present.
 

Code metrics

8
322
21
1
704
430
25
0.08
15.33
21
1.19

Classes

Class Line # Actions
AdministrationTest 35 322 0% 25 67
0.809116880.9%
 

Contributing tests

This file is covered by 14 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.selenium;
21   
22    import org.junit.Test;
23    import org.openqa.selenium.By;
24    import org.openqa.selenium.Keys;
25    import org.openqa.selenium.WebElement;
26    import org.xwiki.test.selenium.framework.AbstractXWikiTestCase;
27   
28    import static org.junit.Assert.*;
29   
30    /**
31    * Verify the overall Administration application features.
32    *
33    * @version $Id: 4a381d59df3719b4840a83ade4876733401c3cbf $
34    */
 
35    public class AdministrationTest extends AbstractXWikiTestCase
36    {
37    /*
38    * Test to see an application page is included only if that application exists
39    */
 
40  1 toggle @Test
41    public void testApplicationSection()
42    {
43    // Delete the Blog.Categories page and test it's not present in the admin global menu anymore
44  1 deletePage("XWiki", "SearchAdmin");
45  1 clickAdministerWiki();
46  1 assertElementNotPresent("//*[contains(@class, 'admin-menu')]//a[contains(@href, 'section=Search')]");
47  1 restorePage("XWiki", "SearchAdmin");
48    }
49   
50    /*
51    * Test modifying XWiki.XWikiPreferences multi-language field and save it.
52    */
 
53  1 toggle @Test
54    public void testSettingXWikiPreferences()
55    {
56  1 clickAdministerWiki();
57  1 clickLinkWithXPath("//a[text()='Localization']", true);
58  1 getSelenium().select("//select[@name='XWiki.XWikiPreferences_0_multilingual']", "label=Yes");
59  1 clickLinkWithXPath("//input[@value='Save']", true);
60  1 assertElementPresent("//a[@id='tmLanguages']");
61    }
62   
63    /*
64    * Test adding a new category in Blog Categories
65    */
66    /* Disabled until the new blog can insert its own administration page.
67    @Test
68    public void testBlogAdmin()
69    {
70    open("XWiki", "XWikiPreferences", "admin");
71   
72    // select global administration
73    clickLinkWithLocator("//span[text()='General']", true);
74    getSelenium().select("//select[@id='XWiki.XWikiPreferences_0_editor']", "label=Text");
75    clickLinkWithLocator("//input[@value='Save']");
76    assertElementPresent("//span[@id='showsectionswrapper']");
77    clickLinkWithXPath("//a[@id='showsections']", false);
78    assertElementPresent("//span[@id='hidesectionswrapper']");
79    clickLinkWithLocator("//span[text()='Blog categories']");
80    setFieldValue("name", "New Category");
81    setFieldValue("description", "New Category Content");
82    clickLinkWithLocator("//input[@value='Add']", true);
83    assertTextPresent("New Category");
84    }*/
85   
86    /*
87    * Test Panel Wizard
88    */
 
89  1 toggle @Test
90    public void testPanelsAdmin()
91    {
92  1 open("XWiki", "XWikiPreferences", "admin");
93   
94    // test panel wizard at global level
95  1 clickLinkWithLocator("//a[text()='Panel Wizard']");
96  1 waitForBodyContains("Page Layout");
97  1 clickLinkWithXPath("//a[@href='#PageLayoutSection']", false);
98  1 waitForElement("//div[@id = 'rightcolumn']");
99  1 clickLinkWithXPath("//div[@id='rightcolumn']", false);
100  1 waitForBodyContains("Panel List");
101  1 clickLinkWithXPath("//a[@href='#PanelListSection']", false);
102  1 dragAndDrop(By.xpath("//div[@class='panel expanded CategoriesPanel']//h1"), By.id("rightPanels"));
103  1 assertElementPresent("//div[@id = 'rightPanels']/div[contains(@class, 'CategoriesPanel')]");
104  1 clickLinkWithXPath("//button[text()='Save the new layout']", false);
105  1 waitForNotificationSuccessMessage("The layout has been saved properly.");
106  1 open("Main", "WebHome");
107  1 assertElementNotPresent("leftPanels");
108  1 assertElementPresent("rightPanels");
109  1 assertElementPresent("//div[@id = 'rightPanels']/div[contains(@class, 'CategoriesPanel')]");
110   
111    // Revert changes
112  1 open("XWiki", "XWikiPreferences", "admin");
113  1 clickLinkWithLocator("//a[text()='Panel Wizard']");
114  1 waitForBodyContains("Page Layout");
115  1 clickLinkWithXPath("//a[@href='#PageLayoutSection']", false);
116  1 waitForCondition("selenium.isElementPresent(\"//div[@id='bothcolumns']\")!=false;");
117  1 clickLinkWithXPath("//div[@id='bothcolumns']", false);
118  1 waitForBodyContains("Panel List");
119  1 clickLinkWithXPath("//a[@href='#PanelListSection']", false);
120  1 dragAndDrop(By.xpath("//div[@id='rightPanels']//div[contains(@class, 'CategoriesPanel')]//h1"),
121    By.xpath("//div[@id='allviewpanels']//div[@class='accordionTabContentBox']"));
122  1 assertElementNotPresent("//div[@id = 'rightPanels']//div[contains(@class, 'CategoriesPanel')]");
123  1 clickLinkWithXPath("//button[text()='Save the new layout']", false);
124  1 waitForNotificationSuccessMessage("The layout has been saved properly.");
125  1 open("Main", "WebHome");
126  1 assertElementPresent("leftPanels");
127  1 assertElementPresent("rightPanels");
128  1 assertElementNotPresent("//div[@id = 'rightPanels']//div[contains(@class, 'CategoriesPanel')]");
129   
130    // test panel wizard at space level
131  1 open("TestPanelsAdmin", "WebHome", "edit", "editor=wiki");
132  1 setFieldValue("content", "aaa");
133  1 clickEditSaveAndView();
134  1 open("TestPanelsAdmin", "WebPreferences", "admin");
135  1 clickLinkWithLocator("//a[text()='Panel Wizard']");
136  1 waitForBodyContains("Page Layout");
137  1 clickLinkWithXPath("//a[@href='#PageLayoutSection']", false);
138  1 waitForCondition("selenium.isElementPresent(\"//div[@id='leftcolumn']\")!=false;");
139  1 clickLinkWithXPath("//div[@id='leftcolumn']", false);
140  1 waitForBodyContains("Panel List");
141  1 clickLinkWithXPath("//a[@href='#PanelListSection']", false);
142  1 dragAndDrop(By.xpath("//div[@class='panel expanded CategoriesPanel']//h1"), By.id("leftPanels"));
143  1 clickLinkWithXPath("//button[text()='Save the new layout']", false);
144  1 waitForNotificationSuccessMessage("The layout has been saved properly.");
145  1 open("TestPanelsAdmin", "WebHome");
146  1 assertElementPresent("leftPanels");
147  1 assertElementPresent("//div[@id = 'leftPanels']//div[contains(@class, 'CategoriesPanel')]");
148  1 open("XWiki", "WebHome");
149  1 assertElementPresent("rightPanels");
150  1 assertElementNotPresent("//div[@id = 'leftPanels']//div[contains(@class, 'CategoriesPanel')]");
151    }
152   
153    /*
154    * Test add configurable application to existing section.
155    *
156    * This test depends on the "Presentation" section existing.
157    * Tests: XWiki.ConfigurableClass
158    */
 
159  1 toggle @Test
160    public void testAddConfigurableApplicationInExistingSection()
161    {
162    // Create the configurable for global admin.
163  1 createConfigurableApplication("Main", "TestConfigurable", "Presentation", true);
164    // Check it's available in global section.
165  1 open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=Presentation");
166  1 assertConfigurationPresent("Main", "TestConfigurable");
167    // Check it's not available in space section.
168  1 open("Main", "WebPreferences", "admin", "editor=spaceadmin&section=Presentation");
169  1 assertConfigurationNotPresent("Main", "TestConfigurable");
170    // Switch application to non-global
171  1 open("Main", "TestConfigurable", "edit", "editor=object");
172  1 expandObject("XWiki.ConfigurableClass", 0);
173  1 getSelenium().uncheck("XWiki.ConfigurableClass_0_configureGlobally");
174  1 clickEditSaveAndView();
175    // Check that it is available in space section.
176  1 open("Main", "WebPreferences", "admin", "editor=spaceadmin&section=Presentation");
177  1 assertConfigurationPresent("Main", "TestConfigurable");
178    // Check that it's not available in another space.
179  1 open("XWiki", "WebPreferences", "admin", "editor=spaceadmin&section=Presentation");
180  1 assertConfigurationNotPresent("Main", "TestConfigurable");
181    // Check that it's not available in global section.
182  1 open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=Presentation");
183  1 assertConfigurationNotPresent("Main", "TestConfigurable");
184    }
185   
186    /**
187    * Test add configurable application to a nonexistent section.
188    * <p>
189    * This test depends on the "HopingThereIsNoSectionByThisName" section not existing.<br/>
190    * Tests: XWiki.ConfigurableClass
191    */
 
192  1 toggle @Test
193    public void testAddConfigurableApplicationInNonexistantSection()
194    {
195  1 String section = "HopingThereIsNoSectionByThisName";
196    // Create the configurable for global admin.
197  1 createConfigurableApplication("Main", "TestConfigurable", section, true);
198    // Check it's available in global section.
199  1 clickAdministerWiki();
200  1 waitForElement(getAdminMenuItemLocator(section));
201  1 clickLinkWithText(section);
202  1 assertConfigurationPresent("Main", "TestConfigurable");
203    // Check that it's not available in space section.
204  1 open("Main", "WebPreferences", "admin");
205    // Assert there is no menu item in the administration menu for our configurable application.
206  1 assertElementNotPresent(getAdminMenuItemLocator(section));
207    }
208   
209    /**
210    * Fails if a user can create a Configurable application without having edit access to the configuration page (in
211    * this case: XWikiPreferences)
212    * <p>
213    * Tests: XWiki.ConfigurableClass
214    */
 
215  1 toggle @Test
216    public void testConfigurableCreatedByUnauthorizedWillNotExecute()
217    {
218    // Make sure the configurable page doesn't exist because otherwise we may fail to overwrite it with a
219    // non-administrator user.
220  1 deletePage("Main", "testConfigurableCreatedByUnauthorizedWillNotExecute");
221    // Create the configurable for global administrator.
222  1 loginAndRegisterUser("anotherJoker", "bentOnMalice", false);
223  1 String nonExistingSection = "HopingThereIsNoSectionByThisName";
224  1 createConfigurableApplication("Main",
225    "testConfigurableCreatedByUnauthorizedWillNotExecute",
226    nonExistingSection, true);
227  1 loginAsAdmin();
228  1 open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=" + nonExistingSection);
229  1 assertConfigurationNotEditable("Main", "testConfigurableCreatedByUnauthorizedWillNotExecute");
230    }
231   
232    /*
233    * Creates a document with 2 configurable objects, one gets configured globally in one section and displays
234    * 2 configuration fields, the other is configured in the space in another section and displays the other 2
235    * fields. Fails if they are not displayed as they should be.
236    *
237    * Tests: XWiki.ConfigurableClass
238    */
 
239  1 toggle @Test
240    public void testApplicationConfiguredInMultipleSections()
241    {
242  1 String space = "Main";
243  1 String page = "TestConfigurable";
244   
245  1 createConfigurableApplication(space, page, "TestSection1", true);
246  1 open(space, page, "edit", "editor=object");
247    // Add a second configurable object.
248  1 getSelenium().select("classname", "value=XWiki.ConfigurableClass");
249  1 clickButtonAndContinue("//input[@name='action_objectadd']");
250  1 setFieldValue("XWiki.ConfigurableClass_1_displayInSection", "TestSection2");
251  1 setFieldValue("XWiki.ConfigurableClass_1_heading", "Some Other Heading");
252  1 setFieldValue("XWiki.ConfigurableClass_1_configurationClass", space + "." + page);
253  1 getSelenium().uncheck("XWiki.ConfigurableClass_1_configureGlobally");
254    // Set propertiesToShow so that each config only shows half of the properties.
255  1 setFieldValue("XWiki.ConfigurableClass_1_propertiesToShow", "TextArea, Select");
256  1 setFieldValue("XWiki.ConfigurableClass_0_propertiesToShow", "String, Boolean");
257  1 clickEditSaveAndView();
258   
259    // Assert that half of the configuration shows up but not the other half.
260  1 open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=TestSection1");
261  1 assertElementPresent("//div[@id='admin-page-content']/h2[@id='HSomeHeading']/span");
262    // Fields
263  1 String fullName = space + "." + page;
264  1 String form = "//div[@id='admin-page-content']/form[@action='/xwiki/bin/save/" + space + "/" + page + "']";
265  1 assertElementPresent(form + "/fieldset//label['String']");
266  1 assertElementPresent(form + "/fieldset//input[@name='" + fullName + "_0_String']");
267  1 assertElementPresent(form + "/fieldset//label['Boolean']");
268  1 assertElementPresent(form + "/fieldset//select[@name='" + fullName + "_0_Boolean']");
269  1 assertElementPresent(form + "/fieldset/input[@id='" + fullName + "_redirect']");
270    // xredirect
271  1 assertElementPresent(form + "/fieldset/input[@value='" + getSelenium().getLocation() + "'][@name='xredirect']");
272    // Save button
273    // assertElementPresent(form + "/div/p/span/input[@type='submit']");
274    // Javascript injects a save button outside of the form and removes the default save button.
275  1 waitForElement("//div/div/p/span/input[@type='submit'][@value='Save']");
276    // Should not be here
277  1 assertElementNotPresent(form + "/fieldset//textarea[@name='" + fullName + "_0_TextArea']");
278  1 assertElementNotPresent(form + "/fieldset//select[@name='" + fullName + "_0_Select']");
279   
280    // Now we go to where the other half of the configuration should be.
281  1 open("Main", "WebPreferences", "admin", "editor=spaceadmin&section=TestSection2");
282  1 assertElementPresent("//h2[@id='HSomeOtherHeading']/span");
283    // Fields
284  1 assertElementPresent(form + "/fieldset//label");
285  1 assertElementPresent(form + "/fieldset//textarea[@name='" + fullName + "_0_TextArea']");
286  1 assertElementPresent(form + "/fieldset//select[@name='" + fullName + "_0_Select']");
287  1 assertElementPresent(form + "/fieldset/input[@id='" + fullName + "_redirect']");
288    // xredirect
289  1 assertElementPresent(form + "/fieldset/input[@value='" + getSelenium().getLocation() + "'][@name='xredirect']");
290    // Save button
291    // assertElementPresent(form + "/div/p/span/input[@type='submit']");
292    // Javascript injects a save button outside of the form and removes the default save button.
293  1 waitForElement("//div/div/p/span/input[@type='submit'][@value='Save']");
294    // Should not be here
295  1 assertElementNotPresent(form + "/fieldset//input[@name='" + fullName + "_0_String']");
296  1 assertElementNotPresent(form + "/fieldset//select[@name='" + fullName + "_0_Boolean']");
297    }
298   
299    /*
300    * Make sure html macros and pre tags are not being stripped
301    * @see: http://jira.xwiki.org/jira/browse/XAADMINISTRATION-141
302    *
303    * Tests: XWiki.ConfigurableClass
304    */
 
305  1 toggle @Test
306    public void testNotStrippingHtmlMacros()
307    {
308  1 String space = "Main";
309  1 String page = "TestConfigurable";
310  1 String test = "{{html}} <pre> {{html clean=\"false\"}} </pre> {{/html}}";
311   
312  1 String fullName = space + "." + page;
313  1 String form = "//div[@id='admin-page-content']/form[@action='/xwiki/bin/save/" + space + "/" + page + "']";
314   
315  1 createConfigurableApplication(space, page, "TestSection1", true);
316  1 open(space, page, "edit", "editor=object");
317  1 expandObject(fullName, 0);
318  1 setFieldValue(fullName + "_0_TextArea", test);
319  1 setFieldValue(fullName + "_0_String", test);
320  1 clickEditSaveAndView();
321   
322  1 open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=TestSection1");
323  1 waitForTextPresent(form + "/fieldset//textarea[@name='" + fullName + "_0_TextArea']", test);
324    // Getting content from an input field required getValue and not getText
325  1 assertTrue(getSelenium().getValue(form + "/fieldset//input[@name='" + fullName + "_0_String']").equals(test));
326    }
327   
328    /*
329    * If a value is specified for linkPrefix, then a link is generated with linkPrefix + prettyName of the property from
330    * the configuration class.
331    * linkPrefix = "http://www.xwiki.org/bin/view/Main/"
332    * property prettyName = "WebHome"
333    * generated link should equal "http://www.xwiki.org/bin/view/Main/WebHome"
334    *
335    * Tests: XWiki.ConfigurableClass
336    */
 
337  1 toggle @Test
338    public void testLabelLinkGeneration()
339    {
340  1 String space = "Main";
341  1 String page = "TestConfigurable";
342  1 createConfigurableApplication(space, page, "TestSection3", true);
343  1 open(space, page, "edit", "editor=object");
344  1 setFieldValue("XWiki.ConfigurableClass_0_linkPrefix", "TheLinkPrefix");
345  1 clickEditSaveAndView();
346   
347  1 open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=TestSection3");
348  1 assertElementPresent("//form/fieldset//a[@href='TheLinkPrefixString']");
349  1 assertElementPresent("//form/fieldset//a[@href='TheLinkPrefixBoolean']");
350  1 assertElementPresent("//form/fieldset//a[@href='TheLinkPrefixTextArea']");
351  1 assertElementPresent("//form/fieldset//a[@href='TheLinkPrefixSelect']");
352    }
353   
354    /*
355    * Fails unless XWiki.ConfigurableClass locks each page on view and unlocks any other configurable page.
356    * Also fails if codeToExecute is not being evaluated.
357    *
358    * Tests: XWiki.ConfigurableClass
359    */
 
360  0 toggle @Test
361    public void testLockingAndUnlocking()
362    {
363  0 String space = "Main";
364  0 String page1 = "TestConfigurable";
365  0 String page2 = "TestConfigurable2";
366  0 String isThisPageLocked = "{{velocity}}Is This Page Locked $doc.getLocked(){{/velocity}}";
367  0 createConfigurableApplication(space, page1, "TestSection4", true);
368  0 createConfigurableApplication(space, page2, "TestSection5", true);
369  0 open(space, page1, "edit", "editor=wiki");
370  0 setFieldValue("content", isThisPageLocked);
371  0 clickEditSaveAndView();
372  0 open(space, page2, "edit", "editor=wiki");
373  0 setFieldValue("content", isThisPageLocked);
374  0 clickEditSaveAndView();
375   
376    // Now we go to the documents and see which is locked.
377  0 open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=TestSection4");
378   
379  0 try {
380    // We have to switch user context without logging out, logging out removes all locks.
381    // We have to open a new window because otherwise the lock is removed when we leave the administration page.
382  0 getSelenium().openWindow("http://127.0.0.1:8080" + getUrl(space, page1, "view"), getTestMethodName());
383  0 getSelenium().selectWindow(getTestMethodName());
384  0 Test failure here assertTextPresent("Is This Page Locked true");
385   
386  0 open("http://127.0.0.1:8080" + getUrl(space, page2, "view"));
387  0 assertTextPresent("Is This Page Locked false");
388   
389  0 getSelenium().selectWindow(null);
390  0 open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=TestSection5");
391   
392  0 getSelenium().selectWindow(getTestMethodName());
393  0 open("http://127.0.0.1:8080" + getUrl(space, page1, "view"));
394  0 assertTextPresent("Is This Page Locked false");
395   
396  0 open("http://127.0.0.1:8080" + getUrl(space, page2, "view"));
397  0 assertTextPresent("Is This Page Locked true");
398   
399    // Close the window we needed for a different user context.
400  0 getSelenium().close();
401    } finally {
402  0 getSelenium().selectWindow(null);
403    }
404    }
405   
406    /*
407    * If CodeToExecute is defined in a configurable app, then it should be evaluated.
408    * Also header should be evaluated and not just printed.
409    * If XWiki.ConfigurableClass is saved with programming rights, it should resave itself so that it doesn't have them.
410    */
 
411  1 toggle @Test
412    public void testCodeToExecutionAndAutoSandboxing()
413    {
414  1 String space = "Main";
415  1 String page = "TestConfigurable";
416  1 String codeToExecute = "#set($code = 's sh')"
417    + "Thi${code}ould be displayed."
418    + "#if($xcontext.hasProgrammingRights())"
419    + "This should not be displayed."
420    + "#end";
421  1 String heading = "#set($code = 'his sho')"
422    + "T${code}uld also be displayed.";
423  1 createConfigurableApplication(space, page, "TestSection6", true);
424  1 open(space, page, "edit", "editor=object");
425  1 expandObject("XWiki.ConfigurableClass", 0);
426  1 setFieldValue("XWiki.ConfigurableClass_0_codeToExecute", codeToExecute);
427  1 setFieldValue("XWiki.ConfigurableClass_0_heading", heading);
428  1 setFieldValue("XWiki.ConfigurableClass_0_configurationClass", "");
429  1 clickEditSaveAndView();
430   
431    // Our admin will foolishly save XWiki.ConfigurableClass, giving it programming rights.
432  1 open("XWiki", "ConfigurableClass", "edit", "editor=wiki");
433   
434  1 try {
435    // Since we modify ConfigurableClass, we must modify it back after to prevent polluting further tests.
436    // See http://code.google.com/p/selenium/issues/detail?id=2876 .
437  1 getDriver().findElement(By.id("content")).sendKeys(Keys.chord(Keys.CONTROL, "a"),
438    Keys.chord(Keys.CONTROL, "c"), Keys.ARROW_RIGHT,
439    "{{velocity}}Has Programming permission: $xcontext.hasProgrammingRights(){{/velocity}}");
440  1 clickEditSaveAndContinue();
441   
442    // Now we look at the section for our configurable.
443  1 open("XWiki", "ConfigurableClass", "view", "editor=globaladmin&section=TestSection6");
444   
445  1 assertTextPresent("This should be displayed.");
446  1 assertTextPresent("This should also be displayed.");
447  1 assertTextNotPresent("This should not be displayed.");
448  1 assertTextPresent("Has Programming permission: false");
449    // Make sure javascript has not added a Save button.
450  1 assertElementNotPresent("//div/div/p/span/input[@type='submit'][@value='Save']");
451    } finally {
452  1 open("XWiki", "ConfigurableClass", "edit", "editor=wiki");
453  1 getDriver().findElement(By.id("content")).sendKeys(Keys.chord(Keys.CONTROL, "a"),
454    Keys.chord(Keys.CONTROL, "v"));
455  1 clickEditSaveAndContinue();
456    }
457    }
458   
459    /*
460    * Proves that ConfigurationClass#codeToExecute is not rendered inline even if there is no
461    * custom configuration class and the on;y content is custom content.
462    * Tests: XWiki.ConfigurableClass
463    */
 
464  0 toggle @Test
465    public void testCodeToExecuteNotInlineIfNoConfigurationClass()
466    {
467  0 String space = "Main";
468  0 String page = "TestConfigurable";
469  0 String test = "{{html}} <div> <p> hello </p> </div> {{/html}}";
470   
471  0 open(space, page, "delete", "confirm=1");
472  0 createConfigurableApplication(space, page, "TestSection1", true);
473  0 open(space, page, "edit", "editor=object");
474  0 expandObject("XWiki.ConfigurableClass", 0);
475  0 setFieldValue("XWiki.ConfigurableClass_0_configurationClass", "");
476  0 setFieldValue("XWiki.ConfigurableClass_0_codeToExecute", test);
477  0 clickEditSaveAndView();
478   
479  0 open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=TestSection1");
480  0 Test failure here assertElementNotPresent("//span[@class='xwikirenderingerror']");
481    }
482   
483    /*
484    * Proves that ConfigurationClass#codeToExecute is not rendered inline whether it's at the top of the
485    * form or inside of the form.
486    * Tests: XWiki.ConfigurableClass
487    */
 
488  0 toggle @Test
489    public void testCodeToExecuteNotInline()
490    {
491  0 String space = "Main";
492  0 String page = "TestConfigurable";
493  0 String test = "{{html}} <div> <p> hello </p> </div> {{/html}}";
494   
495  0 createConfigurableApplication(space, page, "TestSection1", true);
496  0 open(space, page, "edit", "editor=object");
497  0 expandObject("XWiki.ConfigurableClass", 0);
498  0 setFieldValue("XWiki.ConfigurableClass_0_codeToExecute", test);
499  0 setFieldValue("XWiki.ConfigurableClass_0_propertiesToShow", "String, Boolean");
500   
501  0 getSelenium().select("classname", "value=XWiki.ConfigurableClass");
502  0 clickButtonAndContinue("//input[@name='action_objectadd']");
503  0 setFieldValue("XWiki.ConfigurableClass_1_displayInSection", "TestSection1");
504  0 setFieldValue("XWiki.ConfigurableClass_1_configurationClass", space + "." + page);
505  0 setFieldValue("XWiki.ConfigurableClass_1_propertiesToShow", "TextArea, Select");
506  0 setFieldValue("XWiki.ConfigurableClass_1_codeToExecute", test);
507  0 getSelenium().check("XWiki.ConfigurableClass_1_configureGlobally");
508  0 clickEditSaveAndView();
509   
510  0 open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=TestSection1");
511  0 Test failure here assertElementNotPresent("//span[@class='xwikirenderingerror']");
512    }
513   
514    /**
515    * Test functionality of the ForgotUsername page:
516    * <ul>
517    * <li>A user can be found using correct email</li>
518    * <li>No user is found using wrong email</li>
519    * <li>Email text is properly escaped</li>
520    * </ul>
521    */
 
522  1 toggle @Test
523    public void testForgotUsername()
524    {
525  1 String space = "Test";
526  1 String page = "SQLTestPage";
527  1 String mail = "webmaster@xwiki.org"; // default Admin mail
528  1 String user = "Admin";
529  1 String badMail = "bad_mail@evil.com";
530   
531    // Ensure there is a page we will try to find using HQL injection
532  1 editInWikiEditor(space, page);
533  1 setFieldValue("title", page);
534  1 setFieldValue("content", page);
535  1 clickEditSaveAndView();
536   
537    // test that it finds the correct user
538  1 open("XWiki", "ForgotUsername");
539  1 setFieldValue("e", mail);
540  1 submit("//input[@type='submit']"); // there are no other buttons
541  1 assertTextNotPresent("No account is registered using this email address");
542  1 assertElementPresent("//div[@id='xwikicontent']//strong[text()='" + user + "']");
543   
544    // test that bad mail results in no results
545  1 open("XWiki", "ForgotUsername");
546  1 setFieldValue("e", badMail);
547  1 submit("//input[@type='submit']"); // there are no other buttons
548  1 assertTextPresent("No account is registered using this email address");
549  1 assertElementNotPresent("//div[@id='xwikicontent']//strong[@value='" + user + "']");
550   
551    // XWIKI-4920 test that the email is properly escaped
552  1 open("XWiki", "ForgotUsername");
553  1 setFieldValue("e", "a' synta\\'x error");
554  1 submit("//input[@type='submit']"); // there are no other buttons
555  1 assertTextPresent("No account is registered using this email address");
556  1 assertTextNotPresent("Error");
557    }
558   
559    /**
560    * @return an XPath to locate the item with the specified label in the administration vertical menu
561    */
 
562  2 toggle public String getAdminMenuItemLocator(String label)
563    {
564  2 return "//*[contains(@class, 'admin-menu')]//a[. = '" + label + "']";
565    }
566   
567    /*
568    * Fails if there is an administration icon for the named section.
569    * Must be in the administration app first.
570    * Tests: XWiki.ConfigurableClass
571    */
 
572  0 toggle public void assertConfigurationIconNotPresent(String section)
573    {
574  0 assertElementNotPresent("//div[contains(@class,'admin-menu')]//li[contains(@href,'section=" + section + "')]");
575    }
576   
577    /**
578    * Will fail unless it detects a configuration of the type created by createConfigurableApplication.<br/>
579    * Tests: XWiki.ConfigurableClass
580    */
 
581  3 toggle public void assertConfigurationPresent(String space, String page)
582    {
583  3 assertElementPresent("//div[@id='admin-page-content']/h2[@id='HSomeHeading']/span");
584    // Fields
585  3 String fullName = space + "." + page;
586  3 String form = "//div[@id='admin-page-content']/form[@action='/xwiki/bin/save/" + space + "/" + page + "']";
587  3 assertElementPresent(form + "/fieldset/dl/dt[1]/label");
588  3 assertElementPresent(form + "/fieldset/dl/dd[1]/input[@name='" + fullName + "_0_String']");
589  3 assertElementPresent(form + "/fieldset/dl/dt[2]/label");
590  3 assertElementPresent(form + "/fieldset/dl/dd[2]/select[@name='" + fullName + "_0_Boolean']");
591  3 assertElementPresent(form + "/fieldset/dl/dt[3]/label");
592  3 assertElementPresent(form + "/fieldset/dl/dd[3]/textarea[@name='" + fullName + "_0_TextArea']");
593  3 assertElementPresent(form + "/fieldset/dl/dt[4]/label");
594  3 assertElementPresent(form + "/fieldset/dl/dd[4]/select[@name='" + fullName + "_0_Select']");
595  3 assertElementPresent(form + "/fieldset/input[@id='" + fullName + "_redirect']");
596  3 assertElementPresent(form + "/fieldset/input[@value='" + getSelenium().getLocation() + "'][@name='xredirect']");
597    // JavaScript injects a save button outside of the form and removes the default save button.
598  3 waitForElement("//*[@class = 'admin-buttons']//input[@type = 'submit' and @value = 'Save']");
599    }
600   
601    /*
602    * Will fail if it detects a configuration of the type created by createConfigurableApplication.
603    * Tests: XWiki.ConfigurableClass
604    */
 
605  3 toggle public void assertConfigurationNotPresent(String space, String page)
606    {
607  3 assertElementNotPresent("//div[@id='admin-page-content']/h1[@id='HCustomize" + space + "." + page + ":']/span");
608  3 assertElementNotPresent("//div[@id='admin-page-content']/h2[@id='HSomeHeading']/span");
609  3 assertConfigurationNotEditable(space, page);
610    }
611   
 
612  4 toggle public void assertConfigurationNotEditable(String space, String page)
613    {
614  4 assertElementNotPresent("//div[@id='admin-page-content']/form[@action='/xwiki/bin/save/"
615    + space + "/" + page + "']");
616    }
617   
618    /**
619    * Creates a new page with a configuration class with some simple fields<br/>
620    * then adds an object of class configurable and one of it's own class.<br/>
621    * Tests: XWiki.ConfigurableClass
622    */
 
623  11 toggle public void createConfigurableApplication(String space, String page, String section, boolean global)
624    {
625    // We have to use an existing space because the copy page form doesn't allow entering a new space.
626  11 String storageSpace = "Sandbox";
627  11 String storagePage = "CreateConfigurableApplication";
628   
629  11 if (!tryToCopyPage(storageSpace, storagePage, space, page)) {
630    // Create the page with a simple configuration class.
631  8 createPage(space, page, "Test configurable application.", "xwiki/2.1");
632  8 open(space, page, "edit", "editor=class");
633  8 setFieldValue("propname", "String");
634  8 setFieldValue("proptype", "String");
635  8 clickButtonAndContinue("//input[@name='action_propadd']");
636  8 setFieldValue("propname", "Boolean");
637  8 setFieldValue("proptype", "Boolean");
638  8 clickButtonAndContinue("//input[@name='action_propadd']");
639  8 setFieldValue("propname", "TextArea");
640  8 setFieldValue("proptype", "TextArea");
641  8 clickButtonAndContinue("//input[@name='action_propadd']");
642    // Expand the TextArea property we just added in order to set the "editor" meta property.
643  8 getSelenium().click("xproperty_TextArea");
644  8 getSelenium().select("TextArea_editor", "value=Text");
645  8 clickEditSaveAndContinue();
646  8 setFieldValue("propname", "Select");
647  8 setFieldValue("proptype", "StaticList");
648  8 clickButtonAndContinue("//input[@name='action_propadd']");
649   
650    // Go to the object section.
651  8 open(space, page, "edit", "editor=object");
652   
653    // Add a configurable object which points to the new class as the configuration class.
654  8 getSelenium().select("classname", "value=XWiki.ConfigurableClass");
655  8 clickButtonAndContinue("//input[@name='action_objectadd']");
656  8 clickEditSaveAndView();
657   
658    // Try to place it in the storage area.
659  8 tryToCopyPage(space, page, storageSpace, storagePage);
660    }
661   
662    // Go to the object section.
663  11 open(space, page, "edit", "editor=object");
664   
665    // Add an object of the new class.
666  11 waitForElement("classname");
667  11 getSelenium().select("classname", "value=" + space + "." + page);
668    // Scroll the page to the top because the edit menu can be activated when we hover over the add button.
669  11 getSelenium().runScript("window.scrollTo(0, 0)");
670  11 clickButtonAndContinue("//input[@name='action_objectadd']");
671   
672  11 setFieldValue("XWiki.ConfigurableClass_0_displayInSection", section);
673  11 setFieldValue("XWiki.ConfigurableClass_0_heading", "Some Heading");
674  11 setFieldValue("XWiki.ConfigurableClass_0_configurationClass", space + "." + page);
675   
676    // Unfold the XWiki.ConfigurableClass object so that we can modify its properties
677  11 WebElement configurableClassObj = getDriver().findElement(By.id("xobject_XWiki.ConfigurableClass_0"));
678  11 if (configurableClassObj.getAttribute("class").contains("collapsed")) {
679  0 configurableClassObj.click();
680    }
681   
682  11 if (global) {
683  11 getSelenium().check("XWiki.ConfigurableClass_0_configureGlobally");
684    } else {
685  0 getSelenium().uncheck("XWiki.ConfigurableClass_0_configureGlobally");
686    }
687    // We won't set linkPrefix, propertiesToShow, codeToExecute, or iconAttachment.
688   
689  11 clickEditSaveAndView();
690    }
691   
692    /**
693    * This is used by createConfigurableApplication to store a copy of the default configurable to speed up making
694    * them.
695    */
 
696  19 toggle public boolean tryToCopyPage(String fromSpace, String fromPage, String toSpace, String toPage)
697    {
698  19 open(fromSpace, fromPage);
699  19 if (!isExistingPage()) {
700  1 return false;
701    }
702  18 return copyPage(fromSpace, fromPage, toSpace, toPage);
703    }
704    }