Clover Coverage Report - magnolia-module-templating 4.4.5
Coverage timestamp: Mon Sep 12 2011 16:32:30 CEST
60   158   6   10
0   86   0.1   6
6     1  
1    
 
  TemplatingModuleVersionHandlerTest       Line # 54 60 0% 6 0 100% 1.0
 
  (3)
 
1    /**
2    * This file Copyright (c) 2003-2011 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
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 gjoseph
52    * @version $Revision: $ ($Author: $)
53    */
 
54    public class TemplatingModuleVersionHandlerTest extends ModuleVersionHandlerTestCase {
 
55  3 toggle protected String getModuleDescriptorPath() {
56  3 return "/META-INF/magnolia/templating.xml";
57    }
58   
 
59  3 toggle protected ModuleVersionHandler newModuleVersionHandlerForTests() {
60  3 return new TemplatingModuleVersionHandler();
61    }
62   
63    // fixed by 4.0.3 or 4.1.1
 
64  1 toggle public void testPre4_0TemplatesAreFixedProperly() throws Exception {
65    // fake pre-install
66  1 setupConfigProperty("/server/filters/cms/rendering", "class", "info.magnolia.cms.filters.RenderingFilter"); // old RenderingFilter fqn
67  1 setupConfigProperty("/server/filters/cms/backwardCompatibility", "class", BackwardCompatibilityFilter.class.getName());
68  1 setupConfigNode("/server/rendering/freemarker/sharedVariables"); // this is assumed to have been created by CoreModuleVersionHandler
69   
70    // setup a template, with pre-4.0 properties
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    // non-standard props are supposed to be moved to the "parameters" subnode
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    // fixed by 4.0.3 or 4.1.1
 
93  1 toggle public void testMisfixedTemplatesFrom402AreFixed() throws Exception {
94    // fake pre-install
95  1 setupConfigProperty("/server/filters/cms/rendering", "class", "info.magnolia.cms.filters.RenderingFilter"); // old RenderingFilter fqn
96  1 setupConfigProperty("/server/filters/cms/backwardCompatibility", "class", BackwardCompatibilityFilter.class.getName());
97  1 setupConfigNode("/server/rendering/freemarker/sharedVariables"); // this is assumed to have been created by CoreModuleVersionHandler
98   
99    // setup a template, with pre-4.0 properties
100  1 final String tplPath = "/modules/test/templates/myTemplate";
101  1 setupTemplateNode("test", "myTemplate");
102  1 setupConfigProperty(tplPath, "title", "My Test Template");
103    // 4.0.2 and 4.0 wrongly moved the "templatePath" property under /parameters
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    // non-standard props are supposed to be moved to the "parameters" subnode
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   
 
122  1 toggle public void testSilentIfUserFixedTemplatesHimself() throws Exception {
123    // fake pre-install
124  1 setupConfigProperty("/server/filters/cms/rendering", "class", "info.magnolia.cms.filters.RenderingFilter"); // old RenderingFilter fqn
125  1 setupConfigProperty("/server/filters/cms/backwardCompatibility", "class", BackwardCompatibilityFilter.class.getName());
126  1 setupConfigNode("/server/rendering/freemarker/sharedVariables"); // this is assumed to have been created by CoreModuleVersionHandler
127   
128    // setup a template, with pre-4.0 properties
129  1 final String tplPath = "/modules/test/templates/myTemplate";
130  1 setupTemplateNode("test", "myTemplate");
131  1 setupConfigProperty(tplPath, "title", "My Test Template");
132    // 4.0.2 and 4.0 wrongly moved the "templatePath" property under /parameters - here the user fixed it already
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    // non-standard props are supposed to be moved to the "parameters" subnode
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   
 
151  3 toggle 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    }