01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wikitext;
04:
05: import fitnesse.wiki.*;
06: import fitnesse.wikitext.widgets.WidgetRoot;
07: import fitnesse.html.*;
08: import junit.framework.TestCase;
09: import junit.swingui.TestRunner;
10:
11: public class WikiTextTranslatorTest extends TestCase {
12: private WikiPage root;
13:
14: private WikiPage page;
15:
16: private PageCrawler crawler;
17:
18: public static void main(String[] args) {
19: TestRunner
20: .main(new String[] { "fitnesse.wikitext.WikiTextTranslatorTest" });
21: }
22:
23: public void setUp() throws Exception {
24: root = InMemoryPage.makeRoot("RooT");
25: crawler = root.getPageCrawler();
26: page = crawler.addPage(root, PathParser.parse("WidgetRoot"));
27: }
28:
29: public void tearDown() throws Exception {
30: }
31:
32: public void testTranslation1() throws Exception {
33: String wikiText = "!c !1 This is a WidgetRoot\n" + "\n"
34: + "''' ''Some Bold and Italic text'' '''\n";
35: String html = "<div class=\"centered\"><h1>This is a <a href=\"WidgetRoot\">WidgetRoot</a></h1></div>"
36: + HtmlUtil.BR
37: + "<b> <i>Some Bold and Italic text</i> </b>"
38: + HtmlUtil.BR;
39: assertEquals(html, translate(wikiText, page));
40: }
41:
42: public void testHtmlEscape() throws Exception {
43: String wikiText = "<h1>this \"&\" that</h1>";
44: String html = "<h1>this \"&\" that</h1>";
45: assertEquals(html, translate(wikiText, new MockWikiPage()));
46: }
47:
48: public void testTableHtml() throws Exception {
49: String wikiText = "|this|is|a|table|\n|that|has|four|columns|\n";
50: String html = "<table border=\"1\" cellspacing=\"0\" class=\"table-widget\">\n"
51: + "<colgroup>\n<col class=\"col-1\" />\n<col class=\"col-2\" />\n<col class=\"col-3\" />\n<col class=\"col-4\" />\n</colgroup>\n"
52: + "<tr><td class=\"column1\">this</td>"
53: + HtmlElement.endl
54: + "<td class=\"column2\">is</td>"
55: + HtmlElement.endl
56: + "<td class=\"column3\">a</td>"
57: + HtmlElement.endl
58: + "<td class=\"column4\">table</td>"
59: + HtmlElement.endl
60: + "</tr>\n"
61: + "<tr><td class=\"column1\">that</td>"
62: + HtmlElement.endl
63: + "<td class=\"column2\">has</td>"
64: + HtmlElement.endl
65: + "<td class=\"column3\">four</td>"
66: + HtmlElement.endl
67: + "<td class=\"column4\">columns</td>"
68: + HtmlElement.endl + "</tr>\n</table>\n";
69: assertEquals(html, translate(wikiText, new MockWikiPage()));
70: }
71:
72: private static String translate(String value, WikiPage source)
73: throws Exception {
74: WidgetRoot page = new WidgetRoot(value, source);
75: return page.render();
76: }
77: }
|