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.html;
004:
005: import fitnesse.testutil.AbstractRegex;
006: import fitnesse.wiki.InMemoryPage;
007: import fitnesse.wiki.PageCrawler;
008: import fitnesse.wiki.PageData;
009: import fitnesse.wiki.PathParser;
010: import fitnesse.wiki.WikiPage;
011:
012: public class HtmlUtilTest extends AbstractRegex {
013: private static final String endl = HtmlElement.endl;
014:
015: public void setUp() throws Exception {
016: }
017:
018: public void testBreadCrumbsWithCurrentPageLinked() throws Exception {
019: String trail = "1.2.3.4";
020: HtmlTag breadcrumbs = HtmlUtil
021: .makeBreadCrumbsWithCurrentPageLinked(trail);
022: String expected = getBreadCrumbsWithLastOneLinked();
023: assertEquals(expected, breadcrumbs.html());
024: }
025:
026: public void testBreadCrumbsWithCurrentPageNotLinked()
027: throws Exception {
028: String trail = "1.2.3.4";
029: HtmlTag breadcrumbs = HtmlUtil
030: .makeBreadCrumbsWithCurrentPageNotLinked(trail);
031: String expected = getBreadCrumbsWithLastOneNotLinked();
032: //System.out.println(breadcrumbs.html());
033: assertEquals(expected, breadcrumbs.html());
034: }
035:
036: public void testBreadCrumbsWithPageType() throws Exception {
037: String trail = "1.2.3.4";
038: HtmlTag breadcrumbs = HtmlUtil.makeBreadCrumbsWithPageType(
039: trail, "Some Type");
040: String expected = getBreadCrumbsWithLastOneLinked()
041: + "<span class=\"page_type\">Some Type</span>" + endl;
042: assertEquals(expected, breadcrumbs.html());
043: }
044:
045: private String getBreadCrumbsWithLastOneLinked() {
046: return getFirstThreeBreadCrumbs()
047: + "<a href=\"/.1.2.3.4\" class=\"page_title\">4</a>";
048: }
049:
050: private String getBreadCrumbsWithLastOneNotLinked() {
051: return getFirstThreeBreadCrumbs()
052: + "<span class=\"page_title\">4</span>" + endl;
053: }
054:
055: private String getFirstThreeBreadCrumbs() {
056: return "<a href=\"/\">.</a>" + "<a href=\"/.1\">1</a>."
057: + "<a href=\"/.1.2\">2</a>."
058: + "<a href=\"/.1.2.3\">3</a>.";
059: }
060:
061: public void testMakeFormTag() throws Exception {
062: HtmlTag formTag = HtmlUtil.makeFormTag("method", "action");
063: assertSubString("method", formTag.getAttribute("method"));
064: assertSubString("action", formTag.getAttribute("action"));
065: }
066:
067: public void testTestableHtml() throws Exception {
068: WikiPage root = InMemoryPage.makeRoot("RooT");
069: PageCrawler crawler = root.getPageCrawler();
070: crawler.addPage(root, PathParser.parse("SetUp"), "setup");
071: crawler.addPage(root, PathParser.parse("TearDown"), "teardown");
072: WikiPage page = crawler.addPage(root, PathParser
073: .parse("TestPage"), "the content");
074:
075: String html = HtmlUtil.testableHtml(page.getData());
076: assertSubString(".SetUp", html);
077: assertSubString("setup", html);
078: assertSubString(".TearDown", html);
079: assertSubString("teardown", html);
080: assertSubString("the content", html);
081: assertSubString("class=\"collapsable\"", html);
082: }
083:
084: public void testMakeDivTag() throws Exception {
085: String expected = "<div class=\"myClass\"></div>"
086: + HtmlElement.endl;
087: assertEquals(expected, HtmlUtil.makeDivTag("myClass").html());
088: }
089:
090: public void testMakeBreadCrumbsWithCurrentPageLinkedWithEmptyArray()
091: throws Exception {
092: try {
093: HtmlUtil.makeBreadCrumbsWithCurrentPageLinked(".");
094: HtmlUtil.makeBreadCrumbsWithCurrentPageLinked("");
095: } catch (Exception e) {
096: fail("should not throw exception");
097: }
098: }
099:
100: public void testActionsRemoveTestCaseResultsFromSuite()
101: throws Exception {
102: String pageName = "EmptyPage";
103: WikiPage root = InMemoryPage.makeRoot("RooT");
104: root.addChildPage(pageName);
105: PageData pageData = new PageData(root.getChildPage(pageName));
106: String html = HtmlUtil.makeActions(pageData, pageName,
107: pageName, false).html();
108:
109: String removalMethod = "top.removeTestCaseResultsFromSuite()";
110:
111: assertSubString("id=\"edit\" class=\"toolbarLink\" onclick=\""
112: + removalMethod, html);
113: assertSubString(
114: "id=\"properties\" class=\"toolbarLink\" onclick=\""
115: + removalMethod, html);
116: assertSubString(
117: "id=\"refactor\" class=\"toolbarLink\" onclick=\""
118: + removalMethod, html);
119: assertSubString(
120: "id=\"newStiqPage\" class=\"toolbarLink\" onclick=\""
121: + removalMethod, html);
122: assertSubString(
123: "id=\"Refresh\" class=\"toolbarLink\" onclick=\""
124: + removalMethod, html);
125: }
126: }
|