1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.wikimodel.test.xhtml

File XHtmlParserTest.java

 

Code metrics

0
101
22
1
719
558
22
0.22
4.59
22
1

Classes

Class Line # Actions
XHtmlParserTest 31 101 0% 22 0
1.0100%
 

Contributing tests

This file is covered by 20 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.wikimodel.test.xhtml;
21   
22    import org.xwiki.rendering.wikimodel.IWikiParser;
23    import org.xwiki.rendering.wikimodel.WikiParserException;
24    import org.xwiki.rendering.wikimodel.test.AbstractWikiParserTest;
25    import org.xwiki.rendering.wikimodel.xhtml.XhtmlParser;
26   
27    /**
28    * @version $Id: c1d7d26e9fd65b27caaea86caafc0a35fa416f83 $
29    * @since 4.0M1
30    */
 
31    public class XHtmlParserTest extends AbstractWikiParserTest
32    {
33    /**
34    * @param name
35    */
 
36  40 toggle public XHtmlParserTest(String name)
37    {
38  40 super(name);
39    }
40   
 
41  99 toggle @Override
42    protected IWikiParser newWikiParser()
43    {
44  99 return new XhtmlParser();
45    }
46   
47    /**
48    * @throws WikiParserException
49    */
 
50  1 toggle public void testDefinitionLists() throws WikiParserException
51    {
52  1 test("<html><dl><dt>term</dt><dd>definition</dd></dl></html>", ""
53    + "<dl>\n"
54    + " <dt>term</dt>\n"
55    + " <dd>definition</dd>\n"
56    + "</dl>");
57  1 test(
58    "<html><dl><dt>term1</dt><dt>term2</dt><dd>definition</dd></dl></html>",
59    ""
60    + "<dl>\n"
61    + " <dt>term1</dt>\n"
62    + " <dt>term2</dt>\n"
63    + " <dd>definition</dd>\n"
64    + "</dl>");
65  1 test("<html><dl><dt>term</dt><dd>definition<dl><dt>term</dt><dd>definition</dd></dl></dd></dl></html>",
66    "<dl>\n"
67    + " <dt>term</dt>\n"
68    + " <dd>definition<dl>\n"
69    + " <dt>term</dt>\n"
70    + " <dd>definition</dd>\n"
71    + "</dl>\n"
72    + "</dd>\n"
73    + "</dl>");
74    }
75   
76    /**
77    * @throws WikiParserException
78    */
 
79  1 toggle public void testDocuments() throws WikiParserException
80    {
81  1 test("<html><p>before</p>\n"
82    + "<div>\n"
83    + "<p>inside</p>\n"
84    + "</div>\n"
85    + "<p>after</p></html>", "<p>before</p>\n"
86    + "<div class='wikimodel-document'>\n"
87    + "<p>inside</p>\n"
88    + "</div>\n"
89    + "<p>after</p>");
90  1 test("<html><p>before</p>\n"
91    + "<div>\n"
92    + "<p>inside</p>\n"
93    + "</div>\n"
94    + "<p>after</p></html>", "<p>before</p>\n"
95    + "<div class='wikimodel-document'>\n"
96    + "<p>inside</p>\n"
97    + "</div>\n"
98    + "<p>after</p>");
99  1 test(
100    "<html><table><tbody>\n"
101    + " <tr><td> Line One </td><td> First doc:<div>\n"
102    + "<p>inside</p>\n"
103    + "</div>\n"
104    + "after</td></tr>\n"
105    + " <tr><td>Line Two</td><td>Second doc:<div>\n"
106    + "<p>lkjlj</p>\n"
107    + "</div>\n"
108    + "skdjg</td></tr>\n"
109    + "</tbody></table></html>",
110    "<table><tbody>\n"
111    + " <tr><td>Line One</td><td>First doc:<div class='wikimodel-document'>\n"
112    + "<p>inside</p>\n"
113    + "</div>\n"
114    + "after</td></tr>\n"
115    + " <tr><td>Line Two</td><td>Second doc:<div class='wikimodel-document'>\n"
116    + "<p>lkjlj</p>\n"
117    + "</div>\n"
118    + "skdjg</td></tr>\n"
119    + "</tbody></table>");
120  1 test(
121    "<html><table><tbody>\n"
122    + " <tr><td>This is a table:</td><td><div>\n"
123    + "<ul>\n"
124    + " <li>item one</li>\n"
125    + " <li>item two</li>\n"
126    + " <li>subitem 1</li>\n"
127    + " <li>subitem 2</li>\n"
128    + " <li>item three</li>\n"
129    + "</ul>\n"
130    + "</div>\n"
131    + "</td></tr>\n"
132    + "</tbody></table></html>",
133    "<table><tbody>\n"
134    + " <tr><td>This is a table:</td><td><div class='wikimodel-document'>\n"
135    + "<ul>\n"
136    + " <li>item one</li>\n"
137    + " <li>item two</li>\n"
138    + " <li>subitem 1</li>\n"
139    + " <li>subitem 2</li>\n"
140    + " <li>item three</li>\n"
141    + "</ul>\n"
142    + "</div>\n"
143    + "</td></tr>\n"
144    + "</tbody></table>");
145   
146  1 test("<html><p>before</p>\n"
147    + "<div>\n"
148    + "<p>opened and not closed</p>\n"
149    + "</div></html>", "<p>before</p>\n"
150    + "<div class='wikimodel-document'>\n"
151    + "<p>opened and not closed</p>\n"
152    + "</div>");
153  1 test("<html><p>before</p>\n"
154    + "<div>\n"
155    + "<p>one</p>\n"
156    + "<div>\n"
157    + "<p>two</p>\n"
158    + "<div>\n"
159    + "<p>three</p>\n"
160    + "</div>\n"
161    + "</div>\n"
162    + "</div></html>", "<p>before</p>\n"
163    + "<div class='wikimodel-document'>\n"
164    + "<p>one</p>\n"
165    + "<div class='wikimodel-document'>\n"
166    + "<p>two</p>\n"
167    + "<div class='wikimodel-document'>\n"
168    + "<p>three</p>\n"
169    + "</div>\n"
170    + "</div>\n"
171    + "</div>");
172   
173  1 test(
174    "<html><ul><li>Item 1<div><ul><li>Item 2</li></ul></div></li></ul></html>",
175    "<ul>\n"
176    + " <li>Item 1<div class='wikimodel-document'>\n"
177    + "<ul>\n"
178    + " <li>Item 2</li>\n"
179    + "</ul>\n"
180    + "</div>\n"
181    + "</li>\n"
182    + "</ul>");
183  1 test(
184    "<html><ul><li>Item 1<p>Before</p><ul><li>Item 2</li></ul><p>After</p></li></ul></html>",
185    "<ul>\n"
186    + " <li>Item 1<div class='wikimodel-document'>\n"
187    + "<p>Before</p>\n"
188    + "<ul>\n"
189    + " <li>Item 2</li>\n"
190    + "</ul>\n"
191    + "<p>After</p>\n"
192    + "</div>\n"
193    + "</li>\n"
194    + "</ul>");
195   
196  1 test("<html><div class='toto'>\n"
197    + "<p>inside</p>\n"
198    + "</div></html>",
199    "<div class='wikimodel-document' class='toto'>\n"
200    + "<p>inside</p>\n"
201    + "</div>");
202   
203  1 test("<html><ul><li><div>document</div><p>para</p></li></ul></html>",
204    "<ul>\n"
205    + " <li><div class='wikimodel-document'>\n"
206    + "<p>document</p>\n"
207    + "</div>\n"
208    + "<div class='wikimodel-document'>\n"
209    + "<p>para</p>\n"
210    + "</div>\n"
211    + "</li>\n"
212    + "</ul>");
213   
214    }
215   
216    /**
217    * @throws WikiParserException
218    */
 
219  1 toggle public void testEscape() throws WikiParserException
220    {
221    }
222   
223    /**
224    * @throws WikiParserException
225    */
 
226  1 toggle public void testFormats() throws WikiParserException
227    {
228  1 test("<html><b>bold</b></html>", "<p><strong>bold</strong></p>");
229  1 test(
230    "<html><strong>bold</strong></html>",
231    "<p><strong>bold</strong></p>");
232   
233  1 test("<html><s>strike</s></html>", "<p><strike>strike</strike></p>");
234  1 test(
235    "<html><strike>strike</strike></html>",
236    "<p><strike>strike</strike></p>");
237  1 test("<html><del>strike</del></html>", "<p><strike>strike</strike></p>");
238   
239  1 test("<html><em>italic</em></html>", "<p><em>italic</em></p>");
240   
241  1 test("<html><u>underline</u></html>", "<p><ins>underline</ins></p>");
242  1 test("<html><ins>underline</ins></html>", "<p><ins>underline</ins></p>");
243   
244  1 test("<html><sup>sup</sup></html>", "<p><sup>sup</sup></p>");
245  1 test("<html><sub>sub</sub></html>", "<p><sub>sub</sub></p>");
246   
247  1 test("<html><tt>mono</tt></html>", "<p><mono>mono</mono></p>");
248   
249  1 test(
250    "<html>a<strong><em>b</em></strong>c</html>",
251    "<p>a<strong><em>b</em></strong>c</p>");
252   
253  1 test("<html>a<em><em>b</em></em>c</html>", "<p>a<em>b</em>c</p>");
254  1 test(
255    "<html>a<em><strong><em>b</em></strong></em>c</html>",
256    "<p>a<em><strong>b</strong></em>c</p>");
257   
258  1 test(
259    "<html><p>12<strong>34<span param='value'>56</span>78</strong>90</p></html>",
260    "<p>12<strong>34</strong><strong><span class='wikimodel-parameters'[param='value']>56</span></strong><strong>78</strong>90</p>");
261   
262  1 test(
263    "<html><p><span param1='value1'><span param2='value2'>word</span></span></p></html>",
264    "<p><span class='wikimodel-parameters'[param1='value1', param2='value2']>word</span></p>");
265   
266    // merging
267   
268    // style
269   
270  1 test(
271    "<html><p><span param1='value1'><span param2='value2'>word</span></span></p></html>",
272    "<p><span class='wikimodel-parameters'[param1='value1', param2='value2']>word</span></p>");
273   
274  1 test(
275    "<html><p><span param1='value1'><strong param2='value2'>word</strong></span></p></html>",
276    "<p><strong><span class='wikimodel-parameters'[param1='value1', param2='value2']>word</span></strong></p>");
277   
278  1 test(
279    "<html><p><strong param1='value1'><span param2='value2'>word</span>word2</strong></p></html>",
280    "<p><strong><span class='wikimodel-parameters'[param1='value1', param2='value2']>word</span></strong>" +
281    "<strong><span class='wikimodel-parameters'[param1='value1']>word2</span></strong></p>");
282   
283  1 test(
284    "<html><p><span style='color: red;'><span style='background-color: yellow;'>word</span></span></p></html>",
285    "<p><span class='wikimodel-parameters'[style='color: red; background-color: yellow']>word</span></p>");
286   
287  1 test(
288    "<html><p><span style='color: red;'>word1<span style='background-color: yellow;'>word2</span></span></p></html>",
289    "<p><span class='wikimodel-parameters'[style='color: red;']>word1</span><span class='wikimodel-parameters'[style='color: red; background-color: yellow']>word2</span></p>");
290   
291  1 test(
292    "<html><p><span style='font-family: times new roman'>x<span style='font-family: arial black'>y</span>z</span></p></html>",
293    "<p><span class='wikimodel-parameters'[style='font-family: times new roman']>x</span>" +
294    "<span class='wikimodel-parameters'[style='font-family: times new roman; font-family: arial black']>y</span>" +
295    "<span class='wikimodel-parameters'[style='font-family: times new roman']>z</span></p>");
296   
297    // class
298   
299  1 test(
300    "<html><p><span class='class1'><span class='class2'>word</span></span></p></html>",
301    "<p><span class='wikimodel-parameters'[class='class1 class2']>word</span></p>");
302   
303  1 test(
304    "<html><p><span class='class1'>word1<span class='class2'>word2</span>word3</span></p></html>",
305    "<p><span class='wikimodel-parameters'[class='class1']>word1</span>" +
306    "<span class='wikimodel-parameters'[class='class1 class2']>word2</span>" +
307    "<span class='wikimodel-parameters'[class='class1']>word3</span></p>");
308    }
309   
310    /**
311    * @throws WikiParserException
312    */
 
313  1 toggle public void testHeaders() throws WikiParserException
314    {
315  1 test("<html><h1>header1</h1></html>");
316  1 test("<html><h2>header2</h2></html>");
317  1 test("<html><h3>header3</h3></html>");
318  1 test("<html><h4>header4</h4></html>");
319  1 test("<html><h5>header5</h5></html>");
320  1 test("<html><h6>header6</h6></html>");
321   
322  1 test("<html>before<h1>header1</h1>after</html>");
323    }
324   
325    /**
326    * @throws WikiParserException
327    */
 
328  1 toggle public void testHorLine() throws WikiParserException
329    {
330  1 test("<html>before<hr />after</html>", ""
331    + "<p>before</p>\n"
332    + "<hr />\n"
333    + "<p>after</p>");
334  1 test("<html><hr a='b' /></html>", "<hr a='b' />");
335    }
336   
 
337  1 toggle public void testImages() throws WikiParserException
338    {
339  1 test(
340    "<html><img src=\"target\" alt=\"some description\"/></html>",
341    "<p><img src='target' title='some description'/></p>");
342   
343  1 test(
344    "<html><img src=\"target\" alt=\"some description\" class=\"wikimodel-freestanding\" param1=\"value1\"/></html>",
345    "<p><img src='target' param1='value1' title='some description'/></p>");
346   
347  1 test(
348    "<html><img src=\"target\" alt=\"some description\" class=\"wikimodel-freestanding\"/></html>",
349    "<p><img src='target' class='wikimodel-freestanding'/></p>");
350    }
351   
352    /**
353    * @throws WikiParserException
354    */
 
355  1 toggle public void testLineBreak() throws WikiParserException
356    {
357  1 test("<html>before<br />after</html>", "<p>before\nafter</p>");
358    }
359   
360    /**
361    * @throws WikiParserException
362    */
 
363  1 toggle public void testLists() throws WikiParserException
364    {
365  1 test(
366    "<html><ul><li>a<ul><li>b</li></ul></li><li>c</li></ul></html>",
367    ""
368    + "<ul>\n"
369    + " <li>a<ul>\n"
370    + " <li>b</li>\n"
371    + "</ul>\n"
372    + "</li>\n"
373    + " <li>c</li>\n"
374    + "</ul>");
375   
376  1 test("<html><ul>"
377    + "<li>item one</li>"
378    + "<li>before<hr />after</li>"
379    + "</ul></html>");
380  1 test("<html><ul>"
381    + "<li>item one</li>"
382    + "<li>before"
383    + " <ul>"
384    + " <li>item one</li>"
385    + " </ul>"
386    + "after</li>"
387    + "</ul></html>");
388   
389  1 test("<html><ol><li>Item 1<ol><li>Item 2<ul class=\"star\"><li>Item\r\n"
390    + "3</li></ul></li><li>Item 4</li></ol></li><li>Item 5</li></ol><ul\r\n"
391    + "class=\"star\"><li>Item 1<ul class=\"star\"><li>Item 2<ul class=\"star\"><li>Item\r\n"
392    + "3</li></ul></li><li>Item 4</li></ul></li><li>Item 5</li><li>Item\r\n"
393    + "6</li></ul></html>\r\n"
394    + "");
395   
396  1 test(
397    "<html><ol><li>item one<ul><li>item two</li></ul></li></ol></html>",
398    "<ol>\n"
399    + " <li>item one<ul>\n"
400    + " <li>item two</li>\n"
401    + "</ul>\n"
402    + "</li>\n"
403    + "</ol>");
404    }
405   
406    /**
407    * @throws WikiParserException
408    */
 
409  1 toggle public void testParagraphs() throws WikiParserException
410    {
411  1 test("<html><p>paragraph</p></html>", "<p>paragraph</p>");
412  1 test(
413    "<p>hello <em class=\"italic\">beautiful</em> <strong>world</strong></p>",
414    "<p>hello <em><span class='wikimodel-parameters'[class='italic']>beautiful</span></em> <strong>world</strong></p>");
415    }
416   
417    /**
418    * @throws WikiParserException
419    */
 
420  1 toggle public void testQuot() throws WikiParserException
421    {
422  1 test(
423    "<html><blockquote>quote</blockquote></html>",
424    "<blockquote>\nquote\n</blockquote>");
425  1 test(
426    "<html><blockquote>line1<blockquote>line2<blockquote>line3</blockquote>"
427    + "line4</blockquote></blockquote></html>",
428    "<blockquote>\nline1<blockquote>\nline2<blockquote>\nline3\n</blockquote>"
429    + "\n\nline4\n</blockquote>\n\n</blockquote>");
430   
431  1 test(
432    "<html><blockquote><p>quote</p></blockquote></html>",
433    "<blockquote>\nquote\n</blockquote>");
434  1 test(
435    "<html><blockquote><p>line1</p><blockquote><p>line2</p><blockquote><p>line3</p></blockquote>"
436    + "<p>line4</p></blockquote></blockquote></html>",
437    "<blockquote>\nline1<blockquote>\nline2<blockquote>\nline3\n</blockquote>"
438    + "\n\nline4\n</blockquote>\n\n</blockquote>");
439   
440  1 test(
441    "<html><blockquote><span param='vale'>line1<br/>line2</span></blockquote></html>",
442    "<blockquote>\n" +
443    "<span class='wikimodel-parameters'[param='vale']>line1</span>\n" +
444    "<span class='wikimodel-parameters'[param='vale']>line2</span>\n" +
445    "</blockquote>");
446   
447  1 test(
448    "<html><blockquote><span param1='value1'><span param2='vale2'>line1<br/>line2</span></span></blockquote></html>",
449    "<blockquote>\n" +
450    "<span class='wikimodel-parameters'[param1='value1', param2='vale2']>line1</span>\n" +
451    "<span class='wikimodel-parameters'[param1='value1', param2='vale2']>line2</span>\n" +
452    "</blockquote>");
453    }
454   
455    /**
456    * @throws WikiParserException
457    */
 
458  1 toggle public void testReferences() throws WikiParserException
459    {
460  1 test("<html><a href=\"reference\">label</a></html>", "<p><a href='reference'>label</a></p>");
461  1 test("<html><a href=\"reference\" param=\"value\">label</a></html>",
462    "<p><a href='reference' param='value'>label</a></p>");
463  1 test("<html><a href=\"reference\" class=\"wikimodel-freestanding\" param=\"value\">label</a></html>",
464    "<p><a href='reference' param='value'>label</a></p>");
465  1 test("<html><a href=\"reference\" class=\"wikimodel-freestanding\">label</a></html>",
466    "<p><a href='reference' class='wikimodel-freestanding'>reference</a></p>");
467  1 test("<html><a href='#foo'>test</a></html>", "<p><a href='#foo'>test</a></p>");
468    }
469   
470    /**
471    * @throws WikiParserException
472    */
 
473  1 toggle public void testTables() throws WikiParserException
474    {
475  1 test("<html><table><tr><td>first cell</td><td>second cell</td></tr></table></html>",
476    "<table><tbody>\n"
477    + " <tr><td>first cell</td><td>second cell</td></tr>\n"
478    + "</tbody></table>");
479  1 test("<html><table><tr><td>first cell</td></tr></table></html>",
480    "<table><tbody>\n"
481    + " <tr><td>first cell</td></tr>\n"
482    + "</tbody></table>");
483  1 test("<html><table>"
484    + "<tr><th>first header</th><th>second header</th></tr>"
485    + "<tr><td>first cell</td><td>second cell</td></tr>"
486    + "</table></html>",
487    "<table><tbody>\n"
488    + " <tr><th>first header</th><th>second header</th></tr>\n"
489    + " <tr><td>first cell</td><td>second cell</td></tr>\n"
490    + "</tbody></table>");
491  1 test("<html><table>"
492    + "<tr><th>first row</th><td>first cell</td></tr>"
493    + "<tr><th>second row</th><td>before <table><tr><td>first cell</td></tr></table> after</td></tr>"
494    + "<tr><th>third row</th><td>third cell</td></tr>"
495    + "</table></html>",
496    "<table><tbody>\n"
497    + " <tr><th>first row</th><td>first cell</td></tr>\n"
498    + " <tr><th>second row</th><td>before<div class='wikimodel-document'>\n"
499    + "<table><tbody>\n"
500    + " <tr><td>first cell</td></tr>\n"
501    + "</tbody></table>\n"
502    + "<p>after</p>\n"
503    + "</div>\n"
504    + "</td></tr>\n"
505    + " <tr><th>third row</th><td>third cell</td></tr>\n"
506    + "</tbody></table>");
507   
508    // Automatic sub document
509   
510  1 test("<html><table><tr><td><p>text</p></td></tr></table></html>",
511    "<table><tbody>\n"
512    + " <tr><td><div class='wikimodel-document'>\n"
513    + "<p>text</p>\n"
514    + "</div>\n"
515    + "</td></tr>\n"
516    + "</tbody></table>");
517   
518  1 test("<html><table><tr><td><div class='wikimodel-emptyline'/><p>text</p></td></tr></table></html>",
519    "<table><tbody>\n"
520    + " <tr><td><div class='wikimodel-document'>\n"
521    + "<p>text</p>\n"
522    + "</div>\n"
523    + "</td></tr>\n"
524    + "</tbody></table>");
525   
526    // "Bad-formed" tables...
527   
528    // The content is completely ignored.
529  1 test("<html><table>first cell</table></html>", "<table><tbody>\n</tbody></table>");
530   
531    // A "td" element directly in the table
532  1 test("<html><table><td>first cell</td></table></html>", "<table><tbody>\n"
533    + " <tr><td>first cell</td></tr>\n"
534    + "</tbody></table>");
535   
536    // Not a table at all
537  1 test("<html><td>first cell</td></html>", "<table><tbody>\n"
538    + " <tr><td>first cell</td></tr>\n"
539    + "</tbody></table>");
540   
541  1 test("<table><tr><td><tt class=\"wikimodel-verbatim\">x</tt></td><td><tt>y</tt></td></tr></table>",
542    "<table><tbody>\n"
543    + " <tr><td><tt class=\"wikimodel-verbatim\">x</tt></td><td><mono>y</mono></td></tr>\n"
544    + "</tbody></table>");
545    }
546   
547    /**
548    * @throws WikiParserException
549    */
 
550  1 toggle public void testVerbatimBlocks() throws WikiParserException
551    {
552  1 test(
553    "<html><pre>one\ntwo</pre></html>",
554    "<pre>one\ntwo</pre>");
555  1 test(
556    "<html><pre>one<br/>two</pre></html>",
557    "<pre>one\ntwo</pre>");
558  1 test(
559    "<html><pre><b>one</b><br/>two</pre></html>",
560    "<pre>one\ntwo</pre>");
561    }
562   
563    /**
564    * @throws WikiParserException
565    */
 
566  1 toggle public void testVerbatimInline() throws WikiParserException
567    {
568  1 test(
569    "<html><p><tt class=\"wikimodel-verbatim\">one\ntwo</tt></p></html>",
570    "<p><tt class=\"wikimodel-verbatim\">one\ntwo</tt></p>");
571  1 test(
572    "<html><p><tt class=\"wikimodel-verbatim\">one<br/>two</tt></p></html>",
573    "<p><tt class=\"wikimodel-verbatim\">one\ntwo</tt></p>");
574  1 test(
575    "<html><p><tt class=\"wikimodel-verbatim\"><b>one</b><br/>two</tt></p></html>",
576    "<p><tt class=\"wikimodel-verbatim\">one\ntwo</tt></p>");
577    }
578   
 
579  1 toggle public void testMacro() throws WikiParserException
580    {
581  1 test(
582    "<html><!--startmacro:name|-|param=\"value\"|-|content--><!--stopmacro--></html>",
583    "<pre class='wikimodel-macro' macroName='name' param='value'><![CDATA[content]]></pre>");
584  1 test(
585    "<html><!--startmacro:name|-|title=\"value\"-->macro<!--stopmacro--></html>",
586    "<pre class='wikimodel-macro' macroName='name' title='value'/>");
587   
588  1 test(
589    "<html><!--startmacro:name|-|param=\"va|-|lue\"|-|content-->macro<!--stopmacro--></html>",
590    "<pre class='wikimodel-macro' macroName='name' param='va|-|lue'><![CDATA[content]]></pre>");
591  1 test(
592    "<html><!--startmacro:name|-|title=\"va|-|lue\"-->macro<!--stopmacro--></html>",
593    "<pre class='wikimodel-macro' macroName='name' title='va|-|lue'/>");
594  1 test(
595    "<html><!--startmacro:name|-|param=\"value\"|-|content--><!--startmacro:subname|-|subparam=\"subvalue\"|-|subcontent--><!--stopmacro--><!--stopmacro--></html>",
596    "<pre class='wikimodel-macro' macroName='name' param='value'><![CDATA[content]]></pre>");
597    }
598   
 
599  1 toggle public void testMisc() throws WikiParserException
600    {
601  1 test(
602    "<html><p><a name=\"foo\">bar</a></p></html>",
603    "<p></p>");
604  1 test(
605    "<html><p><a id=\"foo\">bar</a></p></html>",
606    "<p></p>");
607    }
608   
609    /**
610    * Test that unsupported tags, like HTML5 ones, are simply ignored
611    * @throws WikiParserException
612    */
 
613  1 toggle public void testUnsupportedTags() throws WikiParserException
614    {
615  1 test("<html>This is <unsupported>tags</unsupported> ignored</html>",
616    "<p>This is tags ignored</p>");
617   
618  1 test("<html><dl><dt>term</dt><dd>definition<unsupported><dl><dt>term</dt><dd>definition</dd></dl></unsupported></dd></dl></html>",
619    "<dl>\n"
620    + " <dt>term</dt>\n"
621    + " <dd>definition<dl>\n"
622    + " <dt>term</dt>\n"
623    + " <dd>definition</dd>\n"
624    + "</dl>\n"
625    + "</dd>\n"
626    + "</dl>");
627   
628  1 test(
629    "<html><ul><li>a<unsupported><ul><li>b</li></ul></unsupported></li></ul></html>",
630    ""
631    + "<ul>\n"
632    + " <li>a<ul>\n"
633    + " <li>b</li>\n"
634    + "</ul>\n"
635    + "</li>\n"
636    + "</ul>");
637   
638  1 test(
639    "<html><blockquote>line1<unsupported><blockquote>line2<blockquote>line3</blockquote>"
640    + "line4</blockquote></unsupported></blockquote></html>",
641    "<blockquote>\nline1<blockquote>\nline2<blockquote>\nline3\n</blockquote>"
642    + "\n\nline4\n</blockquote>\n\n</blockquote>");
643    }
644   
645    /**
646    * Test malformed constructs created by the HTML cleaner not supporting HTML5
647    * @throws WikiParserException
648    */
 
649  1 toggle public void testUnsupportedHTML5Tags() throws WikiParserException
650    {
651  1 test(
652    "<html><p><section><p>test</p></section></p></html>",
653    "<p></p>\n"
654    + "<div class='wikimodel-document'>\n"
655    + "<p>test</p>\n"
656    + "</div>");
657  1 test(
658    "<html><p><header><h1>test</h1></header></p></html>",
659    "<p></p>\n"
660    + "<div class='wikimodel-document'>\n"
661    + "<h1>test</h1>\n"
662    + "</div>");
663   
664  1 test(
665    "<html><p><header><h1>test</h1></header></p></html>",
666    "<p></p>\n"
667    + "<div class='wikimodel-document'>\n"
668    + "<h1>test</h1>\n"
669    + "</div>");
670    }
671   
672    /**
673    * Test basic HTML5 support.
674    * While invalid in XHTML 1.0, if these tags ever appear in the submitted content, it could cause some text nodes
675    * to be merged, which is usually not nice from an end user POV. Therefore Wikimodel provide some minimal support
676    * for them, by considering those tags as simple divs.
677    * @throws WikiParserException
678    */
 
679  1 toggle public void testBasicHTML5Tags() throws WikiParserException
680    {
681  1 test(
682    "<html><header>Header<nav>Navigation</nav></header><main><article><section><h1>section 1</h1><summary>Summary 1</summary><details>Text 1<figure><img src='target'/><figcaption>caption</figcaption></figure></details><aside>Aside</aside></section><section><h1>section 2</h1><p>text 2</p></section></article></main><footer>Footer</footer></html>",
683    "<div class='wikimodel-document'>\n"
684    + "<p>Header</p>\n"
685    + "<div class='wikimodel-document'>\n"
686    + "<p>Navigation</p>\n"
687    + "</div>\n"
688    + "</div>\n"
689    + "<div class='wikimodel-document'>\n"
690    + "<div class='wikimodel-document'>\n"
691    + "<div class='wikimodel-document'>\n"
692    + "<h1>section 1</h1>\n"
693    + "<div class='wikimodel-document'>\n"
694    + "<p>Summary 1</p>\n"
695    + "</div>\n"
696    + "<div class='wikimodel-document'>\n"
697    + "<p>Text 1</p>\n"
698    + "<div class='wikimodel-document'>\n"
699    + "<p><img src='target'/></p>\n"
700    + "<div class='wikimodel-document'>\n"
701    + "<p>caption</p>\n"
702    + "</div>\n"
703    + "</div>\n"
704    + "</div>\n"
705    + "<div class='wikimodel-document'>\n"
706    + "<p>Aside</p>\n"
707    + "</div>\n"
708    + "</div>\n"
709    + "<div class='wikimodel-document'>\n"
710    + "<h1>section 2</h1>\n"
711    + "<p>text 2</p>\n"
712    + "</div>\n"
713    + "</div>\n"
714    + "</div>\n"
715    + "<div class='wikimodel-document'>\n"
716    + "<p>Footer</p>\n"
717    + "</div>");
718    }
719    }