Skip to content

Commit

Permalink
Merge branch 'main' into sites_22335_2
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandru-stancioiu committed Jun 27, 2024
2 parents a0d2011 + 90a8cfa commit 6514f5b
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ private Page getLocalizedPage(Page page, Page languageRoot) {
Page localizedPage;
String path = languageRoot.getPath();
String relativePath = page.getPath();
if (relativePath.startsWith(path)) {
int indexOfStart = 0;
if (path.length() < relativePath.length()) {
indexOfStart = path.length();
}
if (relativePath.startsWith(path) &&
relativePath.charAt(indexOfStart) == '/') {
localizedPage = page;
} else {
String separator = "/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public class LanguageNavigationImplTest {
"/content/languagenavigation/LOCALE-4/LOCALE-9.html"},
};

private static final Object[][] EXPECTED_COUNTRY_LIST = {
{"/content/countrytest/languagenavigation/ch", "ch", false, 0, "", "ch",
"/ch-3-vanity"},
{"/content/countrytest/languagenavigation/ch_zn", "ch_zn", true, 0, "", "ch",
"/ch_zn-3-vanity"},
{"/content/countrytest/languagenavigation/en", "en", false, 0, "", "en", "/en-3-vanity"},
};

protected final AemContext context = CoreComponentTestContext.newAemContext();

protected String testBase;
Expand Down Expand Up @@ -152,6 +160,15 @@ protected void testLanguageNavigationItemsOnTemplate() {

}

@Test
protected void testLanguageNavigationItemsWithExtendedCountryCode() {
context.load().json(testBase + "/test-content-country.json", "/content/countrytest");
LanguageNavigation languageNavigation = getLanguageNavigationUnderTest(
"/content/countrytest/languagenavigation/ch_zn/jcr:content/root/languagenavigation-component-1");
List<NavigationItem> items = getLanguageNavigationItems(languageNavigation);
verifyLanguageNavigationItems(EXPECTED_COUNTRY_LIST, items);
}

protected LanguageNavigation getLanguageNavigationUnderTest(String resourcePath) {
Utils.enableDataLayer(context, true);
context.currentResource(resourcePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"languagenavigation": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "Language Structure",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200"
},
"ch": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "ch",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/ch-3-vanity",
"jcr:language": "ch"
}
},
"ch_zn": {
"jcr:primaryType": "cq:Page",
"jcr:content" : {
"jcr:primaryType": "cq:PageContent",
"jcr:title" : "ch_zn",
"jcr:created" : "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/ch_zn-3-vanity",
"jcr:language" : "ch",
"root" : {
"jcr:primaryType": "nt:unstructured",
"languagenavigation-component-1": {
"jcr:primaryType" : "nt:unstructured",
"sling:resourceType": "core/wcm/components/languagenavigation/v1/languagenavigation",
"navigationRoot" : "/content/countrytest/languagenavigation",
"structureDepth" : 1
}
}
}
},
"en": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "en",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/en-3-vanity",
"jcr:language": "en"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"languagenavigation": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "Language Structure",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200"
},
"ch": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "ch",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/ch-3-vanity",
"jcr:language": "ch"
}
},
"ch_zn": {
"jcr:primaryType": "cq:Page",
"jcr:content" : {
"jcr:primaryType": "cq:PageContent",
"jcr:title" : "ch_zn",
"jcr:created" : "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/ch_zn-3-vanity",
"jcr:language" : "ch",
"root" : {
"jcr:primaryType": "nt:unstructured",
"languagenavigation-component-1": {
"jcr:primaryType" : "nt:unstructured",
"sling:resourceType": "core/wcm/components/languagenavigation/v1/languagenavigation",
"navigationRoot" : "/content/countrytest/languagenavigation",
"structureDepth" : 1
}
}
}
},
"en": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "en",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/en-3-vanity",
"jcr:language": "en"
}
}
}
}

0 comments on commit 6514f5b

Please sign in to comment.