1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.transformation.wikiword

File WikiWordTransformationTest.java

 

Code metrics

0
16
3
1
105
63
3
0.19
5.33
3
1

Classes

Class Line # Actions
WikiWordTransformationTest 51 16 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 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.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    * Unit tests for {@link org.xwiki.rendering.internal.transformation.wikiword.WikiWordTransformation}.
46    *
47    * @version $Id: 4f317eeef4ec038f06a17531e1cce2eb239a3c8c $
48    * @since 2.6RC1
49    */
50    @AllComponents
 
51    public class WikiWordTransformationTest
52    {
53    @Rule
54    public ComponentManagerRule componentManager = new ComponentManagerRule();
55   
56    private Transformation wikiWordTransformation;
57   
 
58  2 toggle @Before
59    public void setUp() throws Exception
60    {
61  2 this.wikiWordTransformation = this.componentManager.getInstance(Transformation.class, "wikiword");
62    }
63   
 
64  1 toggle @Test
65    public void testWikiWordTransformation() throws Exception
66    {
67    // Tests the following at once:
68    // - that a wiki word is recognized
69    // - that several wiki words in a row are recognized
70    // - that wiki words with non ASCII chars are recognized (accented chars)
71    // - that two uppercase letters following each other (as in "XWiki") are not considered a wiki word
72    // - that several uppercases chars followed by lowercases and then one uppercase and lowercase chars is
73    // recognized as a wiki word (eg "XWikiEnterprise")
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   
 
86  1 toggle @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    }