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.MockWikiPage;
06:
07: public class LinkWidgetTest extends AbstractWidget {
08: public void setUp() throws Exception {
09: }
10:
11: public void tearDown() throws Exception {
12: }
13:
14: public void testRegexp() throws Exception {
15: assertMatchEquals(
16: "http://www.objectmentor.com/resources/bookstore/books/PPPCoverIcon.html",
17: "http://www.objectmentor.com/resources/bookstore/books/PPPCoverIcon.html");
18: assertMatchEquals("http://files/someFile",
19: "http://files/someFile");
20: assertMatchEquals("http://files", "http://files");
21: assertMatchEquals("http://objectmentor.com",
22: "http://objectmentor.com");
23: assertMatchEquals("(http://objectmentor.com)",
24: "http://objectmentor.com");
25: assertMatchEquals("http://objectmentor.com.",
26: "http://objectmentor.com");
27: assertMatchEquals("(http://objectmentor.com).",
28: "http://objectmentor.com");
29: assertMatchEquals("https://objectmentor.com",
30: "https://objectmentor.com");
31: }
32:
33: public void testHtml() throws Exception {
34: LinkWidget widget = new LinkWidget(new MockWidgetRoot(),
35: "http://host.com/file.html");
36: assertEquals(
37: "<a href=\"http://host.com/file.html\">http://host.com/file.html</a>",
38: widget.render());
39:
40: widget = new LinkWidget(new MockWidgetRoot(),
41: "http://files/somePage");
42: assertEquals(
43: "<a href=\"/files/somePage\">http://files/somePage</a>",
44: widget.render());
45:
46: widget = new LinkWidget(new MockWidgetRoot(),
47: "http://www.objectmentor.com");
48: assertEquals(
49: "<a href=\"http://www.objectmentor.com\">http://www.objectmentor.com</a>",
50: widget.render());
51: }
52:
53: public void testAsWikiText() throws Exception {
54: final String LINK_TEXT = "http://xyz.com";
55: LinkWidget widget = new LinkWidget(new MockWidgetRoot(),
56: LINK_TEXT);
57: assertEquals(LINK_TEXT, widget.asWikiText());
58: }
59:
60: public void testHttpsLink() throws Exception {
61: String link = "https://link.com";
62: LinkWidget widget = new LinkWidget(new MockWidgetRoot(), link);
63: assertEquals(
64: "<a href=\"https://link.com\">https://link.com</a>",
65: widget.render());
66: assertEquals(link, widget.asWikiText());
67: }
68:
69: public void testLinkWikiWithVariable() throws Exception {
70: String text = "!define HOST {somehost}\nhttp://www.${HOST}.com\n";
71: WidgetRoot root = new WidgetRoot(text, new MockWikiPage());
72: assertSubString(
73: "<a href=\"http://www.somehost.com\">http://www.somehost.com</a>",
74: root.render());
75: assertEquals(text, root.asWikiText());
76: }
77:
78: protected String getRegexp() {
79: return LinkWidget.REGEXP;
80: }
81: }
|