use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LanguageNavigationSiteRootSelectionStrategyTest method testNoSiteRootOnIntermediatePage.
/**
* Intermediate pages exist, when a descendant got published but its parent not. They miss the jcr:content node
*/
@Test
void testNoSiteRootOnIntermediatePage() {
// given
Page page = aemContext.create().resource("/content/languagenavigation/LOCALE-X/LOCALE-Y", "jcr:primaryType", "cq:Page").adaptTo(Page.class);
// when
Page siteRoot = subject.getSiteRoot(page);
int structureDepth = subject.getStructuralDepth(page);
// then
assertNull(siteRoot);
assertEquals(1, structureDepth);
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LanguageNavigationSiteRootSelectionStrategyTest method testSiteRootFromPageWithExperienceFragment.
@Test
void testSiteRootFromPageWithExperienceFragment() {
// given
Page page = aemContext.create().page("/content/languagenavigation/LOCALE-1/LOCALE-5/about-2");
Page variant = aemContext.create().page("/content/experience-fragments/fragment/master", "xf", ExperienceFragmentsConstants.PN_XF_VARIANT_TYPE, "web");
String contentPath = page.getContentResource().getPath();
Resource pageRoot = aemContext.create().resource(contentPath + "/root");
Resource pageRootXf = aemContext.create().resource(contentPath + "/root/xf", "sling:resourceType", ExperienceFragmentImpl.RESOURCE_TYPE_V2, ExperienceFragment.PN_FRAGMENT_VARIATION_PATH, variant.getPath());
String variantContentPath = variant.getContentResource().getPath();
Resource variantRoot = aemContext.create().resource(variantContentPath + "/root");
Resource variantRootLanguageNav = aemContext.create().resource(variantContentPath + "/root/languageNavigation", "sling:resourceType", LanguageNavigationImpl.RESOURCE_TYPE, LanguageNavigation.PN_NAVIGATION_ROOT, "/content/languagenavigation", LanguageNavigation.PN_STRUCTURE_DEPTH, 3);
// when
Page siteRoot = subject.getSiteRoot(page);
int structureDepth = subject.getStructuralDepth(page);
// then
assertNotNull(siteRoot);
assertEquals("/content/languagenavigation", siteRoot.getPath());
assertEquals(3, structureDepth);
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LanguageNavigationSiteRootSelectionStrategyTest method testNoSiteRootFallbackToDefault.
@Test
void testNoSiteRootFallbackToDefault() throws PersistenceException, NoSuchFieldException, IllegalAccessException {
// given
// replace with service injection after SLING-10616 was released
DefaultSiteRootSelectionStrategy defaultSiteRootSelectionStrategy = spy(new DefaultSiteRootSelectionStrategy());
Field defaultSelectionStrategy = subject.getClass().getDeclaredField("defaultSelectionStrategy");
defaultSelectionStrategy.setAccessible(true);
defaultSelectionStrategy.set(subject, defaultSiteRootSelectionStrategy);
Page page = aemContext.pageManager().getPage("/content/languagenavigation/LOCALE-1/LOCALE-5/about");
deleteSiblings(page.getContentResource().getChild("root/languagenavigation-component-4"));
// when
Page siteRoot = subject.getSiteRoot(page);
int structureDepth = subject.getStructuralDepth(page);
// then
assertEquals("/content/languagenavigation", siteRoot.getPath());
assertEquals(2, structureDepth);
verify(defaultSiteRootSelectionStrategy).getSiteRoot(page);
verify(defaultSiteRootSelectionStrategy).getStructuralDepth(page);
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LanguageNavigationSiteRootSelectionStrategyTest method testNoSiteRootOnPageWithoutLanguageNav.
@Test
void testNoSiteRootOnPageWithoutLanguageNav() {
// given
Page page = aemContext.create().page("/content/languagenavigation/LOCALE-X/LOCALE-Y");
aemContext.create().resource(page, "root");
aemContext.create().resource(page, "anyComponent");
// when
Page siteRoot = subject.getSiteRoot(page);
int structureDepth = subject.getStructuralDepth(page);
// then
assertNull(siteRoot);
assertEquals(1, structureDepth);
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LanguageNavigationSiteRootSelectionStrategyTest method testSiteRootFromPageWithDefaultStructureDepth.
@Test
void testSiteRootFromPageWithDefaultStructureDepth() throws PersistenceException {
// given
Page page = aemContext.pageManager().getPage("/content/languagenavigation/LOCALE-1/LOCALE-5/about");
deleteSiblings(page.getContentResource().getChild("root/languagenavigation-component-1"));
// when
Page siteRoot = subject.getSiteRoot(page);
int structureDepth = subject.getStructuralDepth(page);
// then
assertNotNull(siteRoot);
assertEquals("/content/languagenavigation", siteRoot.getPath());
assertEquals(1, structureDepth);
}
Aggregations