Search in sources :

Example 1 with Media

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

the class ImageRendererTest method createContent.

private Content createContent() {
    final Media media = ContentFixtures.newMedia();
    Mockito.when(this.contentService.getByPath(media.getPath())).thenReturn(media);
    Mockito.when(this.contentService.getById(Mockito.any(ContentId.class))).thenReturn(media);
    Mockito.when(this.contentService.getBinaryKey(media.getId(), media.getMediaAttachment().getBinaryReference())).thenReturn("binaryHash");
    return media;
}
Also used : Media(com.enonic.xp.content.Media) ContentId(com.enonic.xp.content.ContentId)

Example 2 with Media

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

the class PortalUrlServiceImpl_processHtmlTest method processHtml_image_imageWidths_with_imageSizes.

@Test
public void processHtml_image_imageWidths_with_imageSizes() {
    // Creates a content
    final Media media = ContentFixtures.newMedia();
    Mockito.when(this.contentService.getById(media.getId())).thenReturn(media);
    Mockito.when(this.contentService.getBinaryKey(media.getId(), media.getMediaAttachment().getBinaryReference())).thenReturn("binaryHash");
    // Process an html text containing a link to this content
    final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<p><figure class=\"editor-align-justify\"><img alt=\"Alt text\" src=\"image://" + media.getId() + "\"/><figcaption>Caption text</figcaption></figure></p>").imageWidths(List.of(660, 1024)).imageSizes("(max-width: 960px) 660px");
    // Checks that the page URL of the content is returned
    final String processedHtml = this.service.processHtml(params);
    assertEquals("<p><figure class=\"editor-align-justify\">" + "<img alt=\"Alt text\" src=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/width-768/mycontent\" " + "srcset=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/width-660/mycontent 660w," + "/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/width-1024/mycontent 1024w\" sizes=\"(max-width: 960px) 660px\"/><figcaption>Caption text</figcaption></figure></p>", processedHtml);
}
Also used : Media(com.enonic.xp.content.Media) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) Test(org.junit.jupiter.api.Test)

Example 3 with Media

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

the class PortalUrlServiceImpl_processHtmlTest method process_single_image.

@Test
public void process_single_image() {
    // Creates a content
    final Media media = ContentFixtures.newMedia();
    Mockito.when(this.contentService.getById(media.getId())).thenReturn(media);
    Mockito.when(this.contentService.getBinaryKey(media.getId(), media.getMediaAttachment().getBinaryReference())).thenReturn("binaryHash");
    // Process an html text containing a link to this content
    final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"image://" + media.getId() + "\">Image</a>");
    // Checks that the page URL of the content is returned
    final String processedHtml = this.service.processHtml(params);
    assertEquals("<a href=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/" + "width-768" + "/" + media.getName() + "\">Image</a>", processedHtml);
}
Also used : Media(com.enonic.xp.content.Media) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) Test(org.junit.jupiter.api.Test)

Example 4 with Media

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

the class PortalUrlServiceImpl_processHtmlTest method process_image_with_styles.

@Test
public void process_image_with_styles() {
    // Creates a content
    final Media media = ContentFixtures.newMedia();
    Mockito.when(this.contentService.getById(media.getId())).thenReturn(media);
    Mockito.when(this.contentService.getBinaryKey(media.getId(), media.getMediaAttachment().getBinaryReference())).thenReturn("binaryHash");
    final ImageStyle imageStyle = ImageStyle.create().name("mystyle").aspectRatio("2:1").filter("myfilter").build();
    final StyleDescriptor styleDescriptor = StyleDescriptor.create().application(ApplicationKey.from("myapp")).addStyleElement(imageStyle).build();
    Mockito.when(styleDescriptorService.getByApplications(Mockito.any())).thenReturn(StyleDescriptors.from(styleDescriptor));
    // Process an html text containing a style
    final String link1 = "<a href=\"image://" + media.getId() + "?style=mystyle\">Image</a>";
    final String link2 = "<a href=\"image://" + media.getId() + "?style=missingstyle\">Image</a>";
    final ProcessHtmlParams params1 = new ProcessHtmlParams().portalRequest(this.portalRequest).value(link1);
    final ProcessHtmlParams params2 = new ProcessHtmlParams().portalRequest(this.portalRequest).value(link2);
    final String processedLink1 = this.service.processHtml(params1);
    final String processedLink2 = this.service.processHtml(params2);
    // Checks that the page URL of the content is returned
    final String expectedResult1 = "<a href=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/" + "block-768-384" + "/" + media.getName() + "?filter=myfilter\">Image</a>";
    final String expectedResult2 = "<a href=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/" + "width-768" + "/" + media.getName() + "\">Image</a>";
    assertEquals(expectedResult1, processedLink1);
    assertEquals(expectedResult2, processedLink2);
}
Also used : StyleDescriptor(com.enonic.xp.style.StyleDescriptor) Media(com.enonic.xp.content.Media) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) ImageStyle(com.enonic.xp.style.ImageStyle) Test(org.junit.jupiter.api.Test)

Example 5 with Media

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

the class PortalUrlServiceImpl_processHtmlTest method process_image_with_scale.

@Test
public void process_image_with_scale() {
    // Creates a content
    final Media media = ContentFixtures.newMedia();
    Mockito.when(this.contentService.getById(media.getId())).thenReturn(media);
    Mockito.when(this.contentService.getBinaryKey(media.getId(), media.getMediaAttachment().getBinaryReference())).thenReturn("binaryHash");
    // Process an html text containing a link to this content
    final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"image://" + media.getId() + "?scale=21:9\">Image</a>");
    // Checks that the page URL of the content is returned
    final String processedHtml = this.service.processHtml(params);
    assertEquals("<a href=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/" + "block-768-324" + "/" + media.getName() + "\">Image</a>", processedHtml);
}
Also used : Media(com.enonic.xp.content.Media) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) Test(org.junit.jupiter.api.Test)

Aggregations

Media (com.enonic.xp.content.Media)19 Test (org.junit.jupiter.api.Test)7 Attachment (com.enonic.xp.attachment.Attachment)6 ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)5 ByteSource (com.google.common.io.ByteSource)5 ContentId (com.enonic.xp.content.ContentId)4 Content (com.enonic.xp.content.Content)3 ExtraData (com.enonic.xp.content.ExtraData)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 ImageOrientation (com.enonic.xp.media.ImageOrientation)3 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)2 BinaryReference (com.enonic.xp.util.BinaryReference)2 ContentService (com.enonic.xp.content.ContentService)1 CreateMediaParams (com.enonic.xp.content.CreateMediaParams)1 ThrottlingException (com.enonic.xp.exception.ThrottlingException)1 Cropping (com.enonic.xp.image.Cropping)1 ReadImageParams (com.enonic.xp.image.ReadImageParams)1 MediaInfo (com.enonic.xp.media.MediaInfo)1 PortalRequest (com.enonic.xp.portal.PortalRequest)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1