use of com.enonic.xp.form.Form in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method testItemSetWithMinOccurrencesMoreZero.
@Test
public void testItemSetWithMinOccurrencesMoreZero() {
FormOptionSet.Builder checkOptionSet = FormOptionSet.create().required(false).name("checkOptionSet").occurrences(Occurrences.create(1, 1));
FormItemSet.Builder formItemSet = FormItemSet.create().name("item-set").occurrences(Occurrences.create(1, 1)).addFormItem(Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).build());
FormOptionSetOption.Builder option = FormOptionSetOption.create().name("option_1").defaultOption(true).addFormItem(formItemSet.build());
checkOptionSet.addOptionSetOption(option.build());
final Form form = Form.create().addFormItem(checkOptionSet.build()).build();
final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
final PropertyTree data = new PropertyTree();
defaultValuesProcessor.setDefaultValues(form, data);
assertEquals(4, data.getTotalSize());
assertNotNull(data.getProperty("checkOptionSet"));
assertEquals("option_1", data.getString("checkOptionSet._selected"));
assertNotNull(data.getProperty("checkOptionSet.option_1.item-set"));
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method testOptionSetWithItemSetWithMinOccurrencesMoreEqualZero.
@Test
public void testOptionSetWithItemSetWithMinOccurrencesMoreEqualZero() {
final Form form = Form.create().addFormItem(FormOptionSet.create().name("checkOptionSet").occurrences(Occurrences.create(1, 1)).addOptionSetOption(FormOptionSetOption.create().name("option").addFormItem(FormItemSet.create().name("checkItemSet").occurrences(Occurrences.create(0, 1)).build()).build()).build()).build();
final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
final PropertyTree data = new PropertyTree();
defaultValuesProcessor.setDefaultValues(form, data);
assertEquals(1, data.getTotalSize());
assertNotNull(data.getString("checkOptionSet"));
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method defaultValue_string.
private void defaultValue_string(final InputTypeName inputTypeName) {
Input input = Input.create().name("testInput").label("testInput").inputTypeProperty(InputTypeProperty.create("one", "one").build()).inputTypeProperty(InputTypeProperty.create("two", "two").build()).inputTypeProperty(InputTypeProperty.create("three", "three").build()).inputType(inputTypeName).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();
defaultValuesProcessor.setDefaultValues(form, data);
assertTrue(data.getString("testInput").equals("two"));
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class MixinServiceImplTest method testInlineFormItems_formItemSet.
@Test
public void testInlineFormItems_formItemSet() {
initializeApps();
final Form form = Form.create().addFormItem(Input.create().name("title").label("Title").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(InlineMixin.create().mixin("myapp2:address").build()).build();
final Form transformedForm = service.inlineFormItems(form);
assertEquals("address.label", transformedForm.getInput("address.label").getPath().toString());
assertEquals("address.street", transformedForm.getInput("address.street").getPath().toString());
assertEquals("address.postalNo", transformedForm.getInput("address.postalNo").getPath().toString());
assertEquals("address.country", transformedForm.getInput("address.country").getPath().toString());
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class MixinServiceImplTest method testInlineFormItems_formOptionSet.
@Test
public void testInlineFormItems_formOptionSet() {
initializeApps();
final FormOptionSet optionSet = FormOptionSet.create().name("myOptionSet").addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption1").label("option label1").addFormItem(InlineMixin.create().mixin("myapp2:address").build()).build()).addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption2").label("option label2").defaultOption(true).addFormItem(Input.create().name("myTextLine2").label("My text line 2").inputType(InputTypeName.TEXT_LINE).build()).build()).build();
final Form form = Form.create().addFormItem(Input.create().name("title").label("Title").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(optionSet).build();
final Form transformedForm = service.inlineFormItems(form);
assertNotNull(transformedForm.getInput("title"));
assertNotNull(transformedForm.getOptionSet("myOptionSet"));
assertNotNull(transformedForm.getOptionSetOption("myOptionSet.myOptionSetOption1"));
assertNotNull(transformedForm.getInput("myOptionSet.myOptionSetOption1.address.label"));
assertNotNull(transformedForm.getInput("myOptionSet.myOptionSetOption1.address.street"));
assertNotNull(transformedForm.getInput("myOptionSet.myOptionSetOption1.address.postalNo"));
assertNotNull(transformedForm.getInput("myOptionSet.myOptionSetOption1.address.country"));
assertNotNull(transformedForm.getOptionSetOption("myOptionSet.myOptionSetOption2"));
assertNotNull(transformedForm.getInput("myOptionSet.myOptionSetOption2.myTextLine2"));
}
Aggregations