Skip to content

Commit

Permalink
[SITES-21656] OOTB Experience Fragment Localization Issue for /eu/fr …
Browse files Browse the repository at this point in the history
…Site
  • Loading branch information
Alexandru Marian Stancioiu committed May 16, 2024
1 parent afb6dda commit 70a7b4f
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static String getLocalizationRoot(@NotNull Resource resource, @NotNull Re
*/
@Nullable
public static String getLanguageRoot(@NotNull Resource resource, @NotNull LanguageManager languageManager) {
return Optional.ofNullable(languageManager.getLanguageRoot(resource))
return Optional.ofNullable(languageManager.getLanguageRoot(resource, true))
.map(Page::getPath)
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public static AemContext newAemContext() {
.resourceResolverType(ResourceResolverType.JCR_MOCK)
.resourceResolverFactoryActivatorProps(PROPERTIES)
.<AemContext>afterSetUp(context -> {
context.addModelsForClasses(MockResponsiveGrid.class);
context.addModelsForPackage("com.adobe.cq.wcm.core.components.models");
context.addModelsForPackage("com.adobe.cq.wcm.core.components.internal.link");
context.registerService(SlingModelFilter.class, new MockSlingModelFilter() {
private final Set<String> IGNORED_NODE_NAMES = new HashSet<String>() {{
add(NameConstants.NN_RESPONSIVE_CONFIG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ExperienceFragmentImplTest {
private static final String US_EN_PAGE = SITE_ROOT + "/us/en/page";
private static final String CH_MYSITE_FR_PAGE = SITE_ROOT + "/ch/mysite/fr/page";
private static final String CH_FR_PAGE = SITE_ROOT + "/ch_fr/page";
private static final String EU_FR_PAGE = SITE_ROOT + "/eu/fr/page";
private static final String BLUEPRINT_ROOT = "/content/mysite/blueprint";
private static final String BLUEPRINT_PAGE = BLUEPRINT_ROOT + "/page";
private static final String LIVECOPY_ROOT = "/content/mysite/livecopy";
Expand Down Expand Up @@ -555,6 +556,23 @@ void testValidXFInPageWithLocalizationWithDifferentCountry_Language() {
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf41"));
}

/**
* Site with region/language localization
* XF component is defined in the template
* XF component points to a different region/language branch as the page
* and system cannot infer correctly the language root unless page is marked with
* "cq:isLanguageRoot": true
* and
* "jcr:language": "fr"
*/
@Test
void testValidXFInPageWithLocalizationWithDifferentCountry_Language_withLanguageRootMarking() {

ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-23", EU_FR_PAGE);
assertEquals(XF_NAME, experienceFragment.getName());
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf23"));
}

/**
* Site with country_language localization
* XF component is defined in the template
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "experiencefragment-8920b315ce",
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/eu/fr/footer/master/jcr:content",
"configured": false,
"classNames": "aem-xf empty",
":items": {},
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
":itemsOrder": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
"fragmentVariationPath": "/content/experience-fragments/mysite/us/en/footer/master/undefined"
},
"xf-component-23": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
"fragmentVariationPath": "/content/experience-fragments/mysite/language-masters/en/footer/master"
},
"xf-component-30a": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
Expand Down Expand Up @@ -147,4 +152,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,36 @@
}
}
},
"eu": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "Europe",
"jcr:created": "Mon APR 08 2019 20:21:55 GMT+0200"
},
"fr": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "Français",
"jcr:created": "Mon APR 08 2019 20:21:55 GMT+0200",
"cq:isLanguageRoot": true,
"jcr:language": "fr"
},
"page": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "Test page",
"jcr:created": "Mon APR 08 2019 20:21:55 GMT+0200",
"cq:template": "/conf/coretest/settings/wcm/templates/product-page",
"root": {
"jcr:primaryType": "nt:unstructured"
}
}
}
}
},
"ch": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
Expand Down Expand Up @@ -303,6 +333,53 @@
"sling:resourceType": "cq/experience-fragments/components/experiencefragment"
}
},
"language-masters": {
"en": {
"jcr:primaryType": "sling:Folder",
"footer": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer",
"jcr:created": "Mon APR 08 2019 20:21:55 GMT+0200",
"sling:resourceType": "cq/experience-fragments/components/experiencefragment"
},
"master": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer Master",
"cq:xfVariantType": "web",
"cq:xfMasterVariation": "true"
}
}
}
}
},
"eu": {
"jcr:primaryType": "sling:Folder",
"fr": {
"jcr:primaryType": "sling:Folder",
"footer": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer",
"jcr:created": "Mon APR 08 2019 20:21:55 GMT+0200",
"sling:resourceType": "cq/experience-fragments/components/experiencefragment"
},
"master": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer Master",
"cq:xfVariantType": "web",
"cq:xfMasterVariation": "true"
}
}
}
}
},
"us": {
"jcr:primaryType": "sling:Folder",
"en": {
Expand Down Expand Up @@ -703,4 +780,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ private AmpTestContext() {
public static io.wcm.testing.mock.aem.junit5.AemContext newAemContext() {
return new AemContextBuilder().resourceResolverType(ResourceResolverType.JCR_MOCK)
.<io.wcm.testing.mock.aem.junit5.AemContext>afterSetUp(context -> {
context.addModelsForClasses(MockResponsiveGrid.class);
context.registerService(SlingModelFilter.class, new MockSlingModelFilter() {
private final Set<String> IGNORED_NODE_NAMES = new HashSet<String>() {{
add(NameConstants.NN_RESPONSIVE_CONFIG);
Expand Down
2 changes: 1 addition & 1 deletion parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>5.1.0</version>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit 70a7b4f

Please sign in to comment.