Skip to content

Commit

Permalink
Merge branch 'master' into manage_accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
suratdas authored Jan 17, 2024
2 parents 4104a8f + bd43869 commit 76cb7d6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 19 deletions.
5 changes: 3 additions & 2 deletions FitNesseRoot/FitNesse/ReleaseNotes/content.txt
Original file line number Diff line number Diff line change
@@ -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]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 6 additions & 4 deletions src/fitnesse/resources/templates/scopeVariables.vm
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
<thead>
<tr>
<th><a href="javascript:void(tableSorter.sort(0));">Variable name</a></th>
<th><a href="javascript:void(tableSorter.sort(1));">Variable location</a></th>
<th><a href="javascript:void(tableSorter.sort(1));">Variable value</a></th>
<th><a href="javascript:void(tableSorter.sort(2));">Variable location</a></th>
</tr>
</thead>
<tbody>
#foreach ($entry in $variables.keySet())
#foreach ($entry in $variables)
<tr>
<td>$entry</td>
<td><a href="$variables.get($entry)">$variables.get($entry)</a></td>
<td>$entry.getKey()</td>
<td>$entry.getValue()</td>
<td><a href="$entry.getLocation()">$entry.getLocation()</a></td>
</tr>
#end
</tbody>
Expand Down
36 changes: 30 additions & 6 deletions src/fitnesse/responders/ScopeVariablesResponder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.*;

public class ScopeVariablesResponder extends BasicResponder {
private HashMap<String,String> variables;
private List<ScopeVariable> variables;
private HtmlPage responsePage;

@Override
Expand All @@ -30,19 +30,19 @@ 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);
}
return response;
}

private void listVariablesLoc(WikiPage page) {
List<String> variableList = MarkUpSystem.listVariables(page);
Map<String, String> variableList = MarkUpSystem.listVariables(page);

for (String var : variableList) {
if (variables.get(var) == null) {
variables.put(var, page.getFullPath().toString());
for (Map.Entry<String, String> var : variableList.entrySet()) {
if (variables.stream().noneMatch(variable -> var.getKey().equals(variable.getKey()))) {
variables.add(new ScopeVariable(var.getKey(), page.getFullPath().toString(), var.getValue()));
}
}

Expand All @@ -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;
}
}
}
10 changes: 8 additions & 2 deletions src/fitnesse/wikitext/MarkUpSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> listVariables(WikiPage page) {
static Map<String, String> listVariables(WikiPage page) {
Map<String, String> 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;
}
}
10 changes: 5 additions & 5 deletions test/fitnesse/responders/ScopeVariablesResponderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("<tr>.*?<td>x</td>.*?<td><a href=\"SimplePage\">SimplePage</a></td>.*?</tr>", response.getContent());
assertHasRegexp("<tr>.*?<td>y</td>.*?<td><a href=\"SimplePage\">SimplePage</a></td>.*?</tr>", response.getContent());
assertHasRegexp("<tr>.*?<td>z</td>.*?<td><a href=\"SimplePage.ChildPage\">SimplePage.ChildPage</a></td>.*?</tr>", response.getContent());
assertHasRegexp("<tr>.*?<td>a</td>.*?<td><a href=\"SimplePage.ChildPage.GrandChildPage\">SimplePage.ChildPage.GrandChildPage</a></td>.*?</tr>", response.getContent());
assertHasRegexp("<tr>.*?<td>b</td>.*?<td><a href=\"SimplePage.ChildPage.GrandChildPage\">SimplePage.ChildPage.GrandChildPage</a></td>.*?</tr>", response.getContent());
assertHasRegexp("<tr>.*?<td>x</td>.*?<td>X</td>.*<td><a href=\"SimplePage\">SimplePage</a></td>.*?</tr>", response.getContent());
assertHasRegexp("<tr>.*?<td>y</td>.*?<td>Y</td>.*<td><a href=\"SimplePage\">SimplePage</a></td>.*?</tr>", response.getContent());
assertHasRegexp("<tr>.*?<td>z</td>.*?<td>Z</td>.*?<td><a href=\"SimplePage.ChildPage\">SimplePage.ChildPage</a></td>.*?</tr>", response.getContent());
assertHasRegexp("<tr>.*?<td>a</td>.*?<td>B</td>.*?<td><a href=\"SimplePage.ChildPage.GrandChildPage\">SimplePage.ChildPage.GrandChildPage</a></td>.*?</tr>", response.getContent());
assertHasRegexp("<tr>.*?<td>b</td>.*?<td>BB</td>.*?<td><a href=\"SimplePage.ChildPage.GrandChildPage\">SimplePage.ChildPage.GrandChildPage</a></td>.*?</tr>", response.getContent());
}
}

0 comments on commit 76cb7d6

Please sign in to comment.