Skip to content

Commit

Permalink
Add group-with-ref form tests (#402)
Browse files Browse the repository at this point in the history
Added XFormParserTest.parseGroupWithRefAttrForm()
  • Loading branch information
cooperka authored and ggalmazor committed Jan 30, 2019
1 parent 981caf3 commit 8c4a7e3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
29 changes: 29 additions & 0 deletions resources/group-with-ref-attr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml">
<h:head>
<h:title>group with ref attribute</h:title>
<model>
<instance>
<data id="group-with-ref-attr">
<G1>
<G2>
<Q1/>
</G2>
<G3>
<Q2/>
</G3>
</G1>
</data>
</instance>
</model>
</h:head>
<h:body>
<group ref="/data/G1">
<group>
<input ref="/data/G1/G2/Q1"/>
</group>
<group ref="/data/G1/G3">
<input ref="/data/G1/G3/Q2"/>
</group>
</group>
</h:body>
</h:html>
35 changes: 35 additions & 0 deletions test/org/javarosa/xform/parse/XFormParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,41 @@ public void parseFormWithSetValueAction() throws IOException {
assertThat(groupElement.getBind(), is(expectedXPathReference));
}

@Test public void parseGroupWithRefAttrForm() throws IOException, XPathSyntaxException {
// Given & When
FormDef formDef = parse(r("group-with-ref-attr.xml"));

// Then
assertEquals(formDef.getTitle(), "group with ref attribute");
assertEquals("Number of error messages", 0, formDef.getParseErrors().size());

final TreeReference g2TreeRef = new TreeReference();
g2TreeRef.setRefLevel(-1); // absolute reference
g2TreeRef.add("data", -1); // the instance root
g2TreeRef.add("G1", -1); // the outer group
g2TreeRef.add("G2", -1); // the inner group

// G2 does NOT have a `ref`.
// Collect implicitly assumes the TreeReference will be created like this.
IDataReference g2AbsRef = FormDef.getAbsRef(null, g2TreeRef.getParentRef());

IFormElement g2Element = formDef.getChild(0).getChild(0);
assertThat(g2Element.getBind(), is(g2AbsRef));

final TreeReference g3TreeRef = new TreeReference();
g3TreeRef.setRefLevel(-1); // absolute reference
g3TreeRef.add("data", -1); // the instance root
g3TreeRef.add("G1", -1); // the outer group
g3TreeRef.add("G3", -1); // the inner group

// G3 has a `ref`.
// Collect implicitly assumes the TreeReference will be created like this.
IDataReference g3AbsRef = FormDef.getAbsRef(new XPathReference(g3TreeRef), g3TreeRef.getParentRef());

IFormElement g3Element = formDef.getChild(0).getChild(1);
assertThat(g3Element.getBind(), is(g3AbsRef));
}

private TreeElement findDepthFirst(TreeElement parent, String name) {
int len = parent.getNumChildren();
for (int i = 0; i < len; ++i) {
Expand Down

0 comments on commit 8c4a7e3

Please sign in to comment.