Search in sources :

Example 46 with ContentType

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

the class ValidateContentDataCommandTest method test_empty_displayName.

@Test
public void test_empty_displayName() {
    // setup
    final FieldSet fieldSet = FieldSet.create().label("My layout").name("myLayout").addFormItem(FormItemSet.create().name("mySet").required(true).addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).build()).build()).build();
    final ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name("myapplication:my_type").addFormItem(fieldSet).build();
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
    final Content content = Content.create().path("/mycontent").type(contentType.getName()).displayName("").build();
    content.getData().setString("mySet.myInput", "thing");
    // exercise
    final ValidationErrors result = executeValidation(content.getData(), contentType.getName(), content.getName(), content.getDisplayName());
    assertThat(result.stream()).hasSize(1);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) FieldSet(com.enonic.xp.form.FieldSet) ContentType(com.enonic.xp.schema.content.ContentType) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 47 with ContentType

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

the class ModifyContentHandlerTest method mockXData.

private void mockXData() {
    final FormItemSet cSet = FormItemSet.create().name("c").occurrences(0, 10).addFormItem(Input.create().label("d").name("d").inputType(InputTypeName.CHECK_BOX).build()).addFormItem(Input.create().label("e").name("e").occurrences(0, 0).inputType(InputTypeName.TEXT_LINE).build()).addFormItem(Input.create().label("f").name("f").inputType(InputTypeName.LONG).build()).build();
    final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(cSet).addFormItem(Input.create().label("z").name("z").occurrences(0, 10).inputType(InputTypeName.TEXT_LINE).build()).build();
    GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
    when(this.contentTypeService.getByName(eq(getContentType))).thenReturn(contentType);
    final XData xData1 = XData.create().name(XDataName.from("com.enonic.myapplication:myschema")).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.DOUBLE).build()).build();
    when(this.xDataService.getByName(eq(xData1.getName()))).thenReturn(xData1);
    final XData xData2 = XData.create().name(XDataName.from("com.enonic.myapplication:other")).addFormItem(Input.create().label("name").name("name").inputType(InputTypeName.TEXT_LINE).build()).build();
    when(this.xDataService.getByName(eq(xData1.getName()))).thenReturn(xData1);
    when(this.xDataService.getByName(eq(xData2.getName()))).thenReturn(xData2);
    when(this.mixinService.inlineFormItems(any(Form.class))).then(returnsFirstArg());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) XData(com.enonic.xp.schema.xdata.XData) FormItemSet(com.enonic.xp.form.FormItemSet)

Example 48 with ContentType

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

the class ContentTypeHandlerTest method testContentTypes.

private ContentTypes testContentTypes() {
    ContentType contentType1 = testContentType();
    ContentType contentType2 = ContentType.create().name("com.enonic.someapp:person").displayName("Person").description("Person content type").superType(ContentTypeName.structured()).build();
    return ContentTypes.from(contentType1, contentType2);
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType)

Example 49 with ContentType

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

the class ContentTypeHandlerTest method testExampleGetType.

@Test
public void testExampleGetType() {
    final Form form = getExampleForm();
    Mockito.when(mixinService.inlineFormItems(Mockito.eq(form))).thenReturn(form);
    final ContentType contentType = exampleContentType();
    final GetContentTypeParams params = new GetContentTypeParams().contentTypeName(contentType.getName());
    Mockito.when(contentTypeService.getByName(params)).thenReturn(contentType);
    runScript("/lib/xp/examples/content/getType.js");
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test)

Example 50 with ContentType

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

the class AbstractContentCommand method validateParentChildRelations.

protected void validateParentChildRelations(final ContentPath parentPath, final ContentTypeName typeName) {
    if (parentPath.isRoot()) {
        // root allows anything except page-template and template-folder.
        if (typeName.isPageTemplate() || typeName.isTemplateFolder()) {
            throw new IllegalArgumentException(String.format("A content with type '%s' cannot be a child of root", typeName));
        } else {
            return;
        }
    }
    final Content parent = GetContentByPathCommand.create(parentPath, this).build().execute();
    if (parent == null) {
        throw new IllegalStateException(String.format("Cannot read parent type with path %s", parentPath));
    }
    final ContentTypeName parentTypeName = parent.getType();
    if ((typeName.isTemplateFolder() && !parentTypeName.isSite()) || (typeName.isPageTemplate() && !parentTypeName.isTemplateFolder())) {
        throw new IllegalArgumentException(String.format("A content with type '%s' cannot be a child of '%s' with path %s", typeName, parentTypeName, parentPath));
    }
    final ContentType parentType = contentTypeService.getByName(GetContentTypeParams.from(parentTypeName));
    if (parentType == null) {
        LOG.debug("Bypass validation for unknown content type of parent with path {}", parentPath);
        return;
    }
    if (!parentType.allowChildContent()) {
        throw new IllegalArgumentException(String.format("Child content is not allowed in '%s' with path %s", parentTypeName, parentPath));
    }
    final boolean isAllowed = allowContentTypeFilter(parentTypeName.getApplicationKey(), parentType.getAllowChildContentType()).test(typeName);
    if (!isAllowed) {
        throw new IllegalArgumentException(String.format("A content with type '%s' cannot be a child of '%s' with path %s", typeName, parentTypeName, parentPath));
    }
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Content(com.enonic.xp.content.Content) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName)

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