Search in sources :

Example 91 with Page

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);
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) SlingBindings(org.apache.sling.api.scripting.SlingBindings) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Resource(org.apache.sling.api.resource.Resource) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Page(com.day.cq.wcm.api.Page)

Example 92 with Page

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()));
}
Also used : Page(com.day.cq.wcm.api.Page) Test(org.junit.jupiter.api.Test)

Example 93 with Page

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()));
}
Also used : Page(com.day.cq.wcm.api.Page) Test(org.junit.jupiter.api.Test)

Example 94 with Page

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());
}
Also used : LinkImpl(com.adobe.cq.wcm.core.components.internal.link.LinkImpl) Page(com.day.cq.wcm.api.Page) Test(org.junit.jupiter.api.Test)

Example 95 with Page

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());
}
Also used : LinkImpl(com.adobe.cq.wcm.core.components.internal.link.LinkImpl) Page(com.day.cq.wcm.api.Page) Test(org.junit.jupiter.api.Test)

Aggregations

Page (com.day.cq.wcm.api.Page)100 Resource (org.apache.sling.api.resource.Resource)45 PageManager (com.day.cq.wcm.api.PageManager)34 Test (org.junit.jupiter.api.Test)22 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)18 ValueMap (org.apache.sling.api.resource.ValueMap)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)12 SlingBindings (org.apache.sling.api.scripting.SlingBindings)12 NotNull (org.jetbrains.annotations.NotNull)10 Test (org.junit.Test)9 HashSet (java.util.HashSet)6 Map (java.util.Map)6 Optional (java.util.Optional)6 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)6 Nullable (org.jetbrains.annotations.Nullable)6 LinkHandler (com.adobe.cq.wcm.core.components.internal.link.LinkHandler)5 Template (com.day.cq.wcm.api.Template)5 StringUtils (org.apache.commons.lang3.StringUtils)5 Before (org.junit.Before)5