001: /*
002: * (C) Janne Jalkanen 2005
003: *
004: */
005: package com.ecyrd.jspwiki.plugin;
006:
007: import java.util.Properties;
008:
009: import com.ecyrd.jspwiki.TestEngine;
010:
011: import junit.framework.Test;
012: import junit.framework.TestCase;
013: import junit.framework.TestSuite;
014:
015: /**
016: * @author jalkanen
017: *
018: * @since
019: */
020: public class TableOfContentsTest extends TestCase {
021: TestEngine testEngine;
022:
023: /*
024: * @see TestCase#setUp()
025: */
026: protected void setUp() throws Exception {
027: super .setUp();
028:
029: Properties props = new Properties();
030:
031: props.load(TestEngine.findTestProperties());
032:
033: testEngine = new TestEngine(props);
034: }
035:
036: /*
037: * @see TestCase#tearDown()
038: */
039: protected void tearDown() throws Exception {
040: super .tearDown();
041:
042: testEngine.deletePage("Test");
043: }
044:
045: public void testHeadingVariables() throws Exception {
046: String src = "[{SET foo=bar}]\n\n[{TableOfContents}]\n\n!!!Heading [{$foo}]";
047:
048: testEngine.saveText("Test", src);
049:
050: String res = testEngine.getHTML("Test");
051:
052: // FIXME: The <p> should not be here.
053: assertEquals(
054: "<p><div class=\"toc\">\n<div class=\"collapsebox\">\n"
055: + "<h4>Table of Contents</h4>\n"
056: + "<ul>\n"
057: + "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-HeadingBar\">Heading bar</a></li>\n"
058: + "</ul>\n</div>\n</div>\n\n</p>"
059: + "\n<h2 id=\"section-Test-HeadingBar\">Heading bar</h2>\n",
060: res);
061: }
062:
063: public void testNumberedItems() throws Exception {
064: String src = "[{SET foo=bar}]\n\n[{INSERT TableOfContents WHERE numbered=true,start=3}]\n\n!!!Heading [{$foo}]\n\n!!Subheading\n\n!Subsubheading";
065:
066: testEngine.saveText("Test", src);
067:
068: String res = testEngine.getHTML("Test");
069:
070: // FIXME: The <p> should not be here.
071: String expecting = "<p><div class=\"toc\">\n<div class=\"collapsebox\">\n"
072: + "<h4>Table of Contents</h4>\n"
073: + "<ul>\n"
074: + "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-HeadingBar\">3 Heading bar</a></li>\n"
075: + "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading\">3.1 Subheading</a></li>\n"
076: + "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading\">3.1.1 Subsubheading</a></li>\n"
077: + "</ul>\n</div>\n</div>\n\n</p>"
078: + "\n<h2 id=\"section-Test-HeadingBar\">Heading bar</h2>"
079: + "\n<h3 id=\"section-Test-Subheading\">Subheading</h3>"
080: + "\n<h4 id=\"section-Test-Subsubheading\">Subsubheading</h4>\n";
081:
082: assertEquals(expecting, res);
083: }
084:
085: public void testNumberedItemsComplex() throws Exception {
086: String src = "[{SET foo=bar}]\n\n[{INSERT TableOfContents WHERE numbered=true,start=3}]\n\n!!!Heading [{$foo}]\n\n!!Subheading\n\n!Subsubheading\n\n!Subsubheading2\n\n!!Subheading2\n\n!Subsubheading3\n\n!!!Heading\n\n!!Subheading3";
087:
088: testEngine.saveText("Test", src);
089:
090: String res = testEngine.getHTML("Test");
091:
092: // FIXME: The <p> should not be here.
093: String expecting = "<p><div class=\"toc\">\n<div class=\"collapsebox\">\n"
094: + "<h4>Table of Contents</h4>\n"
095: + "<ul>\n"
096: + "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-HeadingBar\">3 Heading bar</a></li>\n"
097: + "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading\">3.1 Subheading</a></li>\n"
098: + "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading\">3.1.1 Subsubheading</a></li>\n"
099: + "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading2\">3.1.2 Subsubheading2</a></li>\n"
100: + "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading2\">3.2 Subheading2</a></li>\n"
101: + "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading3\">3.2.1 Subsubheading3</a></li>\n"
102: + "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Heading\">4 Heading</a></li>\n"
103: + "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading3\">4.1 Subheading3</a></li>\n"
104: + "</ul>\n</div>\n</div>\n\n</p>"
105: + "\n<h2 id=\"section-Test-HeadingBar\">Heading bar</h2>"
106: + "\n<h3 id=\"section-Test-Subheading\">Subheading</h3>"
107: + "\n<h4 id=\"section-Test-Subsubheading\">Subsubheading</h4>"
108: + "\n<h4 id=\"section-Test-Subsubheading2\">Subsubheading2</h4>"
109: + "\n<h3 id=\"section-Test-Subheading2\">Subheading2</h3>"
110: + "\n<h4 id=\"section-Test-Subsubheading3\">Subsubheading3</h4>"
111: + "\n<h2 id=\"section-Test-Heading\">Heading</h2>"
112: + "\n<h3 id=\"section-Test-Subheading3\">Subheading3</h3>\n";
113:
114: assertEquals(expecting, res);
115: }
116:
117: public void testNumberedItemsComplex2() throws Exception {
118: String src = "[{SET foo=bar}]\n\n[{INSERT TableOfContents WHERE numbered=true,start=3}]\n\n!!Subheading0\n\n!!!Heading [{$foo}]\n\n!!Subheading\n\n!Subsubheading\n\n!Subsubheading2\n\n!!Subheading2\n\n!Subsubheading3\n\n!!!Heading\n\n!!Subheading3";
119:
120: testEngine.saveText("Test", src);
121:
122: String res = testEngine.getHTML("Test");
123:
124: // FIXME: The <p> should not be here.
125: String expecting = "<p><div class=\"toc\">\n<div class=\"collapsebox\">\n"
126: + "<h4>Table of Contents</h4>\n"
127: + "<ul>\n"
128: + "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading0\">3.1 Subheading0</a></li>\n"
129: + "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-HeadingBar\">4 Heading bar</a></li>\n"
130: + "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading\">4.1 Subheading</a></li>\n"
131: + "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading\">4.1.1 Subsubheading</a></li>\n"
132: + "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading2\">4.1.2 Subsubheading2</a></li>\n"
133: + "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading2\">4.2 Subheading2</a></li>\n"
134: + "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading3\">4.2.1 Subsubheading3</a></li>\n"
135: + "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Heading\">5 Heading</a></li>\n"
136: + "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading3\">5.1 Subheading3</a></li>\n"
137: + "</ul>\n</div>\n</div>\n\n</p>"
138: + "\n<h3 id=\"section-Test-Subheading0\">Subheading0</h3>"
139: + "\n<h2 id=\"section-Test-HeadingBar\">Heading bar</h2>"
140: + "\n<h3 id=\"section-Test-Subheading\">Subheading</h3>"
141: + "\n<h4 id=\"section-Test-Subsubheading\">Subsubheading</h4>"
142: + "\n<h4 id=\"section-Test-Subsubheading2\">Subsubheading2</h4>"
143: + "\n<h3 id=\"section-Test-Subheading2\">Subheading2</h3>"
144: + "\n<h4 id=\"section-Test-Subsubheading3\">Subsubheading3</h4>"
145: + "\n<h2 id=\"section-Test-Heading\">Heading</h2>"
146: + "\n<h3 id=\"section-Test-Subheading3\">Subheading3</h3>\n";
147:
148: assertEquals(expecting, res);
149: }
150:
151: public void testNumberedItemsWithPrefix() throws Exception {
152: String src = "[{SET foo=bar}]\n\n[{INSERT TableOfContents WHERE numbered=true,start=3,prefix=FooBar-}]\n\n!!!Heading [{$foo}]\n\n!!Subheading\n\n!Subsubheading";
153:
154: testEngine.saveText("Test", src);
155:
156: String res = testEngine.getHTML("Test");
157:
158: // FIXME: The <p> should not be here.
159: String expecting = "<p><div class=\"toc\">\n<div class=\"collapsebox\">\n"
160: + "<h4>Table of Contents</h4>\n"
161: + "<ul>\n"
162: + "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-HeadingBar\">FooBar-3 Heading bar</a></li>\n"
163: + "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading\">FooBar-3.1 Subheading</a></li>\n"
164: + "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading\">FooBar-3.1.1 Subsubheading</a></li>\n"
165: + "</ul>\n</div>\n</div>\n\n</p>"
166: + "\n<h2 id=\"section-Test-HeadingBar\">Heading bar</h2>"
167: + "\n<h3 id=\"section-Test-Subheading\">Subheading</h3>"
168: + "\n<h4 id=\"section-Test-Subsubheading\">Subsubheading</h4>\n";
169:
170: assertEquals(expecting, res);
171: }
172:
173: /**
174: * Tests BugTableOfContentsCausesHeapdump
175: *
176: * @throws Exception
177: */
178: public void testSelfReference() throws Exception {
179: String src = "!!![{TableOfContents}]";
180:
181: testEngine.saveText("Test", src);
182:
183: String res = testEngine.getHTML("Test");
184:
185: assertTrue(res.indexOf("Table of Contents") != -1);
186: }
187:
188: public void testHTML() throws Exception {
189: String src = "[{TableOfContents}]\n\n!<i>test</i>";
190:
191: testEngine.saveText("Test", src);
192:
193: String res = testEngine.getHTML("Test");
194:
195: assertTrue("<i>", res.indexOf("<i>") == -1); // Check that there is no HTML left
196: assertTrue("</i>", res.indexOf("</i>") == -1); // Check that there is no HTML left
197:
198: }
199:
200: public static Test suite() {
201: return new TestSuite(TableOfContentsTest.class);
202: }
203:
204: }
|