Search in sources :

Example 31 with Form

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"));
}
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) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 32 with Form

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"));
}
Also used : 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 33 with Form

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"));
}
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)

Example 34 with Form

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());
}
Also used : Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test) AbstractSchemaTest(com.enonic.xp.core.impl.schema.AbstractSchemaTest)

Example 35 with Form

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"));
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test) AbstractSchemaTest(com.enonic.xp.core.impl.schema.AbstractSchemaTest)

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