1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.macro.html

File HTMLMacroTest.java

 

Code metrics

2
16
3
1
80
45
4
0.25
5.33
3
1.33

Classes

Class Line # Actions
HTMLMacroTest 40 16 0% 4 1
0.9523809695.2%
 

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.rendering.macro.html;
21   
22    import java.util.List;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26    import org.xwiki.rendering.block.Block;
27    import org.xwiki.rendering.block.RawBlock;
28    import org.xwiki.rendering.internal.macro.html.HTMLMacro;
29    import org.xwiki.rendering.macro.Macro;
30    import org.xwiki.rendering.macro.MacroExecutionException;
31    import org.xwiki.rendering.transformation.MacroTransformationContext;
32    import org.xwiki.test.jmock.AbstractComponentTestCase;
33   
34    /**
35    * Unit tests for {@link HTMLMacro} that cannot be performed using the Rendering Test framework.
36    *
37    * @version $Id: b202e5726e6b6eaabd8c198d91da525db403a251 $
38    * @since 1.8.3
39    */
 
40    public class HTMLMacroTest extends AbstractComponentTestCase
41    {
42    /**
43    * Verify that inline HTML macros with non inline content generate an exception.
44    */
 
45  1 toggle @Test(expected = MacroExecutionException.class)
46    public void executeMacroWhenNonInlineContentInInlineContext() throws Exception
47    {
48  1 HTMLMacro macro = (HTMLMacro) getComponentManager().getInstance(Macro.class, "html");
49  1 HTMLMacroParameters parameters = new HTMLMacroParameters();
50  1 MacroTransformationContext context = new MacroTransformationContext();
51  1 context.setInline(true);
52  1 macro.execute(parameters, "<ul><li>item</li></ul>", context);
53    }
54   
 
55  1 toggle @Test
56    public void macroDescriptor() throws Exception
57    {
58  1 HTMLMacro macro = (HTMLMacro) getComponentManager().getInstance(Macro.class, "html");
59   
60  1 Assert.assertEquals("Indicate if the HTML should be transformed into valid XHTML or not.",
61    macro.getDescriptor().getParameterDescriptorMap().get("clean").getDescription());
62    }
63   
 
64  1 toggle @Test
65    public void restrictedHtml() throws Exception
66    {
67  1 HTMLMacro macro = (HTMLMacro) getComponentManager().getInstance(Macro.class, "html");
68  1 HTMLMacroParameters parameters = new HTMLMacroParameters();
69  1 MacroTransformationContext context = new MacroTransformationContext();
70  1 context.getTransformationContext().setRestricted(true);
71  1 List<Block> blocks = macro.execute(parameters, "<script>alert('Hello!');</script>", context);
72   
73  1 for (Block block : blocks) {
74  1 if (block instanceof RawBlock) {
75  1 RawBlock rawBlock = (RawBlock) block;
76  1 Assert.assertEquals("<pre>alert('Hello!');</pre>", rawBlock.getRawContent());
77    }
78    }
79    }
80    }