Search in sources :

Example 36 with Input

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

the class FormDefaultValuesProcessorImplTest method defaultValue_checkbox.

@Test
public void defaultValue_checkbox() {
    Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.CHECK_BOX).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "checked").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("true"));
}
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 37 with Input

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

the class FormDefaultValuesProcessorImplTest method defaultValue_checkbox_invalid.

@Test
public void defaultValue_checkbox_invalid() {
    Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.CHECK_BOX).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "unchecked").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);
    assertNull(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)

Example 38 with Input

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

the class CustomSelectorTypeTest method testCreateDefaultValue.

@Test
public void testCreateDefaultValue() {
    final Input input = getDefaultInputBuilder(InputTypeName.CUSTOM_SELECTOR, "testValue").build();
    final Value value = this.type.createDefaultValue(input);
    assertNotNull(value);
    assertEquals("testValue", value.toString());
}
Also used : Input(com.enonic.xp.form.Input) Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Example 39 with Input

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

the class DateTimeTypeTest method testCreateDefaultValue_withTimezone_format2_plus.

@Test
public void testCreateDefaultValue_withTimezone_format2_plus() {
    final Input input = getDefaultInputBuilder(InputTypeName.DATE_TIME, "2014-08-16T10:03:45+03:00").inputTypeConfig(InputTypeConfig.create().property(InputTypeProperty.create("timezone", "true").build()).build()).build();
    final Value value = this.type.createDefaultValue(input);
    assertNotNull(value);
    assertSame(ValueTypes.DATE_TIME, value.getType());
    assertEquals(value.toString(), "2014-08-16T07:03:45Z");
}
Also used : Input(com.enonic.xp.form.Input) Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Example 40 with Input

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

the class DateTimeTypeTest method testRelativeDefaultValue_date_time_invalid.

@Test
public void testRelativeDefaultValue_date_time_invalid() {
    final Input input = getDefaultInputBuilder(InputTypeName.DATE_TIME, "+1year -5months -36d +2minutes -1haaur").build();
    assertThrows(IllegalArgumentException.class, () -> this.type.createDefaultValue(input));
}
Also used : Input(com.enonic.xp.form.Input) Test(org.junit.jupiter.api.Test)

Aggregations

Input (com.enonic.xp.form.Input)62 Test (org.junit.jupiter.api.Test)47 Value (com.enonic.xp.data.Value)24 Form (com.enonic.xp.form.Form)15 PropertyTree (com.enonic.xp.data.PropertyTree)11 FormItem (com.enonic.xp.form.FormItem)9 FormItemSet (com.enonic.xp.form.FormItemSet)9 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)7 ContentType (com.enonic.xp.schema.content.ContentType)7 FormOptionSet (com.enonic.xp.form.FormOptionSet)5 FieldSet (com.enonic.xp.form.FieldSet)4 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)4 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)4 Property (com.enonic.xp.data.Property)3 Occurrences (com.enonic.xp.form.Occurrences)3 Content (com.enonic.xp.content.Content)2 ExtraData (com.enonic.xp.content.ExtraData)2 ValidationErrors (com.enonic.xp.content.ValidationErrors)2 PropertyPath (com.enonic.xp.data.PropertyPath)2 PropertySet (com.enonic.xp.data.PropertySet)2