Search in sources :

Example 16 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class XmlContentTypeParserTest method testMixinRefFormats.

@Test
public void testMixinRefFormats() throws Exception {
    parse(this.parser, "-mixins.xml");
    final ContentType result = this.builder.build();
    final XDataNames xDataNames = result.getXData();
    assertEquals(2, xDataNames.getSize());
    assertTrue(xDataNames.contains(XDataName.from("myapplication:metadata1")));
    assertTrue(xDataNames.contains(XDataName.from("myapplication:metadata2")));
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) XDataNames(com.enonic.xp.schema.xdata.XDataNames) Test(org.junit.jupiter.api.Test)

Example 17 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class XmlContentTypeParserTest method testI18n_fieldSet.

@Test
public void testI18n_fieldSet() throws Exception {
    parse(this.parser, "-i18n.xml");
    final ContentType result = this.builder.build();
    FormItem item = null;
    for (final FormItem next : result.getForm().getFormItems()) {
        if (next.getName().startsWith("fieldSet")) {
            item = next;
        }
    }
    assertNotNull(item);
    final FieldSet fieldSet = (FieldSet) item;
    assertEquals("translated.label", fieldSet.getLabelI18nKey());
    final Input inputInsideFieldSet = fieldSet.getFormItems().getInput(FormItemPath.from("textLine2"));
    assertEquals("translated.help-text", inputInsideFieldSet.getHelpTextI18nKey());
    assertEquals("translated.label", inputInsideFieldSet.getLabelI18nKey());
}
Also used : FieldSet(com.enonic.xp.form.FieldSet) Input(com.enonic.xp.form.Input) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) Test(org.junit.jupiter.api.Test)

Example 18 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class XmlContentTypeParserTest method assertOptionSetResult.

private void assertOptionSetResult() throws Exception {
    final ContentType result = this.builder.build();
    assertEquals("myapplication:mytype", result.getName().toString());
    assertEquals("OptionSet", result.getDisplayName());
    assertEquals("OptionSet for testing", result.getDescription());
    assertEquals("base:structured", result.getSuperType().toString());
    assertFalse(result.isAbstract());
    assertFalse(result.isFinal());
    assertEquals(2, result.getForm().size());
    final FormItem item = result.getForm().getFormItem("radioOptionSet");
    assertNotNull(item);
    final FormOptionSet radioOptionSet = (FormOptionSet) item;
    assertEquals(FormItemType.FORM_OPTION_SET, radioOptionSet.getType());
    final FormItems radioOptions = radioOptionSet.getFormItems();
    assertEquals(2, radioOptions.size());
    FormOptionSetOption radioOption1 = radioOptions.getItemByName("option_1").toFormOptionSetOption();
    FormOptionSetOption radioOption2 = radioOptions.getItemByName("option_2").toFormOptionSetOption();
    assertEquals(FormItemType.FORM_OPTION_SET_OPTION, radioOption1.getType());
    assertEquals(FormItemType.FORM_OPTION_SET_OPTION, radioOption2.getType());
    assertFalse(radioOption1.isDefaultOption());
    assertFalse(radioOption2.isDefaultOption());
    assertEquals(0, radioOption2.getFormItems().size());
    assertEquals(2, radioOption1.getFormItems().size());
    final Input textInput = radioOption1.getFormItems().getItemByName("text-input").toInput();
    assertEquals(InputTypeName.TEXT_LINE.toString(), textInput.getInputType().toString());
    assertEquals("Text input", textInput.getHelpText());
    final FormItemSet formItemSet = radioOption1.getFormItems().getItemByName("minimum3").toFormItemSet();
    assertEquals(2, formItemSet.getFormItems().size());
    final FormOptionSet checkOptionSet = result.getForm().getFormItem("checkOptionSet").toFormOptionSet();
    assertEquals(FormItemType.FORM_OPTION_SET, checkOptionSet.getType());
    assertEquals("Multi selection", checkOptionSet.getLabel());
    assertTrue(checkOptionSet.isExpanded());
    final Occurrences checkOptionSetOccurrences = checkOptionSet.getOccurrences();
    assertEquals(0, checkOptionSetOccurrences.getMinimum());
    assertEquals(1, checkOptionSetOccurrences.getMaximum());
    final FormItems checkOptions = checkOptionSet.getFormItems();
    assertEquals(4, checkOptions.size());
    // check option set 1st option
    final FormOptionSetOption checkOption1 = checkOptions.getItemByName("option_1").toFormOptionSetOption();
    assertTrue(checkOption1.isDefaultOption());
    assertEquals(0, checkOption1.getFormItems().size());
    // check option set 2nd option
    final FormOptionSetOption checkOption2 = checkOptions.getItemByName("option_2").toFormOptionSetOption();
    assertTrue(checkOption2.isDefaultOption());
    assertEquals(1, checkOption2.getFormItems().size());
    // nested option set
    final FormOptionSet nestedOptionSet = checkOption2.getFormItems().getItemByName("nestedOptionSet").toFormOptionSet();
    final FormItems nestedSetOptions = nestedOptionSet.getFormItems();
    assertEquals(2, nestedSetOptions.size());
    assertFalse(nestedOptionSet.isExpanded());
    final FormOptionSetOption nestedSetOption1 = nestedSetOptions.getItemByName("option2_1").toFormOptionSetOption();
    assertFalse(nestedSetOption1.isDefaultOption());
    assertEquals(1, nestedSetOption1.getFormItems().size());
    final FormOptionSetOption nestedSetOption2 = nestedSetOptions.getItemByName("option2_2").toFormOptionSetOption();
    assertTrue(nestedSetOption2.isDefaultOption());
    assertEquals(1, nestedSetOption2.getFormItems().size());
    // check option set 3rd option
    final FormOptionSetOption checkOption3 = checkOptions.getItemByName("option_3").toFormOptionSetOption();
    assertFalse(checkOption3.isDefaultOption());
    assertEquals(1, checkOption3.getFormItems().size());
    final Input imageSelectorInput = checkOption3.getFormItems().getItemByName("imageselector").toInput();
    assertEquals("mytype", imageSelectorInput.getInputTypeConfig().getProperty("allowContentType").getValue());
    assertEquals(2, imageSelectorInput.getInputTypeConfig().getProperties("allowContentType").size());
    assertEquals("path1", imageSelectorInput.getInputTypeConfig().getProperty("allowPath").getValue());
    assertEquals(2, imageSelectorInput.getInputTypeConfig().getProperties("allowPath").size());
    assertEquals("system:reference", imageSelectorInput.getInputTypeConfig().getProperty("relationshipType").getValue());
    final Occurrences imageSelectorOccurrences = imageSelectorInput.getOccurrences();
    assertEquals(1, imageSelectorOccurrences.getMinimum());
    assertEquals(1, imageSelectorOccurrences.getMaximum());
    // check option set 4th option
    final FormOptionSetOption checkOption4 = checkOptions.getItemByName("option_4").toFormOptionSetOption();
    assertFalse(checkOption4.isDefaultOption());
    assertEquals(2, checkOption4.getFormItems().size());
    final Input doubleInput = checkOption4.getFormItems().getItemByName("double").toInput();
    final Input longInput = checkOption4.getFormItems().getItemByName("long").toInput();
    assertEquals(InputTypeName.DOUBLE.toString(), doubleInput.getInputType().toString());
    assertEquals(InputTypeName.LONG.toString(), longInput.getInputType().toString());
    final Occurrences longInputOccurrences = longInput.getOccurrences();
    assertEquals(0, longInputOccurrences.getMinimum());
    assertEquals(1, longInputOccurrences.getMaximum());
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Input(com.enonic.xp.form.Input) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) FormItems(com.enonic.xp.form.FormItems) Occurrences(com.enonic.xp.form.Occurrences) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) FormItemSet(com.enonic.xp.form.FormItemSet)

Example 19 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class XmlContentTypeParserTest method testI18n_optionSet.

@Test
public void testI18n_optionSet() throws Exception {
    parse(this.parser, "-i18n.xml");
    final ContentType result = this.builder.build();
    final FormItem item = result.getForm().getFormItem("radioOptionSet");
    assertNotNull(item);
    final FormOptionSet radioOptionSet = (FormOptionSet) item;
    assertEquals(FormItemType.FORM_OPTION_SET, radioOptionSet.getType());
    assertEquals("translated.help-text", radioOptionSet.getHelpTextI18nKey());
    assertEquals("translated.label", radioOptionSet.getLabelI18nKey());
    final Input inputInsideOption = radioOptionSet.getFormItems().getInput(FormItemPath.from("option_1.text-input"));
    assertEquals("translated.help-text", inputInsideOption.getHelpTextI18nKey());
    assertEquals("translated.label", inputInsideOption.getLabelI18nKey());
    final FormOptionSetOption radioOption = radioOptionSet.getFormItems().getItemByName("option_1").toFormOptionSetOption();
    assertEquals("translated.help-text", radioOption.getHelpTextI18nKey());
    assertEquals("translated.label", radioOption.getLabelI18nKey());
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Input(com.enonic.xp.form.Input) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) Test(org.junit.jupiter.api.Test)

Example 20 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class XmlContentTypeParserTest method assertResult.

private void assertResult() throws Exception {
    final ContentType result = this.builder.build();
    assertEquals("myapplication:mytype", result.getName().toString());
    assertEquals("All the Base Types", result.getDisplayName());
    assertEquals("description", result.getDescription());
    assertEquals("${firstName} ${lastName}", result.getDisplayNameExpression());
    assertEquals("Display Name Label", result.getDisplayNameLabel());
    assertEquals("myapplication:content", result.getSuperType().toString());
    assertEquals(false, result.isAbstract());
    assertEquals(true, result.isFinal());
    assertEquals(4, result.getForm().size());
    final FormItem item = result.getForm().getFormItem("myDate");
    assertNotNull(item);
    final Input input = (Input) item;
    assertEquals(InputTypeName.DATE.toString(), input.getInputType().toString());
    final FormItem contentSelectorItem = result.getForm().getFormItem("someonesParent");
    assertNotNull(contentSelectorItem);
    final Input contentSelectorInput = (Input) contentSelectorItem;
    assertEquals(InputTypeName.CONTENT_SELECTOR.toString(), contentSelectorInput.getInputType().toString());
    assertEquals("mytype", contentSelectorInput.getInputTypeConfig().getProperty("allowContentType").getValue());
    assertEquals(2, contentSelectorInput.getInputTypeConfig().getProperties("allowContentType").size());
    assertEquals("path1", contentSelectorInput.getInputTypeConfig().getProperty("allowPath").getValue());
    assertEquals(2, contentSelectorInput.getInputTypeConfig().getProperties("allowPath").size());
    assertEquals("system:reference", contentSelectorInput.getInputTypeConfig().getProperty("relationshipType").getValue());
    final InputTypeConfig config = input.getInputTypeConfig();
    assertNotNull(config);
    final Input defaultOccurrencesInput = result.getForm().getInput("defaultOccurrences");
    final Occurrences defaultOccurrences = defaultOccurrencesInput.getOccurrences();
    assertEquals(0, defaultOccurrences.getMinimum());
    assertEquals(1, defaultOccurrences.getMaximum());
}
Also used : Input(com.enonic.xp.form.Input) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) InputTypeConfig(com.enonic.xp.inputtype.InputTypeConfig) Occurrences(com.enonic.xp.form.Occurrences)

Aggregations

ContentType (com.enonic.xp.schema.content.ContentType)56 Test (org.junit.jupiter.api.Test)35 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)28 Content (com.enonic.xp.content.Content)12 CreateContentParams (com.enonic.xp.content.CreateContentParams)10 ValidationErrors (com.enonic.xp.content.ValidationErrors)9 Form (com.enonic.xp.form.Form)8 PropertyTree (com.enonic.xp.data.PropertyTree)7 Input (com.enonic.xp.form.Input)7 FormItem (com.enonic.xp.form.FormItem)6 FieldSet (com.enonic.xp.form.FieldSet)5 FormItemSet (com.enonic.xp.form.FormItemSet)5 ContentTypes (com.enonic.xp.schema.content.ContentTypes)5 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)4 EditableSite (com.enonic.xp.content.EditableSite)3 PropertySet (com.enonic.xp.data.PropertySet)3 FormOptionSet (com.enonic.xp.form.FormOptionSet)3 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)3 XData (com.enonic.xp.schema.xdata.XData)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2