HTMLImageAttachmentElementReplacer implements AttachmentElementReplacer { @Override public String replace(String originalImgHtmlElement, FileEntry fileEntry) { Element element = _toElement(originalImgHtmlElement); String fileEntryURL = _portletFileRepository.getPortletFileEntryURL( null, fileEntry, StringPool.BLANK); element.attr("src", fileEntryURL); element.removeAttr(EditorConstants.ATTRIBUTE_DATA_IMAGE_ID); return element.toString(); }  @Override String replace(String originalImgHtmlElement, FileEntry fileEntry);  }
@Test public void testKeepsCustomAttributes() throws Exception { String originalImgTag = String.format( "<img class=\"custom\" data-image-id=\"%s\" src=\"%s\" />", _IMAGE_FILE_ENTRY_ID, StringUtil.randomString()); String expectedImgTag = String.format( "<img class=\"custom\" src=\"%s\" />", _FILE_ENTRY_IMAGE_URL); String actualTag = _htmlImageAttachmentElementReplacer.replace( originalImgTag, _fileEntry); Assert.assertEquals(expectedImgTag, actualTag); }
@Test public void testRemovesTemporalAttributeAndSetsFinalSrc() throws Exception { String originalImgTag = String.format( "<img data-image-id=\"%s\" src=\"%s\" />", _IMAGE_FILE_ENTRY_ID, StringUtil.randomString()); String expectedImgTag = String.format( "<img src=\"%s\" />", _FILE_ENTRY_IMAGE_URL); String actualTag = _htmlImageAttachmentElementReplacer.replace( originalImgTag, _fileEntry); Assert.assertEquals(expectedImgTag, actualTag); }