Search in sources :

Example 1 with EditableContent

use of com.enonic.xp.content.EditableContent in project xp by enonic.

the class HtmlAreaContentProcessorTest method component_config_data.

@Test
public void component_config_data() throws IOException {
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id\"/>"));
    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:part").descriptor(partDescriptor.getKey()).config(data).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(partComponent).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(1, editableContent.processedReferences.build().getSize());
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) Page(com.enonic.xp.page.Page) PartComponent(com.enonic.xp.region.PartComponent) Test(org.junit.jupiter.api.Test)

Example 2 with EditableContent

use of com.enonic.xp.content.EditableContent in project xp by enonic.

the class HtmlAreaContentProcessorTest method text_component_value.

@Test
public void text_component_value() throws IOException {
    // final PropertyTree data = new PropertyTree();
    // data.addProperty( "htmlData", ValueFactory.newString( "<img data-src=\"image://image-id\"/>" ) );
    // 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 TextComponent textComponent = TextComponent.create().text("<img data-src=\"image://image-id\"/>").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(textComponent).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(1, editableContent.processedReferences.build().getSize());
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : TextComponent(com.enonic.xp.region.TextComponent) PageDescriptor(com.enonic.xp.page.PageDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 3 with EditableContent

use of com.enonic.xp.content.EditableContent in project xp by enonic.

the class HtmlAreaContentProcessorTest method page_config_data.

@Test
public void page_config_data() throws IOException {
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id\"/>"));
    final Form form = Form.create().addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final PageDescriptor pageDescriptor = PageDescriptor.create().config(form).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("aaa:bbb")).build();
    Mockito.when(pageDescriptorService.getByKey(Mockito.isA(DescriptorKey.class))).thenReturn(pageDescriptor);
    final Page page = Page.create().config(data).descriptor(pageDescriptor.getKey()).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(1, editableContent.processedReferences.build().getSize());
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) DescriptorKey(com.enonic.xp.page.DescriptorKey) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 4 with EditableContent

use of com.enonic.xp.content.EditableContent in project xp by enonic.

the class ImageContentProcessorTest method testProcessUpdate.

@Test
public void testProcessUpdate() throws IOException {
    Mockito.when(contentService.getBinary(Mockito.any(), Mockito.any())).thenReturn(this.loadImage("cat-small.jpg"));
    final ProcessUpdateParams processUpdateParams = ProcessUpdateParams.create().contentType(ContentType.create().name(ContentTypeName.imageMedia()).superType(ContentTypeName.imageMedia()).build()).build();
    final ProcessUpdateResult result = this.imageContentProcessor.processUpdate(processUpdateParams);
    final PropertyTree data = new PropertyTree();
    data.addProperty(ContentPropertyNames.MEDIA, ValueFactory.newString("MyImage.jpg"));
    final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(ContentTypeName.imageMedia()).parentPath(ContentPath.ROOT).data(data).addExtraData(new ExtraData(MediaInfo.IMAGE_INFO_METADATA_NAME, new PropertyTree())).attachments(Attachments.from(Attachment.create().mimeType("image/jpg").name("MyImage.jpg").build())).build());
    result.getEditor().edit(editableContent);
    assertNotNull(editableContent.extraDatas.first().getData().getLong("pixelSize", 0));
    assertNotNull(editableContent.extraDatas.first().getData().getLong("imageHeight", 0));
    assertNotNull(editableContent.extraDatas.first().getData().getLong("imageWidth", 0));
    assertNotNull(editableContent.extraDatas.first().getData().getLong("byteSize", 0));
}
Also used : ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) ExtraData(com.enonic.xp.content.ExtraData) Test(org.junit.jupiter.api.Test)

Example 5 with EditableContent

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));
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) Form(com.enonic.xp.form.Form) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) XData(com.enonic.xp.schema.xdata.XData) Test(org.junit.jupiter.api.Test)

Aggregations

EditableContent (com.enonic.xp.content.EditableContent)10 PropertyTree (com.enonic.xp.data.PropertyTree)9 Test (org.junit.jupiter.api.Test)8 Form (com.enonic.xp.form.Form)4 Page (com.enonic.xp.page.Page)4 PageDescriptor (com.enonic.xp.page.PageDescriptor)4 ProcessUpdateParams (com.enonic.xp.content.processor.ProcessUpdateParams)2 ProcessUpdateResult (com.enonic.xp.content.processor.ProcessUpdateResult)2 PartComponent (com.enonic.xp.region.PartComponent)2 PartDescriptor (com.enonic.xp.region.PartDescriptor)2 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)1 Content (com.enonic.xp.content.Content)1 ContentEditor (com.enonic.xp.content.ContentEditor)1 ExtraData (com.enonic.xp.content.ExtraData)1 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 LayoutComponent (com.enonic.xp.region.LayoutComponent)1 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)1 TextComponent (com.enonic.xp.region.TextComponent)1 XData (com.enonic.xp.schema.xdata.XData)1