diff --git a/FitNesseRoot/FitNesse/ReleaseNotes/content.txt b/FitNesseRoot/FitNesse/ReleaseNotes/content.txt index bce1297cec..68942dcab8 100644 --- a/FitNesseRoot/FitNesse/ReleaseNotes/content.txt +++ b/FitNesseRoot/FitNesse/ReleaseNotes/content.txt @@ -1,8 +1,9 @@ !2 Pending Changes -* Ability to change password and additionally create/delete users feature for admin([[1468][https://github.com/unclebob/fitnesse/pull/1468]) + * Added the defined values to the overview of all variables in scope. ([[1472][https://github.com/unclebob/fitnesse/pull/1472]]) + * Ability to change password and additionally create/delete users feature for admin([[1468][https://github.com/unclebob/fitnesse/pull/1468]) !2 20231203 -* Updated README and dependencies + * Updated README and dependencies !2 20231029 * Drop Java 8 compatibility and compile with Java 11, Use OpenJDK's nashorn dependency to evaluate JS expressions ([[1426][https://github.com/unclebob/fitnesse/pull/1426]]) diff --git a/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/VariableScope/content.txt b/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/VariableScope/content.txt index 70ec9b53a3..b9090023e7 100644 --- a/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/VariableScope/content.txt +++ b/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/VariableScope/content.txt @@ -5,3 +5,6 @@ For example, lets say the variable we are interested in is X. * If X is defined on this page then it is definately in scope. * If X is not defined on this page but is defined in the page .FitNesse (this page's parent), then X is still in scope. * If X is defined on .FitNesse.UserGuide.FitNesseWiki then X is not in scope because .FitNesse.UserGuide.FitNesseWiki is not a parent of this page. + +All variables that have been declared using !style_code(!define) can be checked by adding !style_code(?variables) at the end of the page's url. +For example !style_code(!-http://myFitNesseHost/FitNesse.UserGuide.FitNesseWiki?variables-!) will show a table with the names, their values and the pages the values are defined. \ No newline at end of file diff --git a/src/fitnesse/resources/templates/scopeVariables.vm b/src/fitnesse/resources/templates/scopeVariables.vm index afbda7f0da..e0566d703b 100644 --- a/src/fitnesse/resources/templates/scopeVariables.vm +++ b/src/fitnesse/resources/templates/scopeVariables.vm @@ -4,14 +4,16 @@ Variable name - Variable location + Variable value + Variable location - #foreach ($entry in $variables.keySet()) + #foreach ($entry in $variables) - $entry - $variables.get($entry) + $entry.getKey() + $entry.getValue() + $entry.getLocation() #end diff --git a/src/fitnesse/responders/ScopeVariablesResponder.java b/src/fitnesse/responders/ScopeVariablesResponder.java index 44cfcc4ac4..fb1e0648ed 100644 --- a/src/fitnesse/responders/ScopeVariablesResponder.java +++ b/src/fitnesse/responders/ScopeVariablesResponder.java @@ -13,7 +13,7 @@ import java.util.*; public class ScopeVariablesResponder extends BasicResponder { - private HashMap variables; + private List variables; private HtmlPage responsePage; @Override @@ -30,7 +30,7 @@ public Response makeResponse(FitNesseContext context, Request request) throws Ex if (requestedPage == null) response = pageNotFoundResponse(context, request); else { - variables = new HashMap<>(); + variables = new ArrayList<>(); listVariablesLoc(page); response = makeResponse(request); } @@ -38,11 +38,11 @@ public Response makeResponse(FitNesseContext context, Request request) throws Ex } private void listVariablesLoc(WikiPage page) { - List variableList = MarkUpSystem.listVariables(page); + Map variableList = MarkUpSystem.listVariables(page); - for (String var : variableList) { - if (variables.get(var) == null) { - variables.put(var, page.getFullPath().toString()); + for (Map.Entry var : variableList.entrySet()) { + if (variables.stream().noneMatch(variable -> var.getKey().equals(variable.getKey()))) { + variables.add(new ScopeVariable(var.getKey(), page.getFullPath().toString(), var.getValue())); } } @@ -61,4 +61,28 @@ private Response makeResponse(Request request) throws UnsupportedEncodingExcepti response.setContent(responsePage.html(request)); return response; } + + public class ScopeVariable { + private String key; + private String location; + private String value; + + public ScopeVariable(String key, String location, String value) { + this.key = key; + this.location = location; + this.value = value; + } + + public String getKey() { + return this.key; + } + + public String getLocation() { + return this.location; + } + + public String getValue() { + return this.value; + } + } } diff --git a/src/fitnesse/wikitext/MarkUpSystem.java b/src/fitnesse/wikitext/MarkUpSystem.java index 1ea95bc91d..03bf110241 100644 --- a/src/fitnesse/wikitext/MarkUpSystem.java +++ b/src/fitnesse/wikitext/MarkUpSystem.java @@ -4,7 +4,9 @@ import fitnesse.wiki.WikiSourcePage; import fitnesse.wikitext.parser.MarkUpSystemV2; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; @@ -18,10 +20,14 @@ public interface MarkUpSystem { static MarkUpSystem make() { return new MarkUpSystemV2(); } static MarkUpSystem make(String content) { return MarkUpSystems.STORE.make(content); } - static List listVariables(WikiPage page) { + static Map listVariables(WikiPage page) { + Map listVariables = new HashMap<>(); ParsingPage parsingPage = new ParsingPage(new WikiSourcePage(page)); String content = page.getData().getContent(); MarkUpSystem.make(content).parse(parsingPage, content); - return parsingPage.listVariables(); + for (String listVariable : parsingPage.listVariables()) { + listVariables.put(listVariable, parsingPage.findVariable(listVariable).orElse("")); + } + return listVariables; } } diff --git a/test/fitnesse/responders/ScopeVariablesResponderTest.java b/test/fitnesse/responders/ScopeVariablesResponderTest.java index 7961933251..081ebc3a12 100644 --- a/test/fitnesse/responders/ScopeVariablesResponderTest.java +++ b/test/fitnesse/responders/ScopeVariablesResponderTest.java @@ -36,10 +36,10 @@ public void setUp() throws Exception { public void shouldListVariables() throws Exception { request.setResource("SimplePage.ChildPage.GrandChildPage"); SimpleResponse response = (SimpleResponse) responder.makeResponse(context,request); - assertHasRegexp(".*?x.*?SimplePage.*?", response.getContent()); - assertHasRegexp(".*?y.*?SimplePage.*?", response.getContent()); - assertHasRegexp(".*?z.*?SimplePage.ChildPage.*?", response.getContent()); - assertHasRegexp(".*?a.*?SimplePage.ChildPage.GrandChildPage.*?", response.getContent()); - assertHasRegexp(".*?b.*?SimplePage.ChildPage.GrandChildPage.*?", response.getContent()); + assertHasRegexp(".*?x.*?X.*SimplePage.*?", response.getContent()); + assertHasRegexp(".*?y.*?Y.*SimplePage.*?", response.getContent()); + assertHasRegexp(".*?z.*?Z.*?SimplePage.ChildPage.*?", response.getContent()); + assertHasRegexp(".*?a.*?B.*?SimplePage.ChildPage.GrandChildPage.*?", response.getContent()); + assertHasRegexp(".*?b.*?BB.*?SimplePage.ChildPage.GrandChildPage.*?", response.getContent()); } }