use of com.enonic.xp.content.EditableContent in project xp by enonic.
the class HtmlAreaContentProcessorTest method inner_component_data.
@Test
public void inner_component_data() throws IOException {
final PropertyTree data1 = new PropertyTree();
data1.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id1\"/>"));
final PropertyTree data2 = new PropertyTree();
data2.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id2\"/>"));
final Form form = Form.create().addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
final PartDescriptor partDescriptor = PartDescriptor.create().key(DescriptorKey.from("app:part")).config(form).build();
Mockito.when(partDescriptorService.getByKey(partDescriptor.getKey())).thenReturn(partDescriptor);
final PartComponent partComponent = PartComponent.create().descriptor("myapp:partest").descriptor(partDescriptor.getKey()).config(data2).build();
final LayoutDescriptor layoutDescriptor = LayoutDescriptor.create().key(DescriptorKey.from("app:layout")).config(form).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("part").build()).build()).build();
Mockito.when(layoutDescriptorService.getByKey(layoutDescriptor.getKey())).thenReturn(layoutDescriptor);
final LayoutComponent layoutComponent = LayoutComponent.create().descriptor("myapp:layout").descriptor(layoutDescriptor.getKey()).regions(LayoutRegions.create().add(Region.create().name("part").add(partComponent).build()).build()).config(data1).build();
final PageDescriptor pageDescriptor = PageDescriptor.create().regions(RegionDescriptors.create().add(RegionDescriptor.create().name("region").build()).build()).key(DescriptorKey.from("app:page")).config(Form.create().build()).build();
Mockito.when(pageDescriptorService.getByKey(pageDescriptor.getKey())).thenReturn(pageDescriptor);
final Page page = Page.create().config(new PropertyTree()).descriptor(pageDescriptor.getKey()).regions(PageRegions.create().add(Region.create().name("region").add(layoutComponent).build()).build()).build();
final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(contentTypeName).page(page).parentPath(ContentPath.ROOT).data(new PropertyTree()).build());
result.getEditor().edit(editableContent);
assertEquals(2, editableContent.processedReferences.build().getSize());
assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id1")));
assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id2")));
}
use of com.enonic.xp.content.EditableContent in project xp by enonic.
the class HtmlAreaContentProcessorTest method content_data.
@Test
public void content_data() throws IOException {
final PropertyTree data = new PropertyTree();
data.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans01.jpg\" data-src=\"image://image-id\"/>"));
final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(contentTypeName).parentPath(ContentPath.ROOT).data(data).build());
result.getEditor().edit(editableContent);
assertEquals(1, editableContent.processedReferences.build().getSize());
assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
use of com.enonic.xp.content.EditableContent in project xp by enonic.
the class ImageContentProcessorTest method testProcessUpdateWithMediaInfo.
@Test
public void testProcessUpdateWithMediaInfo() throws IOException {
final Form.Builder form = Form.create();
form.addFormItem(createTextLine("shutterTime", "Exposure Time").occurrences(0, 1).build());
form.addFormItem(createTextLine("altitude", "Gps Altitude").occurrences(0, 1).build());
final XData xDataInfo = createXData(MediaInfo.IMAGE_INFO_METADATA_NAME, "Extra Info", form.build());
Mockito.when(this.xDataService.getFromContentType(Mockito.any())).thenReturn(XDatas.from(xDataInfo));
final CreateAttachments createAttachments = createAttachments();
final ProcessUpdateParams processUpdateParams = ProcessUpdateParams.create().contentType(ContentType.create().superType(ContentTypeName.imageMedia()).name("myContent").build()).mediaInfo(MediaInfo.create().addMetadata("exposure time", "1").addMetadata("gps altitude ", "2").build()).createAttachments(createAttachments).build();
final ProcessUpdateResult result = this.imageContentProcessor.processUpdate(processUpdateParams);
final PropertyTree data = new PropertyTree();
final EditableContent editableContent = new EditableContent(Content.create().name("myContentName").parentPath(ContentPath.ROOT).data(data).build());
result.getEditor().edit(editableContent);
assertEquals(editableContent.extraDatas.first().getData().getString("shutterTime", 0), "1");
assertEquals(editableContent.extraDatas.first().getData().getString("altitude", 0), "2");
assertEquals(13, editableContent.extraDatas.first().getData().getLong(MediaInfo.MEDIA_INFO_BYTE_SIZE, 0));
}
use of com.enonic.xp.content.EditableContent in project xp by enonic.
the class ModifyContentHandlerTest method invokeUpdate.
private Content invokeUpdate(final UpdateContentParams params, final Content content) {
assertEquals(ContentId.from("123456"), params.getContentId());
final ContentEditor editor = params.getEditor();
assertNotNull(editor);
final EditableContent editable = new EditableContent(content);
editor.edit(editable);
return editable.build();
}
use of com.enonic.xp.content.EditableContent in project xp by enonic.
the class BaseProjectHandlerTest method mockRootContent.
protected void mockRootContent() {
final Content.Builder contentRoot = Content.create().id(ContentId.from("123")).name(ContentName.from("root")).parentPath(ContentPath.ROOT).permissions(AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allow(Permission.READ).build()).build()).data(new PropertyTree()).extraDatas(ExtraDatas.empty());
Mockito.when(contentService.getByPath(ContentPath.ROOT)).thenReturn(contentRoot.build());
Mockito.when(contentService.update(Mockito.isA(UpdateContentParams.class))).thenAnswer(mock -> {
final UpdateContentParams params = (UpdateContentParams) mock.getArguments()[0];
final EditableContent editableContent = new EditableContent(contentRoot.build());
params.getEditor().edit(editableContent);
contentRoot.language(editableContent.language);
Mockito.when(contentService.getByPath(ContentPath.ROOT)).thenReturn(contentRoot.build());
return contentRoot.build();
});
}
Aggregations