Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of unit test written in Scala, with embedded XForms test document
package org.orbeon.oxf.xforms.analysis
import org.orbeon.oxf.common.Version
import org.scalatest.junit.AssertionsForJUnit
import org.orbeon.oxf.test.DocumentTestBase
import org.junit.{Assume, Test}
class ItemsetDependenciesTest extends DocumentTestBase with AssertionsForJUnit {
@Test def testSelectValueDependingOnItemset {
Assume.assumeTrue(Version.isPE) // only test this feature if we are the PE version
this setupDocument
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms">
<xh:head>
<xf:model id="model" xxf:xpath-analysis="true" xxf:encrypt-item-values="false">
<xf:instance id="instance">
<instance xmlns="">
<selection>1 2</selection>
<value>1</value>
<value>2</value>
<index>1</index>
</instance>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<xf:select id="checkbox" ref="selection" appearance="full">
<xf:item>
<xf:label/>
<xf:value ref="../value[xs:integer(../index)]"/>
</xf:item>
</xf:select>
<xf:select1 id="value-selection" ref="index" appearance="full">
<xf:item>
<xf:label>1</xf:label>
<xf:value>1</xf:value>
</xf:item>
<xf:item>
<xf:label>2</xf:label>
<xf:value>2</xf:value>
</xf:item>
</xf:select1>
</xh:body>
</xh:html>
assert(getControlExternalValue("checkbox") === "1")
assert(getControlExternalValue("value-selection") === "1")
assert(getItemset("checkbox") === """[["","1"]]""")
setControlValue("value-selection", "2")
assert(getControlExternalValue("checkbox") === "2")
assert(getItemset("checkbox") === """[["","2"]]""")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.