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

File XWikiSyntaxBlockRendererTest.java

 

Code metrics

0
37
9
1
236
172
9
0.24
4.11
9
1

Classes

Class Line # Actions
XWikiSyntaxBlockRendererTest 54 37 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 7 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.renderer.xwiki20;
21   
22    import java.util.Arrays;
23   
24    import org.junit.jupiter.api.BeforeEach;
25    import org.junit.jupiter.api.Test;
26    import org.xwiki.component.manager.ComponentManager;
27    import org.xwiki.rendering.block.Block;
28    import org.xwiki.rendering.block.BulletedListBlock;
29    import org.xwiki.rendering.block.DefinitionDescriptionBlock;
30    import org.xwiki.rendering.block.DefinitionListBlock;
31    import org.xwiki.rendering.block.DefinitionTermBlock;
32    import org.xwiki.rendering.block.GroupBlock;
33    import org.xwiki.rendering.block.HeaderBlock;
34    import org.xwiki.rendering.block.ListItemBlock;
35    import org.xwiki.rendering.block.NewLineBlock;
36    import org.xwiki.rendering.block.ParagraphBlock;
37    import org.xwiki.rendering.block.SectionBlock;
38    import org.xwiki.rendering.block.TableBlock;
39    import org.xwiki.rendering.block.TableCellBlock;
40    import org.xwiki.rendering.block.TableHeadCellBlock;
41    import org.xwiki.rendering.block.TableRowBlock;
42    import org.xwiki.rendering.block.WordBlock;
43    import org.xwiki.rendering.listener.HeaderLevel;
44    import org.xwiki.rendering.renderer.BlockRenderer;
45    import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter;
46    import org.xwiki.rendering.syntax.Syntax;
47    import org.xwiki.test.annotation.AllComponents;
48    import org.xwiki.test.junit5.mockito.ComponentTest;
49   
50    import static org.junit.jupiter.api.Assertions.assertEquals;
51   
52    @ComponentTest
53    @AllComponents
 
54    public class XWikiSyntaxBlockRendererTest
55    {
56    private BlockRenderer renderer;
57   
 
58  7 toggle @BeforeEach
59    public void before(ComponentManager componentManager) throws Exception
60    {
61  7 this.renderer = componentManager.getInstance(BlockRenderer.class, Syntax.XWIKI_2_0.toIdString());
62    }
63   
 
64  17 toggle private String render(Block block)
65    {
66  17 DefaultWikiPrinter wikiPrinter = new DefaultWikiPrinter();
67  17 this.renderer.render(block, wikiPrinter);
68   
69  17 return wikiPrinter.toString();
70    }
71   
 
72  1 toggle @Test
73    public void inline()
74    {
75  1 assertEquals("word", render(new WordBlock("word")));
76    }
77   
 
78  1 toggle @Test
79    public void tableCellsWithInlineContentOnly()
80    {
81    // Use case: simple word in cell
82  1 Block tableBlock = new TableBlock(
83    Arrays.asList(new TableRowBlock(
84    Arrays.asList(new TableCellBlock(
85    Arrays.asList(new WordBlock("word")))))));
86  1 assertEquals("|word", render(tableBlock));
87    }
88   
 
89  1 toggle @Test
90    public void tableCellsWithStandaloneContent()
91    {
92    // Use case: Header in a table cell
93  1 Block tableBlock = new TableBlock(
94    Arrays.asList(new TableRowBlock(
95    Arrays.asList(new TableCellBlock(
96    Arrays.asList(new SectionBlock(
97    Arrays.asList(new HeaderBlock(
98    Arrays.asList(new WordBlock("heading")), HeaderLevel.LEVEL1)
99    ))))))));
100  1 assertEquals("|(((\n= heading =\n)))", render(tableBlock));
101   
102    // Use case: Paragraph in a table cell
103  1 tableBlock = new TableBlock(
104    Arrays.asList(new TableRowBlock(
105    Arrays.asList(new TableCellBlock(
106    Arrays.asList(new ParagraphBlock(
107    Arrays.asList(new WordBlock("word")))))))));
108  1 assertEquals("|(((\nword\n)))", render(tableBlock));
109   
110    // Use Case: Group in a table cell
111    // Note: A GroupBlock is considered inline content
112  1 tableBlock = new TableBlock(
113    Arrays.asList(new TableRowBlock(
114    Arrays.asList(new TableCellBlock(
115    Arrays.asList(new GroupBlock(
116    Arrays.asList(new WordBlock("word")))))))));
117  1 assertEquals("|(((\nword\n)))", render(tableBlock));
118   
119    // Use case: List on a table cell
120  1 tableBlock = new TableBlock(
121    Arrays.asList(new TableRowBlock(
122    Arrays.asList(new TableCellBlock(
123    Arrays.asList(new BulletedListBlock(
124    Arrays.asList(new ListItemBlock(
125    Arrays.asList(new WordBlock("word")))))))))));
126  1 assertEquals("|(((\n* word\n)))", render(tableBlock));
127    }
128   
 
129  1 toggle @Test
130    public void tableHeadCellsWithInlineContentOnly()
131    {
132    // Use case: simple word in head cell
133  1 Block block = new TableBlock(
134    Arrays.asList(new TableRowBlock(
135    Arrays.asList(new TableHeadCellBlock(
136    Arrays.asList(new WordBlock("word")))))));
137  1 assertEquals("|=word", render(block));
138    }
139   
 
140  1 toggle @Test
141    public void tableHeadCellsWithStandaloneContent()
142    {
143    // Use case: Header in a table head cell
144  1 Block block = new TableBlock(
145    Arrays.asList(new TableRowBlock(
146    Arrays.asList(new TableHeadCellBlock(
147    Arrays.asList(new SectionBlock(
148    Arrays.asList(new HeaderBlock(
149    Arrays.asList(new WordBlock("heading")), HeaderLevel.LEVEL1)
150    ))))))));
151  1 assertEquals("|=(((\n= heading =\n)))", render(block));
152   
153    // Use case: Paragraph in a table head cell
154  1 block = new TableBlock(
155    Arrays.asList(new TableRowBlock(
156    Arrays.asList(new TableHeadCellBlock(
157    Arrays.asList(new ParagraphBlock(
158    Arrays.asList(new WordBlock("word")))))))));
159  1 assertEquals("|=(((\nword\n)))", render(block));
160   
161    // Use Case: Group in a table head cell
162    // Note: A GroupBlock is considered inline content
163  1 block = new TableBlock(
164    Arrays.asList(new TableRowBlock(
165    Arrays.asList(new TableHeadCellBlock(
166    Arrays.asList(new GroupBlock(
167    Arrays.asList(new WordBlock("word")))))))));
168  1 assertEquals("|=(((\nword\n)))", render(block));
169   
170    // Use case: List on a table head cell
171  1 block = new TableBlock(
172    Arrays.asList(new TableRowBlock(
173    Arrays.asList(new TableHeadCellBlock(
174    Arrays.asList(new BulletedListBlock(
175    Arrays.asList(new ListItemBlock(
176    Arrays.asList(new WordBlock("word")))))))))));
177  1 assertEquals("|=(((\n* word\n)))", render(block));
178    }
179   
 
180  1 toggle @Test
181    public void listItemWithInlineContentOnly()
182    {
183    // Use case: List in a list item
184  1 Block block = new BulletedListBlock(
185    Arrays.asList(new ListItemBlock(
186    Arrays.asList(new WordBlock("word1"), new BulletedListBlock(
187    Arrays.asList(new ListItemBlock(
188    Arrays.asList(new WordBlock("word2")))))))));
189  1 assertEquals("* word1\n** word2", render(block));
190   
191    // Use case: definition list in a list item
192  1 block = new BulletedListBlock(
193    Arrays.asList(new ListItemBlock(
194    Arrays.asList(new WordBlock("word1"), new DefinitionListBlock(
195    Arrays.asList(new DefinitionTermBlock(
196    Arrays.asList(new WordBlock("term"))),
197    new DefinitionDescriptionBlock(
198    Arrays.asList(new WordBlock("desc")))))))));
199  1 assertEquals("* word1\n*; term\n*: desc", render(block));
200   
201    // Use case: Newline in a list item
202    // New lines at the end of inline blocks are rendered as linebreaks in wiki syntax
203  1 block = new BulletedListBlock(
204    Arrays.asList(new ListItemBlock(
205    Arrays.asList(new WordBlock("word"), new NewLineBlock()))));
206  1 assertEquals("* word\\\\", render(block));
207    }
208   
 
209  1 toggle @Test
210    public void listItemWithStandaloneContent()
211    {
212    // Use case: Header in a list item
213  1 Block block = new BulletedListBlock(
214    Arrays.asList(new ListItemBlock(
215    Arrays.asList(new SectionBlock(
216    Arrays.asList(new HeaderBlock(
217    Arrays.asList(new WordBlock("heading")), HeaderLevel.LEVEL1)
218    ))))));
219  1 assertEquals("* (((\n= heading =\n)))", render(block));
220   
221    // Use case: Paragraph in a list item
222  1 block = new BulletedListBlock(
223    Arrays.asList(new ListItemBlock(
224    Arrays.asList(new ParagraphBlock(
225    Arrays.asList(new WordBlock("word")))))));
226  1 assertEquals("* (((\nword\n)))", render(block));
227   
228    // Use Case: Group in a list item
229    // Note: A GroupBlock is considered inline content
230  1 block = new BulletedListBlock(
231    Arrays.asList(new ListItemBlock(
232    Arrays.asList(new GroupBlock(
233    Arrays.asList(new WordBlock("word")))))));
234  1 assertEquals("* (((\nword\n)))", render(block));
235    }
236    }