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