]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/SugarTestThemeUtilities.php
Release 6.4.0
[Github/sugarcrm.git] / tests / SugarTestThemeUtilities.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37  
38 require_once 'include/SugarTheme/SugarTheme.php';
39 require_once 'include/dir_inc.php';
40
41 class SugarTestThemeUtilities
42 {
43     private static  $_createdThemes = array();
44
45     private function __construct() {}
46
47     public static function createAnonymousTheme()
48     {
49         $themename = 'TestTheme'.mt_rand();
50
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);
55
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");
62
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('.*')),";
69         $themedef .= ");";
70         sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
71
72         self::$_createdThemes[] = $themename;
73
74         SugarThemeRegistry::buildRegistry();
75
76         return $themename;
77     }
78
79     public static function createAnonymousOldTheme()
80     {
81         $themename = 'TestTheme'.mt_rand();
82
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);
87
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");
94
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')),";
101         $themedef .= ");";
102         sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
103
104         self::$_createdThemes[] = $themename;
105
106         SugarThemeRegistry::buildRegistry();
107
108         return $themename;
109     }
110
111     public static function createAnonymousCustomTheme(
112         $themename = ''
113         )
114     {
115         if ( empty($themename) )
116             $themename = 'TestThemeCustom'.mt_rand();
117
118         create_custom_directory("themes/$themename/images/");
119         create_custom_directory("themes/$themename/css/");
120         create_custom_directory("themes/$themename/js/");
121
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");
126
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('.*')),";
133         $themedef .= ");";
134         sugar_file_put_contents("custom/themes/$themename/themedef.php",$themedef);
135
136         self::$_createdThemes[] = $themename;
137
138         SugarThemeRegistry::buildRegistry();
139
140         return $themename;
141     }
142
143     public static function createAnonymousChildTheme(
144         $parentTheme
145         )
146     {
147         $themename = 'TestThemeChild'.mt_rand();
148
149         sugar_mkdir("themes/$themename/images",null,true);
150         sugar_mkdir("themes/$themename/css",null,true);
151         sugar_mkdir("themes/$themename/js",null,true);
152
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";');
156
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('.*')),";
164         $themedef .= ");";
165         sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
166
167         self::$_createdThemes[] = $themename;
168
169         SugarThemeRegistry::buildRegistry();
170
171         return $themename;
172     }
173     
174     public static function createAnonymousRTLTheme() 
175     {
176         $themename = 'TestTheme'.mt_rand();
177         
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);
182         
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");
189         
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('.*')),";
197         $themedef .= ");";
198         sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
199         
200         self::$_createdThemes[] = $themename;
201         
202         SugarThemeRegistry::buildRegistry();        
203         
204         return $themename;
205     }
206
207     public static function removeAllCreatedAnonymousThemes()
208     {
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);
216         }
217
218         SugarThemeRegistry::buildRegistry();
219     }
220
221     public static function getCreatedThemeNames()
222     {
223         return self::$_createdThemes;
224     }
225 }
226