1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.internal.transformation.icon

File IconTransformationTest.java

 

Code metrics

0
23
3
1
136
97
3
0.13
7.67
3
1

Classes

Class Line # Actions
IconTransformationTest 52 23 0% 3 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

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.icon;
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.Test;
28    import org.xwiki.rendering.block.Block;
29    import org.xwiki.rendering.block.MacroMarkerBlock;
30    import org.xwiki.rendering.block.SpecialSymbolBlock;
31    import org.xwiki.rendering.block.XDOM;
32    import org.xwiki.rendering.parser.Parser;
33    import org.xwiki.rendering.renderer.BlockRenderer;
34    import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter;
35    import org.xwiki.rendering.renderer.printer.WikiPrinter;
36    import org.xwiki.rendering.transformation.Transformation;
37    import org.xwiki.rendering.transformation.TransformationContext;
38    import org.xwiki.rendering.transformation.icon.IconTransformationConfiguration;
39    import org.xwiki.test.annotation.AllComponents;
40    import org.xwiki.test.jmock.AbstractMockingComponentTestCase;
41    import org.xwiki.test.jmock.annotation.MockingRequirement;
42   
43    /**
44    * Unit tests for {@link org.xwiki.rendering.internal.transformation.icon.IconTransformation}.
45    *
46    * @version $Id: 2a0f2ef514ad632bb958291fa74e353f5caafecd $
47    * @since 2.6RC1
48    */
49    @AllComponents
50    @MockingRequirement(value = IconTransformation.class,
51    exceptions = { Parser.class, IconTransformationConfiguration.class })
 
52    public class IconTransformationTest extends AbstractMockingComponentTestCase<Transformation>
53    {
 
54  1 toggle @Test
55    public void testTransform() throws Exception
56    {
57  1 String expected = "beginDocument [[syntax]=[XWiki 2.1]]\n"
58    + "beginParagraph\n"
59    + "onWord [Some]\n"
60    + "onSpace\n"
61    + "onImage [Typed = [true] Type = [icon] Reference = [emoticon_smile]] [true]\n"
62    + "onSpace\n"
63    + "onWord [smileys]\n"
64    + "onImage [Typed = [true] Type = [icon] Reference = [emoticon_unhappy]] [true]\n"
65    + "onImage [Typed = [true] Type = [icon] Reference = [emoticon_tongue]] [true]\n"
66    + "onImage [Typed = [true] Type = [icon] Reference = [emoticon_grin]] [true]\n"
67    + "onImage [Typed = [true] Type = [icon] Reference = [emoticon_wink]] [true]\n"
68    + "onImage [Typed = [true] Type = [icon] Reference = [thumb_up]] [true]\n"
69    + "onImage [Typed = [true] Type = [icon] Reference = [thumb_down]] [true]\n"
70    + "onImage [Typed = [true] Type = [icon] Reference = [information]] [true]\n"
71    + "onImage [Typed = [true] Type = [icon] Reference = [accept]] [true]\n"
72    + "onImage [Typed = [true] Type = [icon] Reference = [cancel]] [true]\n"
73    + "onImage [Typed = [true] Type = [icon] Reference = [error]] [true]\n"
74    + "onImage [Typed = [true] Type = [icon] Reference = [add]] [true]\n"
75    + "onImage [Typed = [true] Type = [icon] Reference = [delete]] [true]\n"
76    + "onImage [Typed = [true] Type = [icon] Reference = [help]] [true]\n"
77    + "onImage [Typed = [true] Type = [icon] Reference = [lightbulb]] [true]\n"
78    + "onImage [Typed = [true] Type = [icon] Reference = [lightbulb_off]] [true]\n"
79    + "onImage [Typed = [true] Type = [icon] Reference = [star]] [true]\n"
80    + "endParagraph\n"
81    + "endDocument [[syntax]=[XWiki 2.1]]";
82   
83  1 Parser parser = getComponentManager().getInstance(Parser.class, "xwiki/2.1");
84  1 XDOM xdom = parser.parse(new StringReader("Some :) smileys:(:P:D;)(y)(n)(i)(/)(x)(!)(+)(-)(?)(on)(off)(*)"));
85  1 this.getMockedComponent().transform(xdom, new TransformationContext());
86   
87  1 WikiPrinter printer = new DefaultWikiPrinter();
88  1 BlockRenderer eventBlockRenderer = getComponentManager().getInstance(BlockRenderer.class, "event/1.0");
89  1 eventBlockRenderer.render(xdom, printer);
90  1 Assert.assertEquals(expected, printer.toString());
91    }
92   
 
93  1 toggle @Test
94    public void testTransformIgnoresProtectedContent() throws Exception
95    {
96  1 String expected = "beginDocument\n"
97    + "beginMacroMarkerStandalone [code] []\n"
98    + "onSpecialSymbol [:]\n"
99    + "onSpecialSymbol [)]\n"
100    + "endMacroMarkerStandalone [code] []\n"
101    + "endDocument";
102   
103  1 XDOM xdom = new XDOM(Arrays.asList((Block) new MacroMarkerBlock("code", Collections.<String, String>emptyMap(),
104    Arrays.asList((Block) new SpecialSymbolBlock(':'), new SpecialSymbolBlock(')')), false)));
105  1 getMockedComponent().transform(xdom, new TransformationContext());
106   
107  1 WikiPrinter printer = new DefaultWikiPrinter();
108  1 BlockRenderer eventBlockRenderer = getComponentManager().getInstance(BlockRenderer.class, "event/1.0");
109  1 eventBlockRenderer.render(xdom, printer);
110  1 Assert.assertEquals(expected, printer.toString());
111    }
112   
113    /**
114    * Fixes XWIKI-5729.
115    */
 
116  1 toggle @Test
117    public void testTransformWhenIncompleteMatchExistsFollowedByMatch() throws Exception
118    {
119  1 String expected = "beginDocument [[syntax]=[XWiki 2.1]]\n"
120    + "beginParagraph\n"
121    + "onSpecialSymbol [(]\n"
122    + "onSpace\n"
123    + "onImage [Typed = [true] Type = [icon] Reference = [information]] [true]\n"
124    + "endParagraph\n"
125    + "endDocument [[syntax]=[XWiki 2.1]]";
126   
127  1 Parser parser = getComponentManager().getInstance(Parser.class, "xwiki/2.1");
128  1 XDOM xdom = parser.parse(new StringReader("( (i)"));
129  1 getMockedComponent().transform(xdom, new TransformationContext());
130   
131  1 WikiPrinter printer = new DefaultWikiPrinter();
132  1 BlockRenderer eventBlockRenderer = getComponentManager().getInstance(BlockRenderer.class, "event/1.0");
133  1 eventBlockRenderer.render(xdom, printer);
134  1 Assert.assertEquals(expected, printer.toString());
135    }
136    }