|
17 | 17 | import com.dotcms.contenttype.model.type.ContentType; |
18 | 18 | import com.dotcms.contenttype.model.type.ContentTypeBuilder; |
19 | 19 | import com.dotcms.contenttype.model.type.SimpleContentType; |
| 20 | +import com.dotcms.datagen.ContainerDataGen; |
20 | 21 | import com.dotcms.datagen.ContentTypeDataGen; |
| 22 | +import com.dotcms.datagen.MultiTreeDataGen; |
21 | 23 | import com.dotcms.datagen.ContentletDataGen; |
| 24 | +import com.dotcms.datagen.HTMLPageDataGen; |
22 | 25 | import com.dotcms.datagen.LanguageDataGen; |
| 26 | +import com.dotcms.datagen.SiteDataGen; |
| 27 | +import com.dotcms.datagen.TemplateDataGen; |
23 | 28 | import com.dotcms.datagen.TestDataUtils; |
24 | 29 | import com.dotcms.util.CollectionsUtils; |
25 | 30 | import com.dotcms.util.IntegrationTestInitService; |
26 | 31 | import com.dotmarketing.beans.Host; |
| 32 | +import com.dotmarketing.beans.MultiTree; |
27 | 33 | import com.dotmarketing.business.APILocator; |
28 | 34 | import com.dotmarketing.business.RelationshipAPI; |
29 | 35 | import com.dotmarketing.business.UserAPI; |
|
32 | 38 | import com.dotmarketing.portlets.contentlet.business.ContentletAPI; |
33 | 39 | import com.dotmarketing.portlets.contentlet.business.HostAPI; |
34 | 40 | import com.dotmarketing.portlets.contentlet.model.Contentlet; |
| 41 | +import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset; |
35 | 42 | import com.dotmarketing.portlets.contentlet.model.IndexPolicy; |
36 | 43 | import com.dotmarketing.portlets.folders.business.FolderAPI; |
37 | 44 | import com.dotmarketing.portlets.languagesmanager.business.LanguageAPI; |
38 | 45 | import com.dotmarketing.portlets.languagesmanager.model.Language; |
| 46 | +import com.dotmarketing.portlets.containers.model.Container; |
39 | 47 | import com.dotmarketing.portlets.structure.model.Relationship; |
| 48 | +import com.dotmarketing.portlets.templates.model.Template; |
40 | 49 | import com.dotmarketing.util.PageMode; |
41 | 50 | import com.dotmarketing.util.PaginatedArrayList; |
42 | 51 | import com.dotmarketing.util.PaginatedContentList; |
|
52 | 61 | import java.util.Calendar; |
53 | 62 | import java.util.Collection; |
54 | 63 | import java.util.Date; |
| 64 | +import java.util.HashMap; |
55 | 65 | import java.util.List; |
| 66 | +import java.util.Map; |
56 | 67 | import java.util.stream.Collectors; |
57 | 68 | import java.util.stream.IntStream; |
58 | 69 | import javax.servlet.http.HttpServletRequest; |
@@ -956,4 +967,129 @@ public void test_pull_hydrated() { |
956 | 967 | Assert.assertTrue(hydratedContentlet.getContentObject().getMap().containsKey("url")); |
957 | 968 | } |
958 | 969 |
|
| 970 | + /** |
| 971 | + * Method to Test: {@link ContentTool#find(String)} with addStylePropertiesFromMultiTree |
| 972 | + * When: Content is loaded via find() in a page/container context (HTMLPAGE_IDENTIFIER, |
| 973 | + * CONTAINER_IDENTIFIER, CONTAINER_UNIQUE_ID set in velocity context) and the contentlet |
| 974 | + * has style properties stored in the MultiTree (from UVE style editor) |
| 975 | + * Should: Add dotStyleProperties to the contentlet map, accessible via get("dotStyleProperties") |
| 976 | + */ |
| 977 | + @Test |
| 978 | + public void testFind_WhenPageContainerContext_AddsDotStylePropertiesFromMultiTree() |
| 979 | + throws DotDataException { |
| 980 | + final Host host = new SiteDataGen().nextPersisted(); |
| 981 | + final Template template = new TemplateDataGen().nextPersisted(); |
| 982 | + final HTMLPageAsset page = new HTMLPageDataGen(host, template).nextPersisted(); |
| 983 | + final Container container = new ContainerDataGen().nextPersisted(); |
| 984 | + final ContentType contentType = new ContentTypeDataGen().nextPersisted(); |
| 985 | + final Contentlet contentlet = new ContentletDataGen(contentType.id()) |
| 986 | + .host(host) |
| 987 | + .languageId(defaultLanguage.getId()) |
| 988 | + .nextPersisted(); |
| 989 | + ContentletDataGen.publish(contentlet); |
| 990 | + |
| 991 | + final Map<String, Object> styleProperties = new HashMap<>(); |
| 992 | + styleProperties.put("fontSize", "20px"); |
| 993 | + styleProperties.put("color", "#ff0000"); |
| 994 | + |
| 995 | + MultiTree multiTree = new MultiTreeDataGen() |
| 996 | + .setPage(page) |
| 997 | + .setContainer(container) |
| 998 | + .setContentlet(contentlet) |
| 999 | + .setInstanceID("1") |
| 1000 | + .next(); |
| 1001 | + multiTree = multiTree.setStyleProperties(styleProperties); |
| 1002 | + APILocator.getMultiTreeAPI().saveMultiTree(multiTree); |
| 1003 | + |
| 1004 | + final ContentTool contentTool = getContentToolWithPageContext( |
| 1005 | + defaultLanguage.getId(), |
| 1006 | + host, |
| 1007 | + page.getIdentifier(), |
| 1008 | + container.getIdentifier() |
| 1009 | + ); |
| 1010 | + |
| 1011 | + final ContentMap contentMap = contentTool.find(contentlet.getIdentifier()); |
| 1012 | + assertNotNull(contentMap); |
| 1013 | + |
| 1014 | + final Map<String, Object> result = (Map<String, Object>) contentMap.get(Contentlet.STYLE_PROPERTIES_KEY); |
| 1015 | + assertNotNull(result); |
| 1016 | + assertEquals("20px", result.get("fontSize")); |
| 1017 | + assertEquals("#ff0000", result.get("color")); |
| 1018 | + } |
| 1019 | + |
| 1020 | + /** |
| 1021 | + * Method to Test: {@link ContentTool#load(String)} (LazyLoaderContentMap) |
| 1022 | + * When: Same as testFind_WhenPageContainerContext - content with style props in MultiTree |
| 1023 | + * Should: LazyLoaderContentMap.get("dotStyleProperties") returns the style properties |
| 1024 | + */ |
| 1025 | + @Test |
| 1026 | + public void testLoad_WhenPageContainerContext_ReturnsDotStylePropertiesInLazyLoaderContentMap() |
| 1027 | + throws DotDataException, DotSecurityException { |
| 1028 | + final Host host = new SiteDataGen().nextPersisted(); |
| 1029 | + final Template template = new TemplateDataGen().nextPersisted(); |
| 1030 | + final HTMLPageAsset page = new HTMLPageDataGen(host, template).nextPersisted(); |
| 1031 | + final Container container = new ContainerDataGen().nextPersisted(); |
| 1032 | + final ContentType contentType = new ContentTypeDataGen().nextPersisted(); |
| 1033 | + final Contentlet contentlet = new ContentletDataGen(contentType.id()) |
| 1034 | + .host(host) |
| 1035 | + .languageId(defaultLanguage.getId()) |
| 1036 | + .nextPersisted(); |
| 1037 | + ContentletDataGen.publish(contentlet); |
| 1038 | + |
| 1039 | + final Map<String, Object> styleProperties = new HashMap<>(); |
| 1040 | + styleProperties.put("fontSize", "16px"); |
| 1041 | + |
| 1042 | + MultiTree multiTree = new MultiTreeDataGen() |
| 1043 | + .setPage(page) |
| 1044 | + .setContainer(container) |
| 1045 | + .setContentlet(contentlet) |
| 1046 | + .setInstanceID("1") |
| 1047 | + .next(); |
| 1048 | + multiTree = multiTree.setStyleProperties(styleProperties); |
| 1049 | + APILocator.getMultiTreeAPI().saveMultiTree(multiTree); |
| 1050 | + |
| 1051 | + final ContentTool contentTool = getContentToolWithPageContext( |
| 1052 | + defaultLanguage.getId(), |
| 1053 | + host, |
| 1054 | + page.getIdentifier(), |
| 1055 | + container.getIdentifier() |
| 1056 | + ); |
| 1057 | + |
| 1058 | + final LazyLoaderContentMap lazyMap = contentTool.load(contentlet.getIdentifier()); |
| 1059 | + assertNotNull(lazyMap); |
| 1060 | + |
| 1061 | + final Map<String, Object> result = (Map<String, Object>) lazyMap.get(Contentlet.STYLE_PROPERTIES_KEY); |
| 1062 | + assertNotNull(result); |
| 1063 | + assertEquals("16px", result.get("fontSize")); |
| 1064 | + } |
| 1065 | + |
| 1066 | + private ContentTool getContentToolWithPageContext(final long languageId, final Host host, |
| 1067 | + final String pageId, final String containerId) { |
| 1068 | + final ViewContext viewContext = mock(ViewContext.class); |
| 1069 | + final Context velocityContext = mock(Context.class); |
| 1070 | + final HttpServletRequest request = mock(HttpServletRequest.class); |
| 1071 | + final HttpSession session = mock(HttpSession.class); |
| 1072 | + |
| 1073 | + when(viewContext.getVelocityContext()).thenReturn(velocityContext); |
| 1074 | + when(viewContext.getRequest()).thenReturn(request); |
| 1075 | + when(request.getParameter("host_id")).thenReturn(host.getInode()); |
| 1076 | + when(request.getParameter("language_id")).thenReturn(String.valueOf(languageId)); |
| 1077 | + when(request.getSession(false)).thenReturn(session); |
| 1078 | + when(request.getSession(true)).thenReturn(session); |
| 1079 | + when(request.getSession()).thenReturn(session); |
| 1080 | + when(request.getParameter(com.dotmarketing.util.WebKeys.PAGE_MODE_PARAMETER)) |
| 1081 | + .thenReturn(PageMode.PREVIEW_MODE.name()); |
| 1082 | + when(session.getAttribute(com.dotmarketing.util.WebKeys.CMS_USER)).thenReturn(user); |
| 1083 | + |
| 1084 | + when(velocityContext.get("HTMLPAGE_IDENTIFIER")).thenReturn(pageId); |
| 1085 | + when(velocityContext.get("CONTAINER_IDENTIFIER")).thenReturn(containerId); |
| 1086 | + when(velocityContext.get("CONTAINER_UNIQUE_ID")).thenReturn("1"); |
| 1087 | + |
| 1088 | + HttpServletRequestThreadLocal.INSTANCE.setRequest(request); |
| 1089 | + |
| 1090 | + final ContentTool contentTool = new ContentTool(); |
| 1091 | + contentTool.init(viewContext); |
| 1092 | + return contentTool; |
| 1093 | + } |
| 1094 | + |
959 | 1095 | } |
0 commit comments