Skip to content

Commit

Permalink
fixed ticket 57 PAGE_NAME inclusion for SetUp and TearDown tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Gaertner authored and Markus Gaertner committed Mar 19, 2009
1 parent 3598b67 commit e720bf7
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
!*< test page content definition
!define pageContent (!include -setup SetUp
!include IncludedPage
Including page name is !-${PAGE_NAME}-!
!include -teardown TearDown)

*!

!|script|
|create page|SetUp|with content|Set Up page name is !-${PAGE_NAME}-!|
|create page|TearDown|with content|Tear Down page name is !-${PAGE_NAME}-!|
|create page|IncludedPage|with content|Included page name is !-${PAGE_NAME}-!|
|given page|IncludingPage|with content|${pageContent}|
|it should contain|Included page name is <a href="IncludedPage">IncludedPage|
|it should contain|Including page name is <a href="IncludingPage">IncludingPage|
|it should contain|Set Up page name is <a href="IncludingPage">IncludingPage|
|it should contain|Tear Down page name is <a href="IncludingPage">IncludingPage|
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<properties>
<Edit>true</Edit>
<Files>true</Files>
<LastModified>20090319152813</LastModified>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
<Search>true</Search>
<Test>true</Test>
<Versions>true</Versions>
<WhereUsed>true</WhereUsed>
<saveId>1237470268676</saveId>
<ticketId>-6178655714902395693</ticketId>
</properties>
30 changes: 28 additions & 2 deletions src/fitnesse/wikitext/widgets/IncludeWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ private String getPageName(Matcher match) {

//TODO MDM I know this is bad... But it seems better then creating two new widgets.
private void buildWidget(String option) throws Exception {
String widgetText = processLiterals(getIncludedPageContent());
String widgetText = processLiterals(getIncludedPageContent(option));

//Create imposter root with alias = this if included page found.
ParentWidget incRoot = (includedPage == null) ? this : new WidgetRoot(includedPage, this);

if ("-seamless".equals(option) || getRoot().isGatheringInfo()) { //Use the imposter if found.
if (isSeamLess(option) || getRoot().isGatheringInfo()) { //Use the imposter if found.
incRoot.addChildWidgets(widgetText + "\n");
} else { //Use new constructor with dual scope.
new CollapsableWidget(incRoot, this, getPrefix(option) + pageName, widgetText, getCssClass(option), isCollapsed(
Expand All @@ -106,6 +106,26 @@ private void buildWidget(String option) throws Exception {
}
}

//TODO MG There was no better way to nest in this behaviour. As future evolution point we can
// expand the if clause to also accept regular includes and replace PAGE_NAME all the time.
private String getIncludedPageContent(String option) throws Exception {

if (isSetup(option) || isTeardown(option)) {
return replaceSpecialVariables(getIncludedPageContent());
}

return getIncludedPageContent();
}

//TODO MG What about PAGE_PATH?
private String replaceSpecialVariables(String includedPageContent) throws Exception {
return includedPageContent.replaceAll("\\$\\{PAGE_NAME\\}", includingPage.getName());
}

private boolean isSeamLess(String option) {
return "-seamless".equals(option);
}

private String getCssClass(String option) {
return optionCssMap.get(option);
}
Expand Down Expand Up @@ -174,4 +194,10 @@ public WikiPage getReferencedPage() throws Exception {
public String asWikiText() throws Exception {
return "";
}

@Override
public String processLiterals(String value) throws Exception {
// TODO Auto-generated method stub
return super.processLiterals(value);
}
}
22 changes: 22 additions & 0 deletions src/fitnesse/wikitext/widgets/IncludeWidgetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,28 @@ private void verifyLiteralsGetRendered(String option, String pageName)
assertEquals("three", widgetRoot.getLiteral(2));
}

public void testPageNameOnSetUpPage() throws Exception {
verifyPageNameResolving("-setup ", "IncludingPage");
}

public void testPageNameOnTearDownPage() throws Exception {
verifyPageNameResolving("-teardown ", "IncludingPage");
}

public void testPageNameOnRegularPage() throws Exception {
verifyPageNameResolving("", "IncludedPage");
}

private void verifyPageNameResolving(String option, String expectedPageName) throws Exception {
crawler.addPage(root, PathParser.parse("IncludedPage"), "This is IncludedPage\nincluded page name is ${PAGE_NAME}\n");
crawler.addPage(root, PathParser.parse("IncludingPage"));
ParentWidget widgetRoot = new WidgetRoot("This is IncludingPage\n" + "!include " + option + "IncludedPage",
root.getChildPage("IncludingPage"), WidgetBuilder.htmlWidgetBuilder);
String content = widgetRoot.render();
assertHasRegexp("included page name is <a href=\"" + expectedPageName + "\">" + expectedPageName , content);
}


public void testRenderWhenMissing() throws Exception {
verifyRenderWhenMissing("MissingPage");
}
Expand Down

0 comments on commit e720bf7

Please sign in to comment.