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:
07: public class ImageWidgetTest extends AbstractWidget {
08: public void testRegexp() throws Exception {
09: assertMatchEquals(
10: "http://www.objectmentor.com/resources/bookstore/books/PPPCoverIcon.gif",
11: "http://www.objectmentor.com/resources/bookstore/books/PPPCoverIcon.gif");
12: assertMatchEquals("http://www.objectmentor.com/x.jpg",
13: "http://www.objectmentor.com/x.jpg");
14: assertMatchEquals("http://www.objectmentor.com/x.GIF",
15: "http://www.objectmentor.com/x.GIF");
16: assertMatchEquals("http://www.objectmentor.com/x.JPG",
17: "http://www.objectmentor.com/x.JPG");
18: assertMatchEquals("!img http://files/someImage",
19: "!img http://files/someImage");
20: assertMatchEquals("!img http://www.oma.com/x.gif",
21: "!img http://www.oma.com/x.gif");
22: assertMatchEquals("!img /root/file.gif", "!img /root/file.gif");
23: assertMatchEquals("!img /root/file.gif", null);
24: assertMatchEquals("!img-l http://files/x.gif",
25: "!img-l http://files/x.gif");
26: }
27:
28: public void testWidget() throws Exception {
29: ImageWidget widget = new ImageWidget(new MockWidgetRoot(),
30: "http://host.com/file.jpg");
31: assertEquals("<img src=\"http://host.com/file.jpg\">", widget
32: .render());
33:
34: widget = new ImageWidget(new MockWidgetRoot(),
35: "!img http://files/file.jpg");
36: assertEquals("<img src=\"/files/file.jpg\">", widget.render());
37:
38: widget = new ImageWidget(new MockWidgetRoot(),
39: "!img-l http://files/file.jpg");
40: assertEquals("<img src=\"/files/file.jpg\" class=\"left\">",
41: widget.render());
42:
43: widget = new ImageWidget(new MockWidgetRoot(),
44: "!img /files/file.jpg");
45: assertEquals("<img src=\"/files/file.jpg\">", widget.render());
46: }
47:
48: public void testAsWikiText() throws Exception {
49: checkWikiTextReconstruction("!img http://hello.jpg");
50: checkWikiTextReconstruction("!img http://files/hello.jpg");
51: checkWikiTextReconstruction("!img-l http://hello.jpg");
52: checkWikiTextReconstruction("!img-r http://hello.jpg");
53: checkWikiTextReconstruction("http://hello.jpg");
54: }
55:
56: private void checkWikiTextReconstruction(String original)
57: throws Exception {
58: WikiPage root = InMemoryPage.makeRoot("root");
59: WikiPage somePage = root.getPageCrawler().addPage(root,
60: PathParser.parse("SomePage"));
61: WidgetRoot widgetRoot = new WidgetRoot(somePage);
62: ImageWidget widget = new ImageWidget(widgetRoot, original);
63: assertEquals(original, widget.asWikiText());
64: }
65:
66: protected String getRegexp() {
67: return ImageWidget.REGEXP;
68: }
69: }
|