| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
@link |
| 36 |
|
|
| 37 |
|
@version |
| 38 |
|
@since |
| 39 |
|
|
| |
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 4 |
Complexity Density: 0.25 |
|
| 40 |
|
public class HTMLMacroTest extends AbstractComponentTestCase |
| 41 |
|
{ |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 45 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 55 |
1 |
@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 |
|
|
| |
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
1PASS
|
|
| 64 |
1 |
@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 |
|
} |