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

File TemplateTest.java

 

Code metrics

2
22
6
1
138
75
7
0.32
3.67
6
1.17

Classes

Class Line # Actions
TemplateTest 36 22 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 3 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 org.junit.Assert;
23    import org.junit.Rule;
24    import org.junit.Test;
25    import org.openqa.selenium.By;
26    import org.xwiki.test.ui.browser.IgnoreBrowser;
27    import org.xwiki.test.ui.browser.IgnoreBrowsers;
28    import org.xwiki.test.ui.po.editor.WikiEditPage;
29   
30    /**
31    * Test template handling.
32    *
33    * @version $Id: 8f2537f7bda3b2f25816f24ff3a1a140d0fe9b57 $
34    * @since 2.4M1
35    */
 
36    public class TemplateTest extends AbstractTest
37    {
38    @Rule
39    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
40   
41    /** Page used for testing: Main.TemplateTest */
42    private WikiEditPage editPage;
43   
44    /**
45    * Test that velocity is rendered
46    */
 
47  1 toggle @Test
48    @IgnoreBrowsers({
49    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
50    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
51    })
52    public void testHelloVelocity()
53    {
54  1 String hello = "Hello Velocity Test Test Test";
55  1 saveVelocity(hello);
56  1 Assert.assertTrue(getDriver().findElement(By.id("xwikicontent")).getText().contains(hello));
57    }
58   
59    /**
60    * Test that an included existing template is displayed correctly
61    */
 
62  1 toggle @Test
63    @IgnoreBrowsers({
64    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
65    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
66    })
67    public void testCorrectTemplate()
68    {
69  1 saveVelocity(includeTemplate("code.vm"), true);
70  1 Assert.assertNotNull(getDriver().findElement(
71    By.xpath("//div[@id='xwikicontent']//textarea[@class='wiki-code']")));
72    }
73   
74    /**
75    * See XWIKI-2580
76    */
 
77  1 toggle @Test
78    @IgnoreBrowsers({
79    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
80    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
81    })
82    public void testWrongTemplate()
83    {
84  1 saveVelocity(includeTemplate("../../"));
85  1 Assert.assertTrue("root directory", getDriver().findElement(By.id("xwikicontent")).getText().length() == 0);
86   
87  1 saveVelocity(includeTemplate("asdfasdf"));
88  1 Assert.assertTrue("not existing template",
89    getDriver().findElement(By.id("xwikicontent")).getText().length() == 0);
90   
91  1 saveVelocity(includeTemplate("../redirect"));
92  1 Assert.assertTrue("file in the parent directory", getDriver().findElement(By.id("xwikicontent")).getText()
93    .length() == 0);
94   
95  1 saveVelocity(includeTemplate("../WEB-INF/version.properties"));
96  1 Assert.assertTrue("file in the wrong directory", getDriver().findElement(By.id("xwikicontent")).getText()
97    .length() == 0);
98   
99  1 saveVelocity(includeTemplate("/chw/../../WEB-INF/../WEB-INF/lib/../version.properties"));
100  1 Assert.assertTrue("file in the wrong directory, not normalized path", getDriver().findElement(
101    By.id("xwikicontent")).getText().length() == 0);
102    }
103   
104    /**
105    * @see #saveVelocity(String, boolean)
106    */
 
107  6 toggle private void saveVelocity(String code)
108    {
109  6 saveVelocity(code, false);
110    }
111   
112    /**
113    * Save a page with given velocity code and switch to view. Encloses <code>code</code> into the {{velocity}} macro
114    * and optionally also {{html}} macro.
115    *
116    * @param code velocity code to save
117    * @param html additionally enclose <code>code</code> in {{html}} if true
118    */
 
119  7 toggle private void saveVelocity(String code, boolean html)
120    {
121  7 this.editPage = WikiEditPage.gotoPage("Main", "TemplateTest");
122  7 if (html) {
123  1 code = "{{html wiki=\"false\"}}\n" + code + "\n{{/html}}";
124    }
125  7 this.editPage.setContent("{{velocity filter=\"none\"}}\n" + code + "\n{{/velocity}}\n");
126  7 this.editPage.clickSaveAndView();
127    }
128   
129    /**
130    * Return velocity code to include a velocity template <code>name</code>
131    *
132    * @param name template to use
133    */
 
134  6 toggle private String includeTemplate(String name)
135    {
136  6 return "#template(\"" + name + "\")\n";
137    }
138    }