001: //Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002: //Released under the terms of the GNU General Public License version 2 or later.
003: package fitnesse.wikitext.widgets;
004:
005: import fitnesse.wiki.InMemoryPage;
006: import fitnesse.wiki.PageCrawler;
007: import fitnesse.wiki.PageData;
008: import fitnesse.wiki.PathParser;
009: import fitnesse.wiki.WikiPage;
010:
011: public class CommentAggregatorWidgetTest extends AbstractWidget {
012: private static final String commentWithMarkup = "| comment |'''\"Obfuscated Text\" comment'''||\n";
013:
014: private static final String commentWithMarkupRendered = "<b>\"Obfuscated Text\" comment</b>";
015:
016: private static final String commentTextOnly = "| comment | Normal stuff ||\n";
017:
018: private static final String commentTextOnlyRendered = "Normal stuff";
019:
020: private static final String rowWithoutComment = "| nocomment | not a comment ||\n";
021:
022: private static final String rowWithoutCommentNotRendered = "not a comment";
023:
024: private static final String contentWithoutTable = "just some stuff";
025:
026: private static final String commentVarValue = "comment substituted with variable";
027:
028: private static final String commentWithVariable = "| comment |${var1}||\n";
029:
030: private static final String commentWithVariableRendered = commentVarValue;
031:
032: private static final String titleRowTextRendered = "This is the first row of a test table";
033:
034: private static final String titleRowText = "| "
035: + titleRowTextRendered + " |\n";
036:
037: private static final String titleRowTextTwoRendered = "Second Title";
038:
039: private static final String titleRowTextTwo = "| "
040: + titleRowTextTwoRendered + " |\n";
041:
042: private static final String titleRowBlankText = "| |\n";
043:
044: private WikiPage root;
045:
046: private WikiPage parent;
047:
048: private WikiPage parentWithVar;
049:
050: private PageCrawler crawler;
051:
052: public void setUp() throws Exception {
053: root = InMemoryPage.makeRoot("RooT");
054: crawler = root.getPageCrawler();
055: // 2 parent pages at the root
056: parent = crawler.addPage(root, PathParser.parse("ParentOne"),
057: "parent 1");
058: parentWithVar = crawler.addPage(root, PathParser
059: .parse("ParentWithVar"), "!define var1 {"
060: + commentVarValue + "}");
061: crawler
062: .addPage(root, PathParser.parse("ParentTwo"),
063: "parent 2");
064: }
065:
066: public void testContainsClassNames() throws Exception {
067: setSTIQTestProperty(crawler
068: .addPage(parentWithVar, PathParser
069: .parse("ChildComments"), titleRowText
070: + commentTextOnly));
071: CommentAggregatorWidget widget = new CommentAggregatorWidget(
072: new WidgetRoot(parentWithVar), "!STIQcomments\n");
073: assertTrue(widget.render(), widget.render().indexOf(
074: "id=\"" + CommentAggregatorWidget.AGGREGATE_DIV_ID
075: + "\"") != -1);
076: assertTrue(widget.render(), widget.render().indexOf(
077: "class=\"" + CommentAggregatorWidget.TEST_COMMENT_CLASS
078: + "\"") != -1);
079: assertTrue(widget.render(), widget.render().indexOf(
080: "class=\"" + CommentAggregatorWidget.TEST_LINK_CLASS
081: + "\"") != -1);
082: assertTrue(widget.render(), widget.render().indexOf(
083: "class=\"" + CommentAggregatorWidget.TEST_TITLE_CLASS
084: + "\"") != -1);
085: assertTrue(widget.render(), widget.render().indexOf(
086: "class=\""
087: + CommentAggregatorWidget.TEST_TITLE_CELL_CLASS
088: + "\"") != -1);
089: }
090:
091: public void testDivIsCollapsable() throws Exception {
092: setSTIQTestProperty(crawler
093: .addPage(parentWithVar, PathParser
094: .parse("ChildComments"), titleRowText
095: + commentTextOnly));
096: CommentAggregatorWidget widget = new CommentAggregatorWidget(
097: new WidgetRoot(parentWithVar), "!STIQcomments\n");
098: assertTrue(widget.render(), widget.render().indexOf(
099: "class=\"collapse_rim\"") != -1);
100: assertTrue(widget.render(), widget.render().indexOf(
101: "class=\"hidden\"") != -1);
102: }
103:
104: public void testContainsTitle() throws Exception {
105: setSTIQTestProperty(crawler
106: .addPage(parentWithVar, PathParser
107: .parse("ChildComments"), titleRowText
108: + commentTextOnly));
109: setSTIQTestProperty(crawler.addPage(parentWithVar, PathParser
110: .parse("ChildWithOnlyTitle"), titleRowTextTwo));
111: setSTIQTestProperty(crawler.addPage(parentWithVar, PathParser
112: .parse("ChildWithBlankTitle"), titleRowBlankText));
113: CommentAggregatorWidget widget = new CommentAggregatorWidget(
114: new WidgetRoot(parentWithVar), "!STIQcomments\n");
115: assertTrue(widget.render(), widget.render().indexOf(
116: titleRowTextRendered) != -1);
117: assertTrue(widget.render(), widget.render().indexOf(
118: "colspan=\"3\">") == -1);
119: assertTrue(widget.render(), widget.render().indexOf(
120: titleRowTextTwoRendered) != -1);
121: }
122:
123: public void testContainsPageLinkRow() throws Exception {
124: setSTIQTestProperty(crawler.addPage(parentWithVar, PathParser
125: .parse("ChildComments"), commentWithVariable));
126: CommentAggregatorWidget widget = new CommentAggregatorWidget(
127: new WidgetRoot(parentWithVar), "!STIQcomments\n");
128: assertTrue(widget.render(), widget.render().indexOf(
129: "href=\"ParentWithVar.ChildComments\"") != -1);
130: }
131:
132: public void testContainsPageName() throws Exception {
133: setSTIQTestProperty(crawler.addPage(parentWithVar, PathParser
134: .parse("ChildComments"), commentWithVariable));
135: CommentAggregatorWidget widget = new CommentAggregatorWidget(
136: new WidgetRoot(parentWithVar), "!STIQcomments\n");
137: assertTrue(widget.render(), widget.render().indexOf(
138: "ChildComments") != -1);
139: }
140:
141: public void testOneCommentWithVariable() throws Exception {
142: setSTIQTestProperty(crawler.addPage(parentWithVar, PathParser
143: .parse("ChildComments"), commentWithVariable));
144: CommentAggregatorWidget widget = new CommentAggregatorWidget(
145: new WidgetRoot(parentWithVar), "!STIQcomments\n");
146: assertTrue(widget.render(), widget.render().indexOf(
147: commentWithVariableRendered) != -1);
148: }
149:
150: public void testOneCommentWithMarkup() throws Exception {
151: setSTIQTestProperty(crawler.addPage(parent, PathParser
152: .parse("ChildComments"), commentWithMarkup));
153: CommentAggregatorWidget widget = new CommentAggregatorWidget(
154: new WidgetRoot(parent), "!STIQcomments\n");
155: assertTrue(widget.render(), widget.render().indexOf(
156: commentWithMarkupRendered) != -1);
157: }
158:
159: public void testOneCommentTextOnly() throws Exception {
160: setSTIQTestProperty(crawler.addPage(parent, PathParser
161: .parse("ChildComments"), commentTextOnly));
162: CommentAggregatorWidget widget = new CommentAggregatorWidget(
163: new WidgetRoot(parent), "!STIQcomments\n");
164: assertTrue(widget.render(), widget.render().indexOf(
165: commentTextOnlyRendered) != -1);
166: }
167:
168: public void testContentWithoutTable() throws Exception {
169: setSTIQTestProperty(crawler.addPage(parent, PathParser
170: .parse("ChildComments"), contentWithoutTable));
171: CommentAggregatorWidget widget = new CommentAggregatorWidget(
172: new WidgetRoot(parent), "!STIQcomments\n");
173: assertFalse(widget.render(), widget.render().indexOf(
174: contentWithoutTable) != -1);
175: }
176:
177: public void testMultipleCommentsOneChild() throws Exception {
178: setSTIQTestProperty(crawler.addPage(parent, PathParser
179: .parse("ChildComments"), commentWithMarkup
180: + commentTextOnly));
181: CommentAggregatorWidget widget = new CommentAggregatorWidget(
182: new WidgetRoot(parent), "!STIQcomments\n");
183: assertTrue(widget.render(), widget.render().indexOf(
184: commentWithMarkupRendered) != -1);
185: assertTrue(widget.render(), widget.render().indexOf(
186: commentTextOnlyRendered) != -1);
187: }
188:
189: public void testMultipleCommentsMultipleChildren() throws Exception {
190: setSTIQTestProperty(crawler.addPage(parent, PathParser
191: .parse("ChildComments"), commentWithMarkup
192: + commentTextOnly));
193: setSTIQTestProperty(crawler.addPage(parent, PathParser
194: .parse("ChildMixed"), commentWithMarkup
195: + rowWithoutComment + commentTextOnly));
196: crawler.addPage(parent, PathParser.parse("ChildNoTable"),
197: contentWithoutTable);
198: CommentAggregatorWidget widget = new CommentAggregatorWidget(
199: new WidgetRoot(parent), "!STIQcomments\n");
200:
201: String renderedStr = widget.render();
202:
203: // commentWithMarkupRendered must be present twice.
204: int p1 = renderedStr.indexOf(commentWithMarkupRendered);
205: assertTrue(renderedStr, p1 != -1);
206: int p2 = renderedStr.indexOf(commentWithMarkupRendered, p1);
207: assertTrue(renderedStr, p2 != -1);
208:
209: // commentTextOnlyRendered must be present twice.
210: p1 = -1;
211: p2 = -1;
212: p1 = renderedStr.indexOf(commentTextOnlyRendered);
213: assertTrue(renderedStr, p1 != -1);
214: p2 = renderedStr.indexOf(commentTextOnlyRendered, p1);
215: assertTrue(renderedStr, p2 != -1);
216:
217: assertFalse(renderedStr, renderedStr
218: .indexOf(rowWithoutCommentNotRendered) != -1);
219: assertFalse(renderedStr, renderedStr
220: .indexOf(contentWithoutTable) != -1);
221: }
222:
223: // "Standard" recursive and hierarchical widget tests
224: public void testMatch() throws Exception {
225: assertMatchEquals("!STIQcomments\n", "!STIQcomments");
226: assertMatchEquals("!STIQcomments -R\n", "!STIQcomments -R");
227: assertMatchEquals("!STIQcomments\r", "!STIQcomments");
228: assertMatchEquals("!STIQcomments -R\r", "!STIQcomments -R");
229: assertMatchEquals(" !STIQcomments\n", null);
230: assertMatchEquals(" !STIQcomments -R\n", null);
231: assertMatchEquals("!STIQcomments zap\n", null);
232: assertMatchEquals("!STIQcomments \n", "!STIQcomments ");
233: }
234:
235: public void testIsNotHierarchical() throws Exception {
236: assertFalse(new ContentsWidget(new WidgetRoot(parent),
237: "!STIQcomments\n").isRecursive());
238: }
239:
240: public void testIsHierarchical() throws Exception {
241: assertTrue(new ContentsWidget(new WidgetRoot(parent),
242: "!STIQcomments -R\n").isRecursive());
243: }
244:
245: protected String getRegexp() {
246: return CommentAggregatorWidget.REGEXP;
247: }
248:
249: private WikiPage setSTIQTestProperty(WikiPage page)
250: throws Exception {
251: PageData pageDataToModify = page.getData();
252: pageDataToModify.getProperties().set(WikiPage.STIQ_TEST);
253: page.commit(pageDataToModify);
254: assertTrue(page.isSTIQTest());
255: return page;
256: }
257:
258: public void tearDown() throws Exception {
259: }
260: }
|