Search in sources :

Example 26 with Form

use of com.enonic.xp.form.Form in project xp by enonic.

the class FormDefaultValuesProcessorImplTest method testDefaultValueForInputWithOccurrences.

@Test
public void testDefaultValueForInputWithOccurrences() {
    Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value").build()).build()).occurrences(Occurrences.create(3, 3)).build();
    final Form form = Form.create().addFormItem(input).build();
    final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
    final PropertyTree data = new PropertyTree();
    defaultValuesProcessor.setDefaultValues(form, data);
    for (int i = 0; i < 3; i++) {
        assertEquals("Default Value", data.getString("testInput", i));
    }
}
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)

Example 27 with Form

use of com.enonic.xp.form.Form in project xp by enonic.

the class FormDefaultValuesProcessorImplTest method testDefaultValueForInputAndItemSetWithOccurrences.

@Test
public void testDefaultValueForInputAndItemSetWithOccurrences() {
    Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value").build()).build()).build();
    FormItemSet formItemSet = FormItemSet.create().name("field").label("field").addFormItem(input).occurrences(Occurrences.create(3, 3)).build();
    final Form form = Form.create().addFormItem(formItemSet).build();
    final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
    final PropertyTree data = new PropertyTree();
    defaultValuesProcessor.setDefaultValues(form, data);
    for (int i = 0; i < 3; i++) {
        assertEquals("Default Value", data.getProperty("field", i).getSet().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) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 28 with Form

use of com.enonic.xp.form.Form in project xp by enonic.

the class FormDefaultValuesProcessorImplTest method testFieldSet.

@Test
public void testFieldSet() {
    FieldSet.Builder fieldSet = FieldSet.create().name("fieldSet").label("FieldSet").addFormItem(InlineMixin.create().mixin("testApp:testMixin").build()).addFormItem(Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value").build()).build()).build()).addFormItem(Input.create().name("testInput2").label("testInput2").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value 2").build()).build()).build());
    FormItemSet.Builder itemSet = FormItemSet.create().name("item-set").label("Item Set").occurrences(Occurrences.create(1, 1)).addFormItem(fieldSet.build());
    final Form form = Form.create().addFormItem(itemSet.build()).build();
    final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
    final PropertyTree data = new PropertyTree();
    defaultValuesProcessor.setDefaultValues(form, data);
    assertEquals("Default Value", data.getString("item-set.testInput"));
    assertEquals("Default Value 2", data.getString("item-set.testInput2"));
}
Also used : FieldSet(com.enonic.xp.form.FieldSet) Form(com.enonic.xp.form.Form) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PropertyTree(com.enonic.xp.data.PropertyTree) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 29 with Form

use of com.enonic.xp.form.Form in project xp by enonic.

the class FormDefaultValuesProcessorImplTest method testOptionSetItemsAreDefaulted.

@Test
public void testOptionSetItemsAreDefaulted() {
    FormOptionSet.Builder myOptionSet = FormOptionSet.create().required(false).name("myOptionSet").occurrences(Occurrences.create(1, 1));
    FormOptionSetOption.Builder option1 = FormOptionSetOption.create().name("option1").defaultOption(true);
    option1.addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "default").build()).build()).build()).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());
    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"));
    assertEquals(0, 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 30 with Form

use of com.enonic.xp.form.Form in project xp by enonic.

the class FormDefaultValuesProcessorImplTest method testOptionSetWithMinOccurrencesEqualZero.

@Test
public void testOptionSetWithMinOccurrencesEqualZero() {
    FormOptionSet.Builder checkOptionSet = FormOptionSet.create().required(false).name("checkOptionSet").occurrences(Occurrences.create(0, 3));
    FormOptionSetOption.Builder option = FormOptionSetOption.create().name("option_1");
    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(0, data.getTotalSize());
}
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)

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