diff --git a/src/test/java/io/wcm/handler/media/impl/ipeconfig/IPEConfigResourceProviderTest.java b/src/test/java/io/wcm/handler/media/impl/ipeconfig/IPEConfigResourceProviderTest.java index c13c6def..dc5c43ec 100644 --- a/src/test/java/io/wcm/handler/media/impl/ipeconfig/IPEConfigResourceProviderTest.java +++ b/src/test/java/io/wcm/handler/media/impl/ipeconfig/IPEConfigResourceProviderTest.java @@ -116,6 +116,7 @@ public Component answer(InvocationOnMock invocation) throws Throwable { when(mediaFormatHandler.getMediaFormat(SHOWROOM_STANDARD.getName())).thenReturn(SHOWROOM_STANDARD); when(mediaFormatHandler.getMediaFormat(NONFIXED_RAW.getName())).thenReturn(NONFIXED_RAW); } + @Test @SuppressWarnings("null") void testCustomIPEConfig() { diff --git a/src/test/java/io/wcm/handler/media/markup/MediaMarkupBuilderUtilTest.java b/src/test/java/io/wcm/handler/media/markup/MediaMarkupBuilderUtilTest.java index 5fb10126..e6ce25dc 100644 --- a/src/test/java/io/wcm/handler/media/markup/MediaMarkupBuilderUtilTest.java +++ b/src/test/java/io/wcm/handler/media/markup/MediaMarkupBuilderUtilTest.java @@ -25,6 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; +import java.util.Set; + import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; @@ -40,6 +42,9 @@ import com.day.cq.wcm.api.Page; import com.day.cq.wcm.api.PageManager; import com.day.cq.wcm.api.components.ComponentContext; +import com.day.cq.wcm.api.components.EditConfig; +import com.day.cq.wcm.api.components.EditContext; +import com.day.cq.wcm.api.components.InplaceEditingConfig; import io.wcm.handler.commons.dom.Image; import io.wcm.handler.media.Dimension; @@ -71,6 +76,14 @@ class MediaMarkupBuilderUtilTest { private SlingHttpServletRequest request; @Mock private ComponentContext componentContext; + @Mock + private Resource componentResource; + @Mock + private EditContext editContext; + @Mock + private EditConfig editConfig; + @Mock + private InplaceEditingConfig inplaceEditingConfig; @BeforeEach @SuppressWarnings("null") @@ -80,6 +93,13 @@ void setUp() throws Exception { when(request.getResource()).thenReturn(resource); when(pageManager.getContainingPage(resource)).thenReturn(page); when(request.getParameter(DiffService.REQUEST_PARAM_DIFF_TO)).thenReturn(VERSION_LABEL); + when(componentContext.getResource()).thenReturn(componentResource); + when(componentResource.getResourceResolver()).thenReturn(resolver); + when(componentContext.getEditContext()).thenReturn(editContext); + when(editContext.getEditConfig()).thenReturn(editConfig); + when(editConfig.getInplaceEditingConfig()).thenReturn(inplaceEditingConfig); + when(inplaceEditingConfig.getConfigPath()).thenReturn("/apps/components/comp1"); + when(inplaceEditingConfig.getEditorType()).thenReturn("image"); } @Test @@ -149,4 +169,36 @@ void testCanApplyDragDropSupport_DragDropSupport_Auto() { assertTrue(MediaMarkupBuilderUtil.canApplyDragDropSupport(mediaRequest, componentContext)); } + @Test + void testCanSetCustomIPECropRatios_ALWAYS() { + MediaRequest mediaRequest = new MediaRequest("/content/dam/path", new MediaArgs().ipeRatioCustomize(IPERatioCustomize.ALWAYS)); + assertTrue(MediaMarkupBuilderUtil.canSetCustomIPECropRatios(mediaRequest, componentContext)); + } + + @Test + void testCanSetCustomIPECropRatios_ALWAYS_CustomEditorType_Mismatch() { + when(inplaceEditingConfig.getEditorType()).thenReturn("custom"); + MediaRequest mediaRequest = new MediaRequest("/content/dam/path", new MediaArgs().ipeRatioCustomize(IPERatioCustomize.ALWAYS)); + assertFalse(MediaMarkupBuilderUtil.canSetCustomIPECropRatios(mediaRequest, componentContext)); + } + + @Test + void testCanSetCustomIPECropRatios_ALWAYS_CustomEditorType_Match() { + when(inplaceEditingConfig.getEditorType()).thenReturn("custom"); + MediaRequest mediaRequest = new MediaRequest("/content/dam/path", new MediaArgs().ipeRatioCustomize(IPERatioCustomize.ALWAYS)); + assertTrue(MediaMarkupBuilderUtil.canSetCustomIPECropRatios(mediaRequest, componentContext, Set.of("image", "custom"))); + } + + @Test + void testCanSetCustomIPECropRatios_NEVER() { + MediaRequest mediaRequest = new MediaRequest("/content/dam/path", new MediaArgs().ipeRatioCustomize(IPERatioCustomize.NEVER)); + assertFalse(MediaMarkupBuilderUtil.canSetCustomIPECropRatios(mediaRequest, componentContext)); + } + + @Test + void testCanSetCustomIPECropRatios_AUTO() { + MediaRequest mediaRequest = new MediaRequest("/content/dam/path", new MediaArgs().ipeRatioCustomize(IPERatioCustomize.AUTO)); + assertTrue(MediaMarkupBuilderUtil.canSetCustomIPECropRatios(mediaRequest, componentContext)); + } + }