1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.transformation.wikiword; |
21 |
|
|
22 |
|
import java.io.StringReader; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.Collections; |
25 |
|
|
26 |
|
import org.junit.Assert; |
27 |
|
import org.junit.Before; |
28 |
|
import org.junit.Rule; |
29 |
|
import org.junit.Test; |
30 |
|
import org.xwiki.rendering.block.Block; |
31 |
|
import org.xwiki.rendering.block.MacroMarkerBlock; |
32 |
|
import org.xwiki.rendering.block.WordBlock; |
33 |
|
import org.xwiki.rendering.block.XDOM; |
34 |
|
import org.xwiki.rendering.parser.Parser; |
35 |
|
import org.xwiki.rendering.renderer.BlockRenderer; |
36 |
|
import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter; |
37 |
|
import org.xwiki.rendering.renderer.printer.WikiPrinter; |
38 |
|
import org.xwiki.rendering.syntax.Syntax; |
39 |
|
import org.xwiki.rendering.transformation.Transformation; |
40 |
|
import org.xwiki.rendering.transformation.TransformationContext; |
41 |
|
import org.xwiki.test.ComponentManagerRule; |
42 |
|
import org.xwiki.test.annotation.AllComponents; |
43 |
|
|
44 |
|
|
45 |
|
@link |
46 |
|
|
47 |
|
@version |
48 |
|
@since |
49 |
|
|
50 |
|
@AllComponents |
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 3 |
Complexity Density: 0.19 |
|
51 |
|
public class WikiWordTransformationTest |
52 |
|
{ |
53 |
|
@Rule |
54 |
|
public ComponentManagerRule componentManager = new ComponentManagerRule(); |
55 |
|
|
56 |
|
private Transformation wikiWordTransformation; |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
2 |
@Before... |
59 |
|
public void setUp() throws Exception |
60 |
|
{ |
61 |
2 |
this.wikiWordTransformation = this.componentManager.getInstance(Transformation.class, "wikiword"); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
64 |
1 |
@Test... |
65 |
|
public void testWikiWordTransformation() throws Exception |
66 |
|
{ |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
1 |
String testInput = "This is a WikiWord, Another\u00D9ne, XWikiEnterprise, not one: XWiki"; |
75 |
|
|
76 |
1 |
Parser parser = this.componentManager.getInstance(Parser.class, "xwiki/2.1"); |
77 |
1 |
XDOM xdom = parser.parse(new StringReader(testInput)); |
78 |
1 |
this.wikiWordTransformation.transform(xdom, new TransformationContext()); |
79 |
1 |
WikiPrinter printer = new DefaultWikiPrinter(); |
80 |
1 |
BlockRenderer xwiki21BlockRenderer = this.componentManager.getInstance(BlockRenderer.class, "xwiki/2.1"); |
81 |
1 |
xwiki21BlockRenderer.render(xdom, printer); |
82 |
1 |
Assert.assertEquals("This is a [[doc:WikiWord]], [[doc:Another\u00D9ne]], [[doc:XWikiEnterprise]], " |
83 |
|
+ "not one: XWiki", printer.toString()); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void testWikiWordTransformationIgnoresProtectedContent() throws Exception |
88 |
|
{ |
89 |
1 |
String expected = "beginDocument\n" |
90 |
|
+ "beginMacroMarkerStandalone [code] []\n" |
91 |
|
+ "onWord [WikiWord]\n" |
92 |
|
+ "endMacroMarkerStandalone [code] []\n" |
93 |
|
+ "endDocument"; |
94 |
|
|
95 |
1 |
XDOM xdom = new XDOM(Arrays.asList((Block) new MacroMarkerBlock("code", Collections.<String, String>emptyMap(), |
96 |
|
Arrays.asList((Block) new WordBlock("WikiWord")), false))); |
97 |
1 |
this.wikiWordTransformation.transform(xdom, new TransformationContext()); |
98 |
|
|
99 |
1 |
WikiPrinter printer = new DefaultWikiPrinter(); |
100 |
1 |
BlockRenderer eventBlockRenderer = |
101 |
|
this.componentManager.getInstance(BlockRenderer.class, Syntax.EVENT_1_0.toIdString()); |
102 |
1 |
eventBlockRenderer.render(xdom, printer); |
103 |
1 |
Assert.assertEquals(expected, printer.toString()); |
104 |
|
} |
105 |
|
} |