Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experience Fragment] XF variantion is not loaded for localized content when the fragmentVariationPath is not accesible #1517

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -287,7 +287,6 @@ private LinkedHashMap<String, ComponentExporter> getChildren() {
@Nullable
private String getXfLocalizationRoot(@Nullable final String xfPath, @Nullable final String currentPageRoot) {
if (StringUtils.isNotEmpty(xfPath) && StringUtils.isNotEmpty(currentPageRoot)
&& this.request.getResourceResolver().getResource(xfPath) != null
&& this.request.getResourceResolver().getResource(currentPageRoot) != null) {
String[] xfPathTokens = Text.explode(xfPath, PATH_DELIMITER_CHAR);
int xfRootDepth = Text.explode(currentPageRoot, PATH_DELIMITER_CHAR).length + 1;
Expand Down
Expand Up @@ -350,6 +350,20 @@ void testEmptyXFInTemplateWithLocalization() {
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf13"));
}

/**
* Site with language localization
* XF component is defined in the template
* XF component points to a different language branch as the page.
* fragmentVariationPath is undefined, but it is defined in the page language branch
*/
@Test
void testUndefinedXFInTemplateWithLocalizationDefinedInPageLanguageBranch() {
ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(
PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-14", EN_PAGE);
assertEquals(XF_NAME, experienceFragment.getName());
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf14"));
}


/* ------------------------------- Tests for a site with country/language localization (us/en) ----------------- */

Expand Down Expand Up @@ -430,6 +444,19 @@ void testUndefinedXFInTemplateWithLocalizationWithDifferentCountryLanguage() {
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf22"));
}

/**
* Site with country-language localization
* XF component is defined in the template
* XF component points to a different language branch as the page.
* fragmentVariationPath is undefined, but it is defined in the page language branch
*/
@Test
void testUndefinedXFInTemplateWithLocalizationWithDifferentCountryLanguageDefinedInPageLanguageBranch() {
ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(
PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-23", US_EN_PAGE);
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf23"));
}


/* ----------------- Tests for a site with country-language localization (eu/mysite/en) ----------------------- */

Expand Down Expand Up @@ -510,6 +537,19 @@ void testUndefinedXFInTemplateWithLocalizationWithDifferentCountrySiteLanguage()
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf32"));
}

/**
* Site with country-language localization (optional): eu/mysite/en
* XF component is defined in the template
* XF component points to a different language branch as the page.
* fragmentVariationPath is undefined, but it is defined in the page language branch
*/
@Test
void testUndefinedXFInTemplateWithLocalizationWithDifferentCountrySiteLanguageDefinedInPageLanguageBranch() {
ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(
PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-33", CH_MYSITE_FR_PAGE);
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf33"));
}


/* ------------------------------- Tests for a site with country_language localization (ch_fr) ----------------- */

Expand Down Expand Up @@ -698,6 +738,20 @@ void testValidXFInTemplateWithLocalizationWithDifferentLivecopy() {
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf61a"));
}

/**
* Site with region localization (current page is a livecopy)
* XF component is defined in the template
* XF component points to a different region branch as the page
* fragmentVariationPath is undefined, but it is defined in the livecopy page
*/
@Test
void testUndefinedXFInTemplateWithLocalizationWithDifferentLivecopyDefinedInLivecopyPage() {
ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(
PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-62", LIVECOPY_PAGE);
assertEquals(XF_NAME, experienceFragment.getName());
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf62"));
}


/* ------------------------------- private stuff ----------------------------------------- */

Expand Down
@@ -0,0 +1,8 @@
{
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/en/footer/definedInEn/jcr:content",
"configured": false,
":itemsOrder": [],
":items": {},
"classNames": "aem-xf empty",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
@@ -0,0 +1,8 @@
{
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/us/en/footer/definedInUsEn/jcr:content",
"configured": false,
":itemsOrder": [],
":items": {},
"classNames": "aem-xf empty",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
@@ -0,0 +1,8 @@
{
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/ch/mysite/fr/footer/definedInChMysiteFr/jcr:content",
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
"classNames": "aem-xf empty",
":itemsOrder": [],
":items": {}
}
@@ -0,0 +1,8 @@
{
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/livecopy/footer/definedInLiveCopy/jcr:content",
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
"classNames": "aem-xf empty",
":itemsOrder": [],
":items": {}
}
20 changes: 20 additions & 0 deletions bundles/core/src/test/resources/experiencefragment/test-conf.json
Expand Up @@ -67,6 +67,11 @@
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment"
},
"xf-component-14": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
"fragmentVariationPath": "/content/experience-fragments/mysite/es/footer/definedInEn"
},
"xf-component-20a": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
Expand All @@ -82,6 +87,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/us/es/footer/definedInUsEn"
},
"xf-component-30a": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
Expand All @@ -97,6 +107,11 @@
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
"fragmentVariationPath": "/content/experience-fragments/mysite/ch/mysite/en/footer/master/undefined"
},
"xf-component-33": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
"fragmentVariationPath": "/content/experience-fragments/mysite/ch/mysite/de/footer/definedInChMysiteFr"
},
"xf-component-40a": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
Expand Down Expand Up @@ -131,6 +146,11 @@
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
"fragmentVariationPath": "/content/experience-fragments/mysite/blueprint/footer/master"
},
"xf-component-62": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/wcm/components/experiencefragment/v1/experiencefragment",
"fragmentVariationPath": "/content/experience-fragments/mysite/blueprint/footer/definedInLiveCopy"
}
}
}
Expand Down
Expand Up @@ -310,8 +310,16 @@
"jcr:content": {
"cq:xfVariantType": "web",
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer Variation"}

"jcr:title": "English Test Footer Variation"
}
},
"definedInUsEn": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"cq:xfVariantType": "web",
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer Variation - Defined in us/en but not in us/es"
}
}
}
},
Expand Down Expand Up @@ -365,8 +373,16 @@
"jcr:content": {
"cq:xfVariantType": "web",
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer Variation"}

"jcr:title": "English Test Footer Variation"
}
},
"definedInChMysiteFr": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"cq:xfVariantType": "web",
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer Variation - Defined in ch/mysite/fr but not in ch/mysite/de"
}
}
}
},
Expand Down Expand Up @@ -509,8 +525,15 @@
"jcr:content": {
"cq:xfVariantType": "web",
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer Variation"}

"jcr:title": "English Test Footer Variation"
}
},
"definedInEn": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"cq:xfVariantType": "web",
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer Variation - Defined in en but not in es"}
}
}
},
Expand Down Expand Up @@ -632,6 +655,14 @@
"cq:xfVariantType": "web",
"cq:xfMasterVariation": "true"
}
},
"definedInLiveCopy": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"cq:xfVariantType": "web",
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English Test Footer Variation - Defined in Livecopy"}

}
}
}
Expand Down