1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.templating.setup; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.Content; |
37 |
|
import info.magnolia.cms.core.HierarchyManager; |
38 |
|
import info.magnolia.cms.core.ItemType; |
39 |
|
import info.magnolia.cms.filters.BackwardCompatibilityFilter; |
40 |
|
import info.magnolia.cms.util.ContentUtil; |
41 |
|
import info.magnolia.context.MgnlContext; |
42 |
|
import info.magnolia.module.InstallContext; |
43 |
|
import info.magnolia.module.ModuleVersionHandler; |
44 |
|
import info.magnolia.module.ModuleVersionHandlerTestCase; |
45 |
|
import info.magnolia.module.model.Version; |
46 |
|
|
47 |
|
import javax.jcr.RepositoryException; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@author |
52 |
|
@version |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (66) |
Complexity: 6 |
Complexity Density: 0.1 |
|
54 |
|
public class TemplatingModuleVersionHandlerTest extends ModuleVersionHandlerTestCase { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
3
|
protected String getModuleDescriptorPath() {... |
56 |
3
|
return "/META-INF/magnolia/templating.xml"; |
57 |
|
} |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
3
|
protected ModuleVersionHandler newModuleVersionHandlerForTests() {... |
60 |
3
|
return new TemplatingModuleVersionHandler(); |
61 |
|
} |
62 |
|
|
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1
PASS
|
|
64 |
1
|
public void testPre4_0TemplatesAreFixedProperly() throws Exception {... |
65 |
|
|
66 |
1
|
setupConfigProperty("/server/filters/cms/rendering", "class", "info.magnolia.cms.filters.RenderingFilter"); |
67 |
1
|
setupConfigProperty("/server/filters/cms/backwardCompatibility", "class", BackwardCompatibilityFilter.class.getName()); |
68 |
1
|
setupConfigNode("/server/rendering/freemarker/sharedVariables"); |
69 |
|
|
70 |
|
|
71 |
1
|
final String tplPath = "/modules/test/templates/myTemplate"; |
72 |
1
|
setupTemplateNode("test", "myTemplate"); |
73 |
1
|
setupConfigProperty(tplPath, "title", "My Test Template"); |
74 |
1
|
setupConfigProperty(tplPath, "path", "/some/path.ftl"); |
75 |
1
|
setupConfigProperty(tplPath, "someProperty", "someValue"); |
76 |
|
|
77 |
1
|
final InstallContext ctx = executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.7")); |
78 |
|
|
79 |
1
|
final HierarchyManager hm = MgnlContext.getHierarchyManager("config"); |
80 |
1
|
assertConfig("My Test Template", tplPath + "/title"); |
81 |
1
|
assertConfig("/some/path.ftl", tplPath + "/templatePath"); |
82 |
|
|
83 |
1
|
assertConfig("someValue", tplPath + "/parameters/someProperty"); |
84 |
1
|
assertFalse("path property should have been removed", hm.isExist(tplPath + "/path")); |
85 |
1
|
assertFalse("path property should have been removed", hm.isExist(tplPath + "/parameters/path")); |
86 |
1
|
assertFalse("path property should have been removed", hm.isExist(tplPath + "/parameters/templatePath")); |
87 |
1
|
assertFalse("path property should have been renamed to templatePath and be in the template's def. node", hm.isExist(tplPath + "/parameters/templatePath")); |
88 |
|
|
89 |
1
|
assertNoMessages(ctx); |
90 |
|
} |
91 |
|
|
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1
PASS
|
|
93 |
1
|
public void testMisfixedTemplatesFrom402AreFixed() throws Exception {... |
94 |
|
|
95 |
1
|
setupConfigProperty("/server/filters/cms/rendering", "class", "info.magnolia.cms.filters.RenderingFilter"); |
96 |
1
|
setupConfigProperty("/server/filters/cms/backwardCompatibility", "class", BackwardCompatibilityFilter.class.getName()); |
97 |
1
|
setupConfigNode("/server/rendering/freemarker/sharedVariables"); |
98 |
|
|
99 |
|
|
100 |
1
|
final String tplPath = "/modules/test/templates/myTemplate"; |
101 |
1
|
setupTemplateNode("test", "myTemplate"); |
102 |
1
|
setupConfigProperty(tplPath, "title", "My Test Template"); |
103 |
|
|
104 |
1
|
setupConfigProperty(tplPath + "/parameters", "templatePath", "/some/path.ftl"); |
105 |
1
|
setupConfigProperty(tplPath + "/parameters", "someProperty", "someValue"); |
106 |
|
|
107 |
1
|
final InstallContext ctx = executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("4.0.2")); |
108 |
|
|
109 |
1
|
final HierarchyManager hm = MgnlContext.getHierarchyManager("config"); |
110 |
1
|
assertConfig("My Test Template", tplPath + "/title"); |
111 |
1
|
assertConfig("/some/path.ftl", tplPath + "/templatePath"); |
112 |
|
|
113 |
1
|
assertConfig("someValue", tplPath + "/parameters/someProperty"); |
114 |
1
|
assertFalse("path property should have been removed", hm.isExist(tplPath + "/path")); |
115 |
1
|
assertFalse("path property should have been removed", hm.isExist(tplPath + "/parameters/path")); |
116 |
1
|
assertFalse("path property should have been removed", hm.isExist(tplPath + "/parameters/templatePath")); |
117 |
1
|
assertFalse("path property should have been renamed to templatePath and be in the template's def. node", hm.isExist(tplPath + "/parameters/templatePath")); |
118 |
|
|
119 |
1
|
assertNoMessages(ctx); |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1
PASS
|
|
122 |
1
|
public void testSilentIfUserFixedTemplatesHimself() throws Exception {... |
123 |
|
|
124 |
1
|
setupConfigProperty("/server/filters/cms/rendering", "class", "info.magnolia.cms.filters.RenderingFilter"); |
125 |
1
|
setupConfigProperty("/server/filters/cms/backwardCompatibility", "class", BackwardCompatibilityFilter.class.getName()); |
126 |
1
|
setupConfigNode("/server/rendering/freemarker/sharedVariables"); |
127 |
|
|
128 |
|
|
129 |
1
|
final String tplPath = "/modules/test/templates/myTemplate"; |
130 |
1
|
setupTemplateNode("test", "myTemplate"); |
131 |
1
|
setupConfigProperty(tplPath, "title", "My Test Template"); |
132 |
|
|
133 |
1
|
setupConfigProperty(tplPath, "templatePath", "/some/path.ftl"); |
134 |
1
|
setupConfigProperty(tplPath + "/parameters", "someProperty", "someValue"); |
135 |
|
|
136 |
1
|
final InstallContext ctx = executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("4.0.2")); |
137 |
|
|
138 |
1
|
final HierarchyManager hm = MgnlContext.getHierarchyManager("config"); |
139 |
1
|
assertConfig("My Test Template", tplPath + "/title"); |
140 |
1
|
assertConfig("/some/path.ftl", tplPath + "/templatePath"); |
141 |
|
|
142 |
1
|
assertConfig("someValue", tplPath + "/parameters/someProperty"); |
143 |
1
|
assertFalse("path property should have been removed", hm.isExist(tplPath + "/path")); |
144 |
1
|
assertFalse("path property should have been removed", hm.isExist(tplPath + "/parameters/path")); |
145 |
1
|
assertFalse("path property should have been removed", hm.isExist(tplPath + "/parameters/templatePath")); |
146 |
1
|
assertFalse("path property should have been renamed to templatePath and be in the template's def. node", hm.isExist(tplPath + "/parameters/templatePath")); |
147 |
|
|
148 |
1
|
assertNoMessages(ctx); |
149 |
|
} |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
151 |
3
|
private void setupTemplateNode(String moduleName, String templateNodeName) throws RepositoryException {... |
152 |
3
|
final HierarchyManager hm = MgnlContext.getHierarchyManager("config"); |
153 |
3
|
final Content content = ContentUtil.createPath(hm, "/modules/" + moduleName + "/templates", ItemType.CONTENT); |
154 |
3
|
content.createContent(templateNodeName, ItemType.CONTENTNODE); |
155 |
3
|
hm.save(); |
156 |
|
} |
157 |
|
|
158 |
|
} |