use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SocialMediaHelperImplTest method getSocialMediaHelperUnderTest.
private SocialMediaHelper getSocialMediaHelperUnderTest(String pagePath) {
Resource currentResource = context.resourceResolver().getResource(pagePath);
Page currentPage = currentResource.adaptTo(Page.class);
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
request.setContextPath(CONTEXT_PATH);
request.setResource(currentResource);
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setExtension(EXTENSION);
requestPathInfo.setResourcePath(currentResource.getPath());
SlingBindings slingBindings = new SlingBindings();
slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
slingBindings.put(SlingBindings.RESOLVER, context.resourceResolver());
slingBindings.put(SlingBindings.RESPONSE, response);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(SocialMediaHelper.class);
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class DefaultPathProcessorTest method testVanityUrl.
@Test
void testVanityUrl() {
Page page = context.create().page("/content/links/site1/en", "/conf/example", ImmutableMap.of("sling:vanityPath", "vanity.html"));
DefaultPathProcessor underTest = context.registerInjectActivateService(new DefaultPathProcessor(), ImmutableMap.of("vanityConfig", DefaultPathProcessor.VanityConfig.MAPPING.getValue()));
assertTrue(underTest.accepts(page.getPath() + LinkHandler.HTML_EXTENSION, context.request()));
assertEquals("/content/links/site1/en.html", underTest.sanitize(page.getPath() + LinkHandler.HTML_EXTENSION, context.request()));
assertEquals("/vanity.html", underTest.map(page.getPath() + LinkHandler.HTML_EXTENSION, context.request()));
assertEquals("https://example.org/vanity.html", underTest.externalize(page.getPath() + LinkHandler.HTML_EXTENSION, context.request()));
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class DefaultPathProcessorTest method testVanityConfig.
@Test
void testVanityConfig() {
Page page = context.create().page("/content/links/site1/en", "/conf/example", ImmutableMap.of("sling:vanityPath", "vanity.html"));
DefaultPathProcessor underTest = context.registerInjectActivateService(new DefaultPathProcessor(), ImmutableMap.of("vanityConfig", "shouldBeDefault"));
assertEquals("/content/site1/en.html", underTest.map(page.getPath() + LinkHandler.HTML_EXTENSION, context.request()));
assertEquals("https://example.org/content/links/site1/en.html", underTest.externalize(page.getPath() + LinkHandler.HTML_EXTENSION, context.request()));
context.request().setContextPath("/cp");
underTest = context.registerInjectActivateService(new DefaultPathProcessor(), ImmutableMap.of("vanityConfig", DefaultPathProcessor.VanityConfig.ALWAYS.getValue()));
assertEquals("/cp/vanity.html", underTest.sanitize(page.getPath() + LinkHandler.HTML_EXTENSION, context.request()));
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LinkImplTest method testValidLinkWithTargetTargetPageAccessibilityLabelAndTitleAttribute.
@Test
void testValidLinkWithTargetTargetPageAccessibilityLabelAndTitleAttribute() {
Page page = mock(Page.class);
Link<Page> link = new LinkImpl<>(URL, URL, MockExternalizerFactory.ROOT + URL, page, new HashMap<String, String>() {
{
put(ATTR_TARGET, "_blank");
put(ATTR_ARIA_LABEL, "Url Label");
put(ATTR_TITLE, "Url Title");
}
});
assertValidLink(link, URL, "Url Label", "Url Title", "_blank");
assertSame(page, link.getReference());
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LinkImplTest method testValidLinkWithTargetPageAccessibilityLabelTitleAttributeAndWithoutTarget.
@Test
void testValidLinkWithTargetPageAccessibilityLabelTitleAttributeAndWithoutTarget() {
Page page = mock(Page.class);
Link<Page> link = new LinkImpl<>(URL, URL, MockExternalizerFactory.ROOT + URL, page, new HashMap<String, String>() {
{
put(ATTR_ARIA_LABEL, "Url Label");
put(ATTR_TITLE, "Url Title");
}
});
assertValidLink(link, URL, "Url Label", "Url Title", null);
assertSame(page, link.getReference());
}
Aggregations