Search in sources :

Example 11 with ProcessHtmlParams

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);
}
Also used : Media(com.enonic.xp.content.Media) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) Test(org.junit.jupiter.api.Test)

Example 12 with ProcessHtmlParams

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:&nbsp;<a href=\"content://" + content.getId() + "\">FirstLink</a></p>\n" + "<p>A second content link:&nbsp;<a href=\"content://" + content.getId() + "\">SecondLink</a>" + "&nbsp;and a download link:&nbsp;<a href=\"media://download/" + content.getId() + "\">Download</a></p>\n" + "<p>An external link:&nbsp;<a href=\"http://www.enonic.com\">An external  link</a></p>\n" + "<p>&nbsp;</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:&nbsp;<a href=\"/site/default/draft" + content.getPath() + "\">FirstLink</a></p>\n" + "<p>A second content link:&nbsp;<a href=\"/site/default/draft" + content.getPath() + "\">SecondLink</a>" + "&nbsp;and a download link:&nbsp;<a href=\"/site/default/draft/context/path/_/attachment/download/" + content.getId() + ":binaryHash2/" + source.getName() + "\">Download</a></p>\n" + "<p>An external link:&nbsp;<a href=\"http://www.enonic.com\">An external  link</a></p>\n" + "<p>&nbsp;</p>\n" + "<a href=\"/site/default/draft/context/path/_/attachment/inline/" + content.getId() + ":binaryHash2/" + source.getName() + "\">Inline</a>", processedHtml);
}
Also used : Content(com.enonic.xp.content.Content) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) Attachment(com.enonic.xp.attachment.Attachment) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Example 13 with ProcessHtmlParams

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);
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 14 with ProcessHtmlParams

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);
}
Also used : ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) Test(org.junit.jupiter.api.Test)

Example 15 with ProcessHtmlParams

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);
}
Also used : Content(com.enonic.xp.content.Content) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) Attachment(com.enonic.xp.attachment.Attachment) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)15 Test (org.junit.jupiter.api.Test)13 Media (com.enonic.xp.content.Media)5 Content (com.enonic.xp.content.Content)4 ContentId (com.enonic.xp.content.ContentId)3 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)3 Attachment (com.enonic.xp.attachment.Attachment)2 Attachments (com.enonic.xp.attachment.Attachments)2 PortalResponse (com.enonic.xp.portal.PortalResponse)1 RenderMode (com.enonic.xp.portal.RenderMode)1 ImageStyle (com.enonic.xp.style.ImageStyle)1 StyleDescriptor (com.enonic.xp.style.StyleDescriptor)1 InputStream (java.io.InputStream)1