// Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the GNU General Public License version 2 or later.
package fitnesse.html;
import fitnesse.testutil.AbstractRegex;
import fitnesse.wiki.InMemoryPage;
import fitnesse.wiki.PageCrawler;
import fitnesse.wiki.PageData;
import fitnesse.wiki.PathParser;
import fitnesse.wiki.WikiPage;
public class HtmlUtilTest extends AbstractRegex
{
private static final String endl = HtmlElement.endl;
public void setUp() throws Exception {
}
public void testBreadCrumbsWithCurrentPageLinked() throws Exception
{
String trail = "1.2.3.4";
HtmlTag breadcrumbs = HtmlUtil.makeBreadCrumbsWithCurrentPageLinked(trail);
String expected = getBreadCrumbsWithLastOneLinked();
assertEquals(expected, breadcrumbs.html());
}
public void testBreadCrumbsWithCurrentPageNotLinked() throws Exception
{
String trail = "1.2.3.4";
HtmlTag breadcrumbs = HtmlUtil.makeBreadCrumbsWithCurrentPageNotLinked(trail);
String expected = getBreadCrumbsWithLastOneNotLinked();
//System.out.println(breadcrumbs.html());
assertEquals(expected, breadcrumbs.html());
}
public void testBreadCrumbsWithPageType() throws Exception
{
String trail = "1.2.3.4";
HtmlTag breadcrumbs = HtmlUtil.makeBreadCrumbsWithPageType(trail, "Some Type");
String expected = getBreadCrumbsWithLastOneLinked() +
"<span class=\"page_type\">Some Type</span>" + endl;
assertEquals(expected, breadcrumbs.html());
}
private String getBreadCrumbsWithLastOneLinked()
{
return getFirstThreeBreadCrumbs() +
"<a href=\"/.1.2.3.4\" class=\"page_title\">4</a>";
}
private String getBreadCrumbsWithLastOneNotLinked()
{
return getFirstThreeBreadCrumbs() +
"<span class=\"page_title\">4</span>" + endl;
}
private String getFirstThreeBreadCrumbs()
{
return "<a href=\"/\">.</a>"
+ "<a href=\"/.1\">1</a>."
+ "<a href=\"/.1.2\">2</a>."
+ "<a href=\"/.1.2.3\">3</a>.";
}
public void testMakeFormTag() throws Exception
{
HtmlTag formTag = HtmlUtil.makeFormTag("method", "action");
assertSubString("method", formTag.getAttribute("method"));
assertSubString("action", formTag.getAttribute("action"));
}
public void testTestableHtml() throws Exception
{
WikiPage root = InMemoryPage.makeRoot("RooT");
PageCrawler crawler = root.getPageCrawler();
crawler.addPage(root, PathParser.parse("SetUp"), "setup");
crawler.addPage(root, PathParser.parse("TearDown"), "teardown");
WikiPage page = crawler.addPage(root, PathParser.parse("TestPage"), "the content");
String html = HtmlUtil.testableHtml(page.getData());
assertSubString(".SetUp", html);
assertSubString("setup", html);
assertSubString(".TearDown", html);
assertSubString("teardown", html);
assertSubString("the content", html);
assertSubString("class=\"collapsable\"", html);
}
public void testMakeDivTag() throws Exception
{
String expected = "<div class=\"myClass\"></div>" + HtmlElement.endl;
assertEquals(expected, HtmlUtil.makeDivTag("myClass").html());
}
public void testMakeBreadCrumbsWithCurrentPageLinkedWithEmptyArray() throws Exception
{
try
{
HtmlUtil.makeBreadCrumbsWithCurrentPageLinked(".");
HtmlUtil.makeBreadCrumbsWithCurrentPageLinked("");
}
catch(Exception e)
{
fail("should not throw exception");
}
}
public void testActionsRemoveTestCaseResultsFromSuite() throws Exception
{
String pageName = "EmptyPage";
WikiPage root = InMemoryPage.makeRoot("RooT");
root.addChildPage(pageName);
PageData pageData = new PageData(root.getChildPage(pageName));
String html = HtmlUtil.makeActions(pageData, pageName, pageName, false).html();
String removalMethod = "top.removeTestCaseResultsFromSuite()";
assertSubString("id=\"edit\" class=\"toolbarLink\" onclick=\"" + removalMethod, html);
assertSubString("id=\"properties\" class=\"toolbarLink\" onclick=\"" + removalMethod, html);
assertSubString("id=\"refactor\" class=\"toolbarLink\" onclick=\"" + removalMethod, html);
assertSubString("id=\"newStiqPage\" class=\"toolbarLink\" onclick=\"" + removalMethod, html);
assertSubString("id=\"Refresh\" class=\"toolbarLink\" onclick=\"" + removalMethod, html);
}
}
|