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