Search in sources :

Example 16 with XData

use of com.enonic.xp.schema.xdata.XData in project xp by enonic.

the class HtmlAreaContentProcessorTest method extra_data.

@Test
public void extra_data() throws IOException {
    final XDataName xDataName = XDataName.from("xDataName");
    final XData xData = XData.create().name(xDataName).addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final ContentType contentType = ContentType.create().name(contentTypeName).superType(ContentTypeName.folder()).xData(XDataNames.from(xDataName)).build();
    Mockito.when(contentTypeService.getByName(GetContentTypeParams.from(ContentTypeName.site()))).thenReturn(contentType);
    Mockito.when(xDataService.getByNames(XDataNames.from(xDataName))).thenReturn(XDatas.from(xData));
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans01.jpg\" data-src=\"image://image-id\"/>"));
    final EditableSite editableSite = new EditableSite(Site.create().name("myContentName").type(ContentTypeName.site()).parentPath(ContentPath.ROOT).data(new PropertyTree()).extraDatas(ExtraDatas.create().add(new ExtraData(XDataName.from("xDataName"), data)).build()).build());
    result.getEditor().edit(editableSite);
    assertEquals(1, editableSite.processedReferences.build().getSize());
    assertTrue(editableSite.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) EditableSite(com.enonic.xp.content.EditableSite) PropertyTree(com.enonic.xp.data.PropertyTree) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName) Test(org.junit.jupiter.api.Test)

Example 17 with XData

use of com.enonic.xp.schema.xdata.XData in project xp by enonic.

the class HtmlAreaContentProcessorTest method create.

@Test
public void create() throws IOException {
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans01.jpg\" data-src=\"image://image-id1\"/>"));
    final XDataName xDataName = XDataName.from("xDataName");
    final XData xData = XData.create().name(xDataName).addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final PropertyTree extraData = new PropertyTree();
    extraData.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans02.jpg\" data-src=\"image://image-id2\"/>"));
    Mockito.when(xDataService.getByNames(XDataNames.from(xDataName))).thenReturn(XDatas.from(xData));
    final ProcessCreateParams processCreateParams = Mockito.mock(ProcessCreateParams.class);
    final CreateContentParams createContentParams = CreateContentParams.create().parent(ContentPath.ROOT).contentData(data).extraDatas(ExtraDatas.create().add(new ExtraData(XDataName.from("xDataName"), extraData)).build()).type(contentTypeName).build();
    contentType = ContentType.create(contentType).xData(XDataNames.from(XDataName.from("xDataName"))).build();
    Mockito.when(contentTypeService.getByName(GetContentTypeParams.from(contentTypeName))).thenReturn(contentType);
    Mockito.when(processCreateParams.getCreateContentParams()).thenReturn(createContentParams);
    final ProcessCreateResult result = htmlAreaContentProcessor.processCreate(processCreateParams);
    assertEquals(2, result.getCreateContentParams().getProcessedIds().getSize());
    assertTrue(result.getCreateContentParams().getProcessedIds().contains(ContentId.from("image-id1")));
    assertTrue(result.getCreateContentParams().getProcessedIds().contains(ContentId.from("image-id2")));
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

Aggregations

XData (com.enonic.xp.schema.xdata.XData)17 Test (org.junit.jupiter.api.Test)8 ExtraData (com.enonic.xp.content.ExtraData)7 PropertyTree (com.enonic.xp.data.PropertyTree)6 Form (com.enonic.xp.form.Form)5 CreateContentParams (com.enonic.xp.content.CreateContentParams)4 XDataName (com.enonic.xp.schema.xdata.XDataName)4 XDatas (com.enonic.xp.schema.xdata.XDatas)4 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)3 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)3 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)3 ContentType (com.enonic.xp.schema.content.ContentType)3 FormItem (com.enonic.xp.form.FormItem)2 FormItemSet (com.enonic.xp.form.FormItemSet)2 Input (com.enonic.xp.form.Input)2 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)2 GeoPoint (com.enonic.xp.util.GeoPoint)2 Application (com.enonic.xp.app.Application)1 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)1 EditableContent (com.enonic.xp.content.EditableContent)1