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