2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
38 require_once 'include/SugarTheme/SugarTheme.php';
39 require_once 'include/dir_inc.php';
41 class SugarTestThemeUtilities
43 private static $_createdThemes = array();
45 private function __construct() {}
47 public static function createAnonymousTheme()
49 $themename = 'TestTheme'.mt_rand();
51 sugar_mkdir("themes/$themename/images",null,true);
52 sugar_mkdir("themes/$themename/css",null,true);
53 sugar_mkdir("themes/$themename/js",null,true);
54 sugar_mkdir("themes/$themename/tpls",null,true);
56 sugar_file_put_contents("themes/$themename/css/style.css","h2 { display: inline; }");
57 sugar_file_put_contents("themes/$themename/css/yui.css",".yui { display: inline; }");
58 sugar_file_put_contents("themes/$themename/js/style.js",'var dog = "cat";');
59 sugar_touch("themes/$themename/images/Accounts.gif");
60 sugar_touch("themes/$themename/images/fonts.big.icon.gif");
61 sugar_touch("themes/$themename/tpls/header.tpl");
63 $themedef = "<?php\n";
64 $themedef .= "\$themedef = array(\n";
65 $themedef .= "'name' => '$themename',";
66 $themedef .= "'dirName' => '$themename',";
67 $themedef .= "'description' => '$themename',";
68 $themedef .= "'version' => array('regex_matches' => array('.*')),";
70 sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
72 self::$_createdThemes[] = $themename;
74 SugarThemeRegistry::buildRegistry();
79 public static function createAnonymousOldTheme()
81 $themename = 'TestTheme'.mt_rand();
83 sugar_mkdir("themes/$themename/images",null,true);
84 sugar_mkdir("themes/$themename/css",null,true);
85 sugar_mkdir("themes/$themename/js",null,true);
86 sugar_mkdir("themes/$themename/tpls",null,true);
88 sugar_file_put_contents("themes/$themename/css/style.css","h2 { display: inline; }");
89 sugar_file_put_contents("themes/$themename/css/yui.css",".yui { display: inline; }");
90 sugar_file_put_contents("themes/$themename/js/style.js",'var dog = "cat";');
91 sugar_touch("themes/$themename/images/Accounts.gif");
92 sugar_touch("themes/$themename/images/fonts.big.icon.gif");
93 sugar_touch("themes/$themename/tpls/header.tpl");
95 $themedef = "<?php\n";
96 $themedef .= "\$themedef = array(\n";
97 $themedef .= "'name' => '$themename',";
98 $themedef .= "'dirName' => '$themename',";
99 $themedef .= "'description' => '$themename',";
100 $themedef .= "'version' => array('exact_matches' => array('5.5.1')),";
102 sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
104 self::$_createdThemes[] = $themename;
106 SugarThemeRegistry::buildRegistry();
111 public static function createAnonymousCustomTheme(
115 if ( empty($themename) )
116 $themename = 'TestThemeCustom'.mt_rand();
118 create_custom_directory("themes/$themename/images/");
119 create_custom_directory("themes/$themename/css/");
120 create_custom_directory("themes/$themename/js/");
122 sugar_touch("custom/themes/$themename/css/style.css");
123 sugar_touch("custom/themes/$themename/js/style.js");
124 sugar_touch("custom/themes/$themename/images/Accounts.gif");
125 sugar_touch("custom/themes/$themename/images/fonts.big.icon.gif");
127 $themedef = "<?php\n";
128 $themedef .= "\$themedef = array(\n";
129 $themedef .= "'name' => 'custom $themename',";
130 $themedef .= "'dirName' => '$themename',";
131 $themedef .= "'description' => 'custom $themename',";
132 $themedef .= "'version' => array('regex_matches' => array('.*')),";
134 sugar_file_put_contents("custom/themes/$themename/themedef.php",$themedef);
136 self::$_createdThemes[] = $themename;
138 SugarThemeRegistry::buildRegistry();
143 public static function createAnonymousChildTheme(
147 $themename = 'TestThemeChild'.mt_rand();
149 sugar_mkdir("themes/$themename/images",null,true);
150 sugar_mkdir("themes/$themename/css",null,true);
151 sugar_mkdir("themes/$themename/js",null,true);
153 sugar_file_put_contents("themes/$themename/css/style.css","h3 { display: inline; }");
154 sugar_file_put_contents("themes/$themename/css/yui.css",".yui { display: inline; }");
155 sugar_file_put_contents("themes/$themename/js/style.js",'var bird = "frog";');
157 $themedef = "<?php\n";
158 $themedef .= "\$themedef = array(\n";
159 $themedef .= "'name' => '$themename',";
160 $themedef .= "'dirName' => '$themename',";
161 $themedef .= "'parentTheme' => '".$parentTheme."',";
162 $themedef .= "'description' => '$themename',";
163 $themedef .= "'version' => array('regex_matches' => array('.*')),";
165 sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
167 self::$_createdThemes[] = $themename;
169 SugarThemeRegistry::buildRegistry();
174 public static function createAnonymousRTLTheme()
176 $themename = 'TestTheme'.mt_rand();
178 sugar_mkdir("themes/$themename/images",null,true);
179 sugar_mkdir("themes/$themename/css",null,true);
180 sugar_mkdir("themes/$themename/js",null,true);
181 sugar_mkdir("themes/$themename/tpls",null,true);
183 sugar_file_put_contents("themes/$themename/css/style.css","h2 { display: inline; }");
184 sugar_file_put_contents("themes/$themename/css/yui.css",".yui { display: inline; }");
185 sugar_file_put_contents("themes/$themename/js/style.js",'var dog = "cat";');
186 sugar_touch("themes/$themename/images/Accounts.gif");
187 sugar_touch("themes/$themename/images/fonts.big.icon.gif");
188 sugar_touch("themes/$themename/tpls/header.tpl");
190 $themedef = "<?php\n";
191 $themedef .= "\$themedef = array(\n";
192 $themedef .= "'name' => '$themename',";
193 $themedef .= "'dirName' => '$themename',";
194 $themedef .= "'description' => '$themename',";
195 $themedef .= "'directionality' => 'rtl',";
196 $themedef .= "'version' => array('regex_matches' => array('.*')),";
198 sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
200 self::$_createdThemes[] = $themename;
202 SugarThemeRegistry::buildRegistry();
207 public static function removeAllCreatedAnonymousThemes()
209 foreach (self::getCreatedThemeNames() as $name ) {
210 if ( is_dir('themes/'.$name) )
211 rmdir_recursive('themes/'.$name);
212 if ( is_dir('custom/themes/'.$name) )
213 rmdir_recursive('custom/themes/'.$name);
214 if ( is_dir(sugar_cached('themes/').$name) )
215 rmdir_recursive(sugar_cached('themes/').$name);
218 SugarThemeRegistry::buildRegistry();
221 public static function getCreatedThemeNames()
223 return self::$_createdThemes;