Search in sources :

Example 6 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 7 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 8 with ContentType

use of com.enonic.xp.schema.content.ContentType 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 9 with ContentType

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

the class ContentServiceImplTest_publish method push_one_content_not_valid.

@Disabled
@Test
public void push_one_content_not_valid() throws Exception {
    ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name("myapplication:test").addFormItem(Input.create().name("title").label("Title").inputType(InputTypeName.TEXT_LINE).required(true).build()).build();
    Mockito.when(this.contentTypeService.getByName(GetContentTypeParams.from(contentType.getName()))).thenReturn(contentType);
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(contentType.getName()).build();
    final Content content = this.contentService.create(createContentParams);
    final PublishContentResult push = this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).includeDependencies(false).build());
    assertEquals(1, push.getPushedContents().getSize());
}
Also used : PublishContentResult(com.enonic.xp.content.PublishContentResult) ContentType(com.enonic.xp.schema.content.ContentType) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 10 with ContentType

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

the class ContentTypeHandler method getContentType.

public ContentTypeMapper getContentType() {
    if (name == null || name.isBlank()) {
        return null;
    }
    final GetContentTypeParams params = GetContentTypeParams.from(ContentTypeName.from(name));
    final ContentType ctype = contentTypeService.get().getByName(params);
    return ctype == null ? null : new ContentTypeMapper(inlineMixins(ctype));
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) ContentTypeMapper(com.enonic.xp.lib.content.mapper.ContentTypeMapper)

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