use of com.enonic.xp.form.Form in project xp by enonic.
the class InputValidationVisitorTest method validateInputTypeInvalid.
@Test
public void validateInputTypeInvalid() throws Exception {
Input myTextLine = Input.create().name("myTextLine").inputType(InputTypeName.TEXT_LINE).label("My text line").required(true).build();
Form form = Form.create().addFormItem(myTextLine).build();
PropertyTree propertyTree = new PropertyTree();
propertyTree.setLong("myTextLine", 33L);
final InputValidationVisitor validationVisitor = new InputValidationVisitor(propertyTree, InputTypes.BUILTIN);
assertThrows(InputTypeValidationException.class, () -> validationVisitor.traverse(form));
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class InputValidationVisitorTest method validateOptionSetInvalid.
@Test
public void validateOptionSetInvalid() throws Exception {
FormOptionSet formOptionSet = FormOptionSet.create().name("myOptionSet").label("My option set").helpText("Option set help text").addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption1").label("option label1").helpText("Option help text").addFormItem(Input.create().name("myTextLine1").label("myTextLine1").inputType(InputTypeName.TEXT_LINE).build()).build()).addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption2").label("option label2").helpText("Option help text").addFormItem(Input.create().name("myTextLine2").label("myTextLine2").inputType(InputTypeName.TEXT_LINE).build()).build()).build();
Form form = Form.create().addFormItem(formOptionSet).build();
PropertyTree propertyTree = new PropertyTree();
propertyTree.setLong("myOptionSet.myOptionSetOption1.myTextLine1", 33L);
final InputValidationVisitor validationVisitor = new InputValidationVisitor(propertyTree, InputTypes.BUILTIN);
assertThrows(InputTypeValidationException.class, () -> validationVisitor.traverse(form));
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class OccurrenceValidatorTest method testOptionSetWithDefaultValue.
@Test
public void testOptionSetWithDefaultValue() {
Form form = Form.create().addFormItem(FormOptionSet.create().name("checkOptionSet").label("Multi selection").expanded(true).helpText("Help Text").multiple(true).multiselection(Occurrences.create(1, 3)).occurrences(Occurrences.create(1, 1)).addOptionSetOption(FormOptionSetOption.create().name("option_1").label("option_1").helpText("Help text for Option_1").build()).addOptionSetOption(FormOptionSetOption.create().name("option_2").label("option_2").helpText("Help text for Option_2").build()).addOptionSetOption(FormOptionSetOption.create().name("option_3").label("option_3").defaultOption(true).helpText("Help text for Option_3").addFormItem(Input.create().name("htmlAreaField").label("Input").inputType(InputTypeName.HTML_AREA).occurrences(Occurrences.create(2, 4)).build()).build()).build()).build();
ContentType contentType = ContentType.create().name("myapplication:my_type").superType(ContentTypeName.structured()).form(form).build();
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setSet("checkOptionSet.option_3", new PropertySet());
final ValidationErrors validationResults = validate(content);
assertFalse(validationResults.hasErrors());
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method testOptionSetIsNotDefaultedForUnselected.
@Test
public void testOptionSetIsNotDefaultedForUnselected() {
FormOptionSet.Builder myOptionSet = FormOptionSet.create().required(false).name("myOptionSet").occurrences(Occurrences.create(1, 1));
FormOptionSetOption.Builder option1 = FormOptionSetOption.create().name("option1").defaultOption(true);
FormOptionSetOption.Builder option2 = FormOptionSetOption.create().name("option2");
option1.addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "default").build()).build()).build());
option2.addFormItem(Input.create().name("myDouble").label("double").inputType(InputTypeName.DOUBLE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "0").build()).build()).build());
myOptionSet.addOptionSetOption(option1.build());
myOptionSet.addOptionSetOption(option2.build());
final Form form = Form.create().addFormItem(myOptionSet.build()).build();
final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
final PropertyTree data = new PropertyTree();
defaultValuesProcessor.setDefaultValues(form, data);
assertEquals("default", data.getString("myOptionSet.option1.myInput"));
assertNull(data.getDouble("myOptionSet.option1.myDouble"));
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method defaultValue_string_nonEmptyData.
@Test
public void defaultValue_string_nonEmptyData() {
Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "two").build()).build()).build();
final Form form = Form.create().addFormItem(input).build();
final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
final PropertyTree data = new PropertyTree();
data.setProperty(PropertyPath.from("testInput"), ValueFactory.newString("three"));
defaultValuesProcessor.setDefaultValues(form, data);
assertEquals("three", data.getString("testInput"));
}
Aggregations