Last active
March 29, 2024 22:31
-
-
Save eloff/85876aca54f06790b452cdae5524477d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fitnesse.html; | |
import fitnesse.responders.run.SuiteResponder; | |
import fitnesse.wiki.*; | |
// Note: I did not compile or run this, so it may have stupid errors | |
public class TestableHtml { | |
private PageData pageData; | |
private WikiPage wikiPage; | |
private PageCrawler pageCrawler; | |
private StringBuffer output; | |
private boolean isSuite; | |
public static String render(PageData pageData) throws Exception { | |
return render(pageData, false); | |
} | |
public static String render(PageData pageData, boolean isSuite) throws Exception { | |
if (!pageData.hasAttribute("Test")) { | |
return pageData.getHtml(); | |
} | |
return new TestableHtml(pageData, isSuite).render(); | |
} | |
private TestableHtml(PageData pageData, boolean isSuite) { | |
this.pageData = pageData; | |
this.isSuite = isSuite; | |
wikiPage = pageData.getWikiPage(); | |
pageCrawler = testPage.getPageCrawler(); | |
stringBuffer = new StringBuffer(); | |
} | |
private String render() throws Exception { | |
writeTestSetup(); | |
output.append(pageData.getContent()); | |
output.append("\n"); | |
writeTestTearDown(); | |
pageData.setContent(output.toString()); | |
return pageData.getHtml(); | |
} | |
private writeTestSetup() throws Exception { | |
if (isSuite) { | |
writeIncludePage(output, SuiteResponder.SUITE_SETUP_NAME, "-setup"); | |
} | |
writeIncludePage(output, "SetUp", "-setup"); | |
} | |
private writeTestTearDown() throws Exception { | |
writeIncludePage(output, "TearDown", "-teardown"); | |
if (isSuite) { | |
writeIncludePage(output, SuiteResponder.SUITE_TEARDOWN_NAME, "-teardown"); | |
} | |
} | |
private writeIncludePage(String pageName, String arg) throws Exception { | |
WikiPage inheritedPage = PageCrawlerImpl.getInheritedPage(pageName, wikiPage); | |
if (inheritedPage == null) { | |
return; | |
} | |
WikiPagePath path = pageCrawler.getFullPath(inheritedPage); | |
String renderedPath = PathParser.render(path); | |
output.append("!include ") | |
.append(arg) | |
.append(" .") | |
.append(renderedPath) | |
.append("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment