Skip to content

Commit

Permalink
#28769 include in 23.10.24 LTS
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Jun 17, 2024
1 parent 106ce02 commit ba1e58d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dotCMS/hotfix_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ This maintenance release includes the following code fixes:
107. https://github.com/dotCMS/private-issues/issues/34
108. https://github.com/dotCMS/core/issues/28785 : APIs return incorrect information for pages with fields using the variable name "description" #28785
109. https://github.com/dotCMS/core/issues/28695 : UT210901 UpdateDateTimezones has wrong DST query #28695
110. https://github.com/dotCMS/core/issues/28760 : Template Evaluation for Non-Default Language Pages #28760
110. https://github.com/dotCMS/core/issues/28760 : Template Evaluation for Non-Default Language Pages #28760
111. https://github.com/dotCMS/core/issues/28769 : Language Fallback not working. #28769
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
import static org.junit.Assert.assertEquals;

import com.dotcms.api.web.HttpServletRequestThreadLocal;
import com.dotcms.datagen.LanguageDataGen;
import com.dotcms.datagen.TestDataUtils;
import com.dotcms.datagen.VariantDataGen;
import com.dotcms.mock.request.MockSession;
import com.dotcms.util.IntegrationTestInitService;
import com.dotcms.variant.VariantAPI;
import com.dotcms.variant.model.Variant;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.web.WebAPILocator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.contentlet.model.ContentletVersionInfo;
import com.dotmarketing.portlets.languagesmanager.model.Language;
import com.dotmarketing.util.PageMode;
import com.liferay.portal.model.User;
import net.bytebuddy.utility.RandomString;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -246,4 +255,21 @@ private static HttpServletRequest createHttpServletRequest(final Variant variant
when(request.getSession(true)).thenReturn(mockSession);
return request;
}

/**
* Method to test {@link VariantWebAPIImpl#getContentletVersionInfoByFallback(long, String, PageMode, User, boolean)}
* When: The contentlet does not have a version for the language
* Should: Return the default contentlet
* @throws DotDataException
*/
@Test
public void test_getContentletVersionInfoByFallback_should_get_default_content() throws DotDataException {
final Contentlet content = TestDataUtils.getFileAssetContent(true, APILocator.getLanguageAPI().getDefaultLanguage().getId());
final Language language = new LanguageDataGen().nextPersisted();

final VariantWebAPI variantWebAPI = WebAPILocator.getVariantWebAPI();
ContentletVersionInfo cvi = variantWebAPI.getContentletVersionInfoByFallback(language.getId(), content.getIdentifier(), PageMode.LIVE, APILocator.getUserAPI().getAnonymousUser());

assertNotNull(cvi);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ private boolean shouldFallbackByLang(final ContentletVersionInfo contentletVersi

return Boolean.TRUE.equals(contentlet.isHTMLPage()) ||
forceFallbackByContentType(type) ||
isFileFallback(type) ||
isContentletFallback(type) ||
isWidgetFallback(type);
}
Expand All @@ -247,6 +248,11 @@ private static boolean isWidgetFallback(ContentType type) {
&& APILocator.getLanguageAPI().canDefaultWidgetToDefaultLanguage();
}

private static boolean isFileFallback(ContentType type) {
return type.baseType() == BaseContentType.FILEASSET
&& APILocator.getLanguageAPI().canDefaultFileToDefaultLanguage();
}

private static boolean isContentletFallback(ContentType type) {
return type.baseType() == BaseContentType.CONTENT
&& APILocator.getLanguageAPI().canDefaultContentToDefaultLanguage();
Expand Down

0 comments on commit ba1e58d

Please sign in to comment.