Search in sources :

Example 21 with Form

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));
}
Also used : Input(com.enonic.xp.form.Input) Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 22 with 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));
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 23 with 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());
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 24 with Form

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"));
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Form(com.enonic.xp.form.Form) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PropertyTree(com.enonic.xp.data.PropertyTree) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) Test(org.junit.jupiter.api.Test)

Example 25 with Form

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"));
}
Also used : Input(com.enonic.xp.form.Input) Form(com.enonic.xp.form.Form) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Aggregations

Form (com.enonic.xp.form.Form)79 Test (org.junit.jupiter.api.Test)59 PropertyTree (com.enonic.xp.data.PropertyTree)36 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)17 Input (com.enonic.xp.form.Input)17 FormItemSet (com.enonic.xp.form.FormItemSet)13 FormOptionSet (com.enonic.xp.form.FormOptionSet)11 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)10 ContentType (com.enonic.xp.schema.content.ContentType)8 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)7 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)5 PropertySet (com.enonic.xp.data.PropertySet)5 Content (com.enonic.xp.content.Content)4 CreateContentParams (com.enonic.xp.content.CreateContentParams)4 EditableContent (com.enonic.xp.content.EditableContent)4 MacroKey (com.enonic.xp.macro.MacroKey)4 XData (com.enonic.xp.schema.xdata.XData)4 SiteConfigs (com.enonic.xp.site.SiteConfigs)4 ContentPath (com.enonic.xp.content.ContentPath)3 Page (com.enonic.xp.page.Page)3