use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method processHtml_image_imageWidths.
@Test
public void processHtml_image_imageWidths() {
// 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(" ");
// 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\"/><figcaption>Caption text</figcaption></figure></p>", processedHtml);
}
use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_multiple_links.
@Test
public void process_multiple_links() {
// Creates a content with attachments
final Attachment thumb = Attachment.create().label("thumb").name("a1.jpg").mimeType("image/jpg").build();
final Attachment source = Attachment.create().label("source").name("a2.jpg").mimeType("image/jpg").build();
final Attachments attachments = Attachments.from(thumb, source);
final Content content = Content.create(ContentFixtures.newContent()).attachments(attachments).build();
Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
Mockito.when(this.contentService.getBinaryKey(content.getId(), source.getBinaryReference())).thenReturn("binaryHash2");
// Process an html text containing multiple links, on multiple lines, to this content as a media and as a content
final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<p>A content link: <a href=\"content://" + content.getId() + "\">FirstLink</a></p>\n" + "<p>A second content link: <a href=\"content://" + content.getId() + "\">SecondLink</a>" + " and a download link: <a href=\"media://download/" + content.getId() + "\">Download</a></p>\n" + "<p>An external link: <a href=\"http://www.enonic.com\">An external link</a></p>\n" + "<p> </p>\n" + "<a href=\"media://inline/" + content.getId() + "\">Inline</a>");
// Checks the returned value
final String processedHtml = this.service.processHtml(params);
assertEquals("<p>A content link: <a href=\"/site/default/draft" + content.getPath() + "\">FirstLink</a></p>\n" + "<p>A second content link: <a href=\"/site/default/draft" + content.getPath() + "\">SecondLink</a>" + " and a download link: <a href=\"/site/default/draft/context/path/_/attachment/download/" + content.getId() + ":binaryHash2/" + source.getName() + "\">Download</a></p>\n" + "<p>An external link: <a href=\"http://www.enonic.com\">An external link</a></p>\n" + "<p> </p>\n" + "<a href=\"/site/default/draft/context/path/_/attachment/inline/" + content.getId() + ":binaryHash2/" + source.getName() + "\">Inline</a>", processedHtml);
}
use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_unknown_content.
@Test
public void process_unknown_content() {
when(contentService.getById(isA(ContentId.class))).thenAnswer((params) -> {
final ContentId id = params.getArgument(0);
throw new ContentNotFoundException(id, ContextAccessor.current().getBranch());
});
// Process an html text containing a link to an unknown content
final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"content://123\">Content</a>");
// Checks that the error 500 page is returned
final String processedHtml = this.service.processHtml(params);
assertEquals("<a href=\"/site/default/draft/context/path/_/error/404?message=Content+with+id+%5B123%5D+was+not+found+in+branch+%5Bdraft%5D\">Content</a>", processedHtml);
}
use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_empty_value.
@Test
public void process_empty_value() {
// Checks the process for a null value
final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest);
String processedHtml = this.service.processHtml(params);
assertEquals("", processedHtml);
// Checks the process for an empty string value
params.value("");
processedHtml = this.service.processHtml(params);
assertEquals("", processedHtml);
}
use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_single_media.
@Test
public void process_single_media() {
// Creates a content with attachments
final Attachment thumb = Attachment.create().label("thumb").name("a1.jpg").mimeType("image/jpg").build();
final Attachment source = Attachment.create().label("source").name("a2.jpg").mimeType("image/jpg").build();
final Attachments attachments = Attachments.from(thumb, source);
final Content content = Content.create(ContentFixtures.newContent()).attachments(attachments).build();
Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
Mockito.when(this.contentService.getBinaryKey(content.getId(), source.getBinaryReference())).thenReturn("binaryHash2");
// Process an html text containing an inline link to this content
ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"media://inline/" + content.getId() + "\">Media</a>");
// Checks that the URL of the source attachment of the content is returned
String processedHtml = this.service.processHtml(params);
assertEquals("<a href=\"/site/default/draft/context/path/_/attachment/inline/" + content.getId() + ":binaryHash2/" + source.getName() + "\">Media</a>", processedHtml);
// Process an html text containing a download link to this content
params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"media://download/" + content.getId() + "\">Media</a>");
// Checks that the URL of the source attachment of the content is returned
processedHtml = this.service.processHtml(params);
assertEquals("<a href=\"/site/default/draft/context/path/_/attachment/download/" + content.getId() + ":binaryHash2/" + source.getName() + "\">Media</a>", processedHtml);
// Process an html text containing an inline link to this content in a img tag
params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"/some/page\"><img src=\"media://inline/" + content.getId() + "\">Media</a>");
// Checks that the URL of the source attachment of the content is returned
processedHtml = this.service.processHtml(params);
assertEquals("<a href=\"/some/page\"><img src=\"/site/default/draft/context/path/_/attachment/inline/" + content.getId() + ":binaryHash2/" + source.getName() + "\">Media</a>", processedHtml);
}
Aggregations