use of com.enonic.xp.portal.url.ProcessHtmlParams 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.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method assertProcessHtml.
private void assertProcessHtml(String inputName, String expectedOutputName) throws IOException {
final String input;
final String expected;
// Reads the input and output files
try (InputStream is = this.getClass().getResourceAsStream(inputName)) {
input = new String(is.readAllBytes(), StandardCharsets.UTF_8);
}
try (InputStream is = this.getClass().getResourceAsStream(expectedOutputName)) {
expected = new String(is.readAllBytes(), StandardCharsets.UTF_8);
}
// Processes the input file
final ProcessHtmlParams processHtmlParams = new ProcessHtmlParams().value(input);
final String processedHtml = this.service.processHtml(processHtmlParams);
// Checks that the processed text is equal to the expected output
assertEquals(expected, processedHtml);
}
use of com.enonic.xp.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_absolute.
@Test
public void process_absolute() {
// Creates a content
final Content content = ContentFixtures.newContent();
Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
// Process an html text containing a link to this content
final ProcessHtmlParams params = new ProcessHtmlParams().type(UrlTypeConstants.ABSOLUTE).portalRequest(this.portalRequest).value("<a href=\"content://" + content.getId() + "\">Content</a>");
when(req.getServerName()).thenReturn("localhost");
when(req.getScheme()).thenReturn("http");
when(req.getServerPort()).thenReturn(80);
// Checks that the page URL of the content is returned
final String processedHtml = this.service.processHtml(params);
assertEquals("<a href=\"http://localhost/site/default/draft" + content.getPath() + "\">Content</a>", processedHtml);
}
use of com.enonic.xp.portal.url.ProcessHtmlParams 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.portal.url.ProcessHtmlParams in project xp by enonic.
the class PortalUrlServiceImpl_processHtmlTest method process_unknown_media.
@Test
public void process_unknown_media() {
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 media
final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"media://inline/123\">Media</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\">Media</a>", processedHtml);
}
Aggregations