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