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.widgets;
04:
05: import fitnesse.wiki.*;
06: import fitnesse.wikitext.WidgetBuilder;
07:
08: public class VariableWidgetTest extends AbstractWidget {
09: private WikiPage root;
10:
11: private PageCrawler crawler;
12:
13: private WikiPage page;
14:
15: private WidgetRoot widgetRoot;
16:
17: public void setUp() throws Exception {
18: root = InMemoryPage.makeRoot("root");
19: crawler = root.getPageCrawler();
20: page = crawler.addPage(root, PathParser.parse("MyPage"));
21: widgetRoot = new WidgetRoot("", page);
22: }
23:
24: public void tearDown() throws Exception {
25: }
26:
27: public void testMatches() throws Exception {
28: assertMatches("${X}");
29: assertMatches("${xyz}");
30: }
31:
32: protected String getRegexp() {
33: return VariableWidget.REGEXP;
34: }
35:
36: public void testVariableIsExpressed() throws Exception {
37: widgetRoot.addVariable("x", "1");
38: VariableWidget w = new VariableWidget(widgetRoot, "${x}");
39: assertEquals("1", w.render());
40: }
41:
42: public void testRenderTwice() throws Exception {
43: widgetRoot.addVariable("x", "1");
44: VariableWidget w = new VariableWidget(widgetRoot, "${x}");
45: assertEquals("1", w.render());
46: assertEquals("1", w.render());
47: }
48:
49: public void testVariableInParentPage() throws Exception {
50: WikiPage parent = crawler.addPage(root, PathParser
51: .parse("ParentPage"), "!define var {zot}\n");
52: WikiPage child = crawler.addPage(parent, PathParser
53: .parse("ChildPage"), "ick");
54:
55: WidgetRoot widgetRoot = new WidgetRoot("", child,
56: WidgetBuilder.htmlWidgetBuilder);
57: VariableWidget w = new VariableWidget(widgetRoot, "${var}");
58: assertEquals("zot", w.render());
59: }
60:
61: public void testUndefinedVariable() throws Exception {
62: WikiPage page = crawler.addPage(root, PathParser
63: .parse("MyPage"));
64: WidgetRoot widgetRoot = new WidgetRoot("", page);
65: VariableWidget w = new VariableWidget(widgetRoot, "${x}");
66: assertSubString("undefined variable: x", w.render());
67: }
68:
69: public void testAsWikiText() throws Exception {
70: VariableWidget w = new VariableWidget(widgetRoot, "${x}");
71: assertEquals("${x}", w.asWikiText());
72: }
73: }
|