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.*;
006:
007: public class AliasLinkWidgetTest extends AbstractWidget {
008: private WikiPage root;
009:
010: private PageCrawler crawler;
011:
012: public void setUp() throws Exception {
013: root = InMemoryPage.makeRoot("RooT");
014: crawler = root.getPageCrawler();
015: }
016:
017: public void tearDown() throws Exception {
018: }
019:
020: public void testMatches() throws Exception {
021: assertMatches("[[tag][link]]");
022: assertMatches("[[this is fun][http://www.objectmentor.com]]");
023: assertNoMatch("[[this\nshould][not match]]");
024: assertNoMatch("[[][]]");
025: assertNoMatch("[[x][]");
026: assertNoMatch("[[][x]");
027: assertNoMatch("[[x] [x]]");
028: assertNoMatch("[[x]]");
029: }
030:
031: public void testHtmlAtTopLevelPage() throws Exception {
032: crawler.addPage(root, PathParser.parse("TestPage"));
033: WidgetRoot wroot = new WidgetRoot(new PagePointer(root,
034: PathParser.parse("TestPage")));
035: AliasLinkWidget w = new AliasLinkWidget(wroot,
036: "[[tag][TestPage]]");
037: String html = w.render();
038: assertEquals("<a href=\"TestPage\">tag</a>", html);
039: }
040:
041: public void testHtmlOnSubPage() throws Exception {
042: crawler.addPage(root, PathParser.parse("ParenT"), "Content");
043: WikiPage parent = root.getChildPage("ParenT");
044: crawler.addPage(parent, PathParser.parse("ChilD"), "ChilD");
045: crawler.addPage(parent, PathParser.parse("ChildTwo"),
046: "ChildTwo");
047: WikiPage child = parent.getChildPage("ChilD");
048: WidgetRoot parentWidget = new WidgetRoot(new PagePointer(root,
049: PathParser.parse("ParenT.ChilD")));
050: AliasLinkWidget w = new AliasLinkWidget(parentWidget,
051: "[[tag][ChildTwo]]");
052: assertEquals("<a href=\"ParenT.ChildTwo\">tag</a>", w.render());
053: AliasLinkWidget w2 = new AliasLinkWidget(new WidgetRoot(child),
054: "[[tag][.ParenT]]");
055: assertEquals("<a href=\"ParenT\">tag</a>", w2.render());
056: }
057:
058: public void testHtmlForPageThatDoesNotExist() throws Exception {
059: crawler.addPage(root, PathParser.parse("FrontPage"));
060: WidgetRoot parentWidget = new WidgetRoot(new PagePointer(root,
061: PathParser.parse("FrontPage")));
062: AliasLinkWidget w = new AliasLinkWidget(parentWidget,
063: "[[tag][TestPage]]");
064: assertEquals("tag<a href=\"TestPage?edit\">"
065: + WikiWordWidget.NONEXISTENT_PAGE_TOKEN + "</a>", w
066: .render());
067: }
068:
069: public void testUparrowOnPageThatDoesNotExist() throws Exception {
070: WikiPage page = crawler.addPage(root, PathParser
071: .parse("FrontPage"));
072: AliasLinkWidget w = new AliasLinkWidget(new WidgetRoot(page),
073: "[[tag][^TestPage]]");
074: assertEquals("tag<a href=\"FrontPage.TestPage?edit\">"
075: + WikiWordWidget.NONEXISTENT_PAGE_TOKEN + "</a>", w
076: .render());
077: }
078:
079: public void testUparrowOnPageThatDoesExist() throws Exception {
080: WikiPage page = crawler.addPage(root, PathParser
081: .parse("TestPage"));
082: crawler.addPage(page, PathParser.parse("SubPage"));
083: WidgetRoot wroot = new WidgetRoot(page);
084: AliasLinkWidget w = new AliasLinkWidget(wroot,
085: "[[tag][^SubPage]]");
086: String html = w.render();
087: assertEquals("<a href=\"TestPage.SubPage\">tag</a>", html);
088: }
089:
090: public void testNoPageTokenDoesNotAppear() throws Exception {
091: WikiPage page = crawler.addPage(root, PathParser
092: .parse("FrontPage"));
093: AliasLinkWidget aliasWidget = new AliasLinkWidget(
094: new WidgetRoot(page),
095: "[[UnknownPage][http://www.solutionsiq.com/UnknownPage]]");
096: String renderedAlias = aliasWidget.render();
097: assertNotSubString(renderedAlias,
098: WikiWordWidget.NONEXISTENT_PAGE_TOKEN);
099: //assertDoesntHaveRegexp("[" + NoPageToken + "]", renderedAlias);
100: }
101:
102: protected String getRegexp() {
103: return AliasLinkWidget.REGEXP;
104: }
105:
106: public void testUsageOnRootPageDoesntCrash() throws Exception {
107: AliasLinkWidget w = new AliasLinkWidget(new WidgetRoot(root),
108: "[[here][PageOne]]");
109: try {
110: w.render();
111: } catch (Exception e) {
112: fail("should not throw Exception: " + e);
113: }
114: }
115:
116: public void testAsWikiText() throws Exception {
117: String ALIAS_LINK = "[[this][that]]";
118: AliasLinkWidget w = new AliasLinkWidget(new WidgetRoot(root),
119: ALIAS_LINK);
120: assertEquals(ALIAS_LINK, w.asWikiText());
121: }
122:
123: public void testLinkToNonExistentWikiPageOnVirtualPage()
124: throws Exception {
125: // When a virtual page contains a link to a non-existent page, the ?
126: // should
127: // issue an edit request to the remote machine
128:
129: ProxyPage virtualPage = new ProxyPage("VirtualPage", root,
130: "host", 9999, PathParser.parse("RealPage.VirtualPage"));
131: AliasLinkWidget widget = new AliasLinkWidget(new WidgetRoot(
132: virtualPage), "[[link][NonExistentPage]]");
133: assertEquals(
134: "link<a href=\"http://host:9999/RealPage.NonExistentPage?edit\" target=\"NonExistentPage\">"
135: + WikiWordWidget.NONEXISTENT_PAGE_TOKEN
136: + "</a>", widget.render());
137: }
138: }
|