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.html.HtmlElement;
06: import fitnesse.wiki.*;
07: import fitnesse.wikitext.widgets.WidgetRoot;
08: import junit.framework.TestCase;
09: import junit.swingui.TestRunner;
10:
11: public class WikiTextTranslatorTest extends TestCase {
12: private WikiPage root;
13: private WikiPage page;
14: private PageCrawler crawler;
15:
16: public static void main(String[] args) {
17: TestRunner
18: .main(new String[] { "fitnesse.wikitext.WikiTextTranslatorTest" });
19: }
20:
21: public void setUp() throws Exception {
22: root = InMemoryPage.makeRoot("RooT");
23: crawler = root.getPageCrawler();
24: page = crawler.addPage(root, PathParser.parse("WidgetRoot"));
25: }
26:
27: public void tearDown() throws Exception {
28: }
29:
30: public void testTranslation1() throws Exception {
31: String wikiText = "!c !1 This is a WidgetRoot\n" + "\n"
32: + "''' ''Some Bold and Italic text'' '''\n";
33: String html = "<div class=\"centered\"><h1>This is a <a href=\"WidgetRoot\">WidgetRoot</a></h1></div>"
34: + "<br>"
35: + "<b> <i>Some Bold and Italic text</i> </b><br>";
36: assertEquals(html, translate(wikiText, page));
37: }
38:
39: public void testHtmlEscape() throws Exception {
40: String wikiText = "<h1>this \"&\" that</h1>";
41: String html = "<h1>this \"&\" that</h1>";
42: assertEquals(html, translate(wikiText, new WikiPageDummy()));
43: }
44:
45: public void testTableHtml() throws Exception {
46: String wikiText = "|this|is|a|table|\n|that|has|four|columns|\n";
47: String html = "<table border=\"1\" cellspacing=\"0\">\n<tr><td>this</td>"
48: + HtmlElement.endl
49: + "<td>is</td>"
50: + HtmlElement.endl
51: + "<td>a</td>"
52: + HtmlElement.endl
53: + "<td>table</td>"
54: + HtmlElement.endl
55: + "</tr>\n"
56: + "<tr><td>that</td>"
57: + HtmlElement.endl
58: + "<td>has</td>"
59: + HtmlElement.endl
60: + "<td>four</td>"
61: + HtmlElement.endl
62: + "<td>columns</td>"
63: + HtmlElement.endl
64: + "</tr>\n</table>\n";
65: assertEquals(html, translate(wikiText, new WikiPageDummy()));
66: }
67:
68: private static String translate(String value, WikiPage source)
69: throws Exception {
70: WidgetRoot page = new WidgetRoot(value, source);
71: return page.render();
72: }
73: }
|