Skip to content

Commit 1250092

Browse files
authored
Unit test: Teaser with inherited feature image and media options policies (#36)
1 parent 28fc5b6 commit 1250092

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Diff for: bundles/core/src/test/java/io/wcm/wcm/core/components/impl/models/v2/TeaserV2ImplTest.java

+36
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
import static io.wcm.handler.link.LinkNameConstants.PN_LINK_EXTERNAL_REF;
4141
import static io.wcm.handler.link.LinkNameConstants.PN_LINK_TYPE;
4242
import static io.wcm.handler.link.LinkNameConstants.PN_LINK_WINDOW_TARGET;
43+
import static io.wcm.handler.media.MediaNameConstants.NN_COMPONENT_MEDIA_RESPONSIVEIMAGE_SIZES;
4344
import static io.wcm.handler.media.MediaNameConstants.PN_COMPONENT_MEDIA_AUTOCROP;
4445
import static io.wcm.handler.media.MediaNameConstants.PN_COMPONENT_MEDIA_FORMATS;
46+
import static io.wcm.handler.media.MediaNameConstants.PN_COMPONENT_MEDIA_RESPONSIVE_TYPE;
4547
import static io.wcm.handler.media.MediaNameConstants.PN_MEDIA_REF_STANDARD;
4648
import static io.wcm.wcm.core.components.impl.models.helpers.DataLayerTestUtils.enableDataLayer;
4749
import static io.wcm.wcm.core.components.impl.models.v2.TeaserV2Impl.RESOURCE_TYPE;
@@ -69,6 +71,7 @@
6971
import com.adobe.cq.wcm.core.components.models.datalayer.ComponentData;
7072
import com.day.cq.dam.api.Asset;
7173
import com.day.cq.wcm.api.Page;
74+
import com.day.cq.wcm.api.policies.ContentPolicyMapping;
7275

7376
import io.wcm.handler.link.type.ExternalLinkType;
7477
import io.wcm.handler.link.type.InternalLinkType;
@@ -199,6 +202,39 @@ void testTitleDescriptionImageFromPage() {
199202
assertValidMedia(underTest, "/content/dam/sample/sample.jpg/_jcr_content/renditions/original./sample.jpg");
200203
}
201204

205+
@Test
206+
void testTitleDescriptionImageFromPage_WithContentPolicy() {
207+
Page targetPage = context.create().page(page, "page1", null,
208+
JCR_TITLE, "Page Title",
209+
JCR_DESCRIPTION, "Page Description");
210+
context.create().resource(targetPage, NN_PAGE_FEATURED_IMAGE,
211+
PN_MEDIA_REF_STANDARD, asset.getPath());
212+
context.currentResource(context.create().resource(page, "teaser",
213+
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
214+
JCR_TITLE, "Teaser Title",
215+
JCR_DESCRIPTION, "Teaser Description",
216+
PN_LINK_TYPE, InternalLinkType.ID,
217+
PN_LINK_CONTENT_REF, targetPage.getPath(),
218+
PN_TITLE_FROM_PAGE, true,
219+
PN_DESCRIPTION_FROM_PAGE, true,
220+
PN_IMAGE_FROM_PAGE_IMAGE, true,
221+
PN_ALT_VALUE_FROM_PAGE_IMAGE, true));
222+
223+
ContentPolicyMapping policyMapping = context.contentPolicyMapping(RESOURCE_TYPE,
224+
JCR_TITLE, "Teaser Mock Policy",
225+
PN_COMPONENT_MEDIA_FORMATS, MediaFormats.SQUARE.getName(),
226+
PN_COMPONENT_MEDIA_AUTOCROP, Boolean.TRUE,
227+
PN_COMPONENT_MEDIA_RESPONSIVE_TYPE, "imageSizes");
228+
context.create().resource(policyMapping.getPolicy().getPath() + "/" + NN_COMPONENT_MEDIA_RESPONSIVEIMAGE_SIZES,
229+
"widths", "45,90");
230+
231+
Teaser underTest = AdaptTo.notNull(context.request(), Teaser.class);
232+
233+
assertEquals("Page Title", underTest.getTitle());
234+
assertEquals("Page Description", underTest.getDescription());
235+
assertValidMedia(underTest, "/content/dam/sample/sample.jpg/_jcr_content/renditions/original.image_file.90.90.35,0,125,90.file/sample.jpg");
236+
}
237+
202238
@Test
203239
void testTitleDescriptionFromPage_HtmlReservedChars() {
204240
Page targetPage = context.create().page(page, "page1", null,

0 commit comments

Comments
 (0)