Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Sep 4, 2023
1 parent 6959eff commit 0bfa813
Show file tree
Hide file tree
Showing 5 changed files with 486 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private void activate() {
// resolve media and properties from DAM asset
ComponentFeatureImageResolver imageResolver = new ComponentFeatureImageResolver(resource, getCurrentPage(), currentStyle, mediaHandler)
.targetPage(link.getLinkObject().getTargetPage())
.altValueFromDam(altFromAsset)
.mediaHandlerProperty(PROP_CSS_CLASS, "cmp-image__image")
.mediaHandlerProperty("itemprop", "contentUrl");
String imageTitle = title;
Expand All @@ -152,10 +153,6 @@ private void activate() {
}
media = imageResolver.buildMedia();

media = HandlerUnwrapper.get(mediaHandler, resource)
.decorative(isDecorative)
.forceAltValueFromAsset(altFromAsset)
.build();
if (media.isValid() && !media.getRendition().isImage()) {
// no image asset selected (cannot be rendered) - set to invalid
media = mediaHandler.invalid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ComponentFeatureImageResolver {

private final boolean imageFromPageImage;
private final boolean altValueFromPageImage;
private final boolean altValueFromDam;
private boolean altValueFromDam;
private final boolean isDecorative;
private final String componentAltText;

Expand Down Expand Up @@ -105,6 +105,15 @@ public ComponentFeatureImageResolver mediaHandlerProperty(@NotNull String key, @
return this;
}

/**
* @param value Alt Value from DAM
* @return self
*/
public ComponentFeatureImageResolver altValueFromDam(boolean value) {
this.altValueFromDam = value;
return this;
}

/**
* Build media after resolving feature images and alt. texts.
* @return Media
Expand Down Expand Up @@ -167,6 +176,7 @@ else if (!(altValueFromPageImage || altValueFromDam)) {
// otherwise rely to default media handler behavior
builder.altText(componentAltText);
}
builder.forceAltValueFromAsset(altValueFromDam);

// apply custom media handling properties
mediaHandlerProperties.entrySet().forEach(entry -> builder.property(entry.getKey(), entry.getValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void testWithUploadedImage() {
}

@Test
@SuppressWarnings({ "null", "deprecation" })
@SuppressWarnings("deprecation")
void testWithImageAndLink() {
enableDataLayer(context, true);

Expand Down
Loading

0 comments on commit 0bfa813

Please sign in to comment.