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

File VelocityMacrosTest.java

 

Code metrics

0
18
3
1
77
38
3
0.17
6
3
1

Classes

Class Line # Actions
VelocityMacrosTest 30 18 0% 3 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.selenium;
21   
22    import org.junit.Test;
23    import org.xwiki.test.selenium.framework.AbstractXWikiTestCase;
24   
25    /**
26    * Verify proper execution of some Velocity Macros.
27    *
28    * @version $Id: adf97f890896d045ceb43826bb0d77b81bc396f5 $
29    */
 
30    public class VelocityMacrosTest extends AbstractXWikiTestCase
31    {
32    private static final String SYNTAX = "xwiki/2.1";
33   
 
34  1 toggle @Test
35    public void testMacros() throws Exception
36    {
37  1 editInWikiEditor("Test", "VelocityMacrosTest", SYNTAX);
38   
39    // TODO: Add more macro tests here (for performance reasons it's much faster to have more
40    // tests in a single junit test) and modify thet assert so that it checks for exact content
41  1 setFieldValue("content", "{{velocity}}{{html}}#mimetypeimg('image/jpeg' 'photo.jpeg'){{/html}}{{/velocity}}");
42  1 clickEditSaveAndView();
43  1 assertGeneratedHTML("p/img[@src='/xwiki/resources/icons/silk/picture.png' "
44    + "and @alt='Image' and @title='Image']");
45    }
46   
47    /**
48    * Verify that we can create macros in a document and including them into another document.
49    */
 
50  1 toggle @Test
51    public void testIncludeMacrosInPage()
52    {
53  1 editInWikiEditor("Test", "Macro", SYNTAX);
54  1 setFieldValue("content", "{{velocity}}#macro(testIncludeMacrosInPage)hellomacro#end{{/velocity}}");
55  1 clickEditSaveAndView();
56  1 editInWikiEditor("Test", "IncludeMacroTest", SYNTAX);
57  1 setFieldValue("content", "{{velocity}}#includeMacros(\"Test.Macro\")\n#testIncludeMacrosInPage(){{/velocity}}");
58  1 clickEditSaveAndView();
59  1 assertTextPresent("hellomacro");
60    }
61   
62    /**
63    * Verify that a Macro defined in a document is not visible from another document (using XWiki Syntax 1.0).
64    * Note that for XWiki Syntax 2.0 this is verified in a unit test in the Velocity Macro module.
65    */
 
66  1 toggle @Test
67    public void testMacrosAreLocal()
68    {
69  1 editInWikiEditor("Test", "TestMacrosAreLocal1", SYNTAX);
70  1 setFieldValue("content", "{{velocity}}#macro(testMacrosAreLocal)mymacro#end{{/velocity}}");
71  1 clickEditSaveAndView();
72  1 editInWikiEditor("Test", "TestMacrosAreLocal2", SYNTAX);
73  1 setFieldValue("content", "{{velocity}}#testMacrosAreLocal(){{/velocity}}");
74  1 clickEditSaveAndView();
75  1 assertTextNotPresent("mymacro");
76    }
77    }