PageRenderTime 54ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/SugarTestThemeUtilities.php

https://github.com/mikmagic/sugarcrm_dev
PHP | 226 lines | 149 code | 43 blank | 34 comment | 4 complexity | e2a1e127f338e3a72639c50aaa82f0dd MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause, AGPL-3.0
  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. require_once 'include/SugarTheme/SugarTheme.php';
  37. require_once 'include/dir_inc.php';
  38. class SugarTestThemeUtilities
  39. {
  40. private static $_createdThemes = array();
  41. private function __construct() {}
  42. public static function createAnonymousTheme()
  43. {
  44. $themename = 'TestTheme'.mt_rand();
  45. sugar_mkdir("themes/$themename/images",null,true);
  46. sugar_mkdir("themes/$themename/css",null,true);
  47. sugar_mkdir("themes/$themename/js",null,true);
  48. sugar_mkdir("themes/$themename/tpls",null,true);
  49. sugar_file_put_contents("themes/$themename/css/style.css","h2 { display: inline; }");
  50. sugar_file_put_contents("themes/$themename/css/yui.css",".yui { display: inline; }");
  51. sugar_file_put_contents("themes/$themename/js/style.js",'var dog = "cat";');
  52. sugar_touch("themes/$themename/images/Accounts.gif");
  53. sugar_touch("themes/$themename/images/fonts.big.icon.gif");
  54. sugar_touch("themes/$themename/tpls/header.tpl");
  55. $themedef = "<?php\n";
  56. $themedef .= "\$themedef = array(\n";
  57. $themedef .= "'name' => '$themename',";
  58. $themedef .= "'dirName' => '$themename',";
  59. $themedef .= "'description' => '$themename',";
  60. $themedef .= "'version' => array('regex_matches' => array('.*')),";
  61. $themedef .= ");";
  62. sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
  63. self::$_createdThemes[] = $themename;
  64. SugarThemeRegistry::buildRegistry();
  65. return $themename;
  66. }
  67. public static function createAnonymousOldTheme()
  68. {
  69. $themename = 'TestTheme'.mt_rand();
  70. sugar_mkdir("themes/$themename/images",null,true);
  71. sugar_mkdir("themes/$themename/css",null,true);
  72. sugar_mkdir("themes/$themename/js",null,true);
  73. sugar_mkdir("themes/$themename/tpls",null,true);
  74. sugar_file_put_contents("themes/$themename/css/style.css","h2 { display: inline; }");
  75. sugar_file_put_contents("themes/$themename/css/yui.css",".yui { display: inline; }");
  76. sugar_file_put_contents("themes/$themename/js/style.js",'var dog = "cat";');
  77. sugar_touch("themes/$themename/images/Accounts.gif");
  78. sugar_touch("themes/$themename/images/fonts.big.icon.gif");
  79. sugar_touch("themes/$themename/tpls/header.tpl");
  80. $themedef = "<?php\n";
  81. $themedef .= "\$themedef = array(\n";
  82. $themedef .= "'name' => '$themename',";
  83. $themedef .= "'dirName' => '$themename',";
  84. $themedef .= "'description' => '$themename',";
  85. $themedef .= "'version' => array('exact_matches' => array('5.5.1')),";
  86. $themedef .= ");";
  87. sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
  88. self::$_createdThemes[] = $themename;
  89. SugarThemeRegistry::buildRegistry();
  90. return $themename;
  91. }
  92. public static function createAnonymousCustomTheme(
  93. $themename = ''
  94. )
  95. {
  96. if ( empty($themename) )
  97. $themename = 'TestThemeCustom'.mt_rand();
  98. create_custom_directory("themes/$themename/images/");
  99. create_custom_directory("themes/$themename/css/");
  100. create_custom_directory("themes/$themename/js/");
  101. sugar_touch("custom/themes/$themename/css/style.css");
  102. sugar_touch("custom/themes/$themename/js/style.js");
  103. sugar_touch("custom/themes/$themename/images/Accounts.gif");
  104. sugar_touch("custom/themes/$themename/images/fonts.big.icon.gif");
  105. $themedef = "<?php\n";
  106. $themedef .= "\$themedef = array(\n";
  107. $themedef .= "'name' => 'custom $themename',";
  108. $themedef .= "'dirName' => '$themename',";
  109. $themedef .= "'description' => 'custom $themename',";
  110. $themedef .= "'version' => array('regex_matches' => array('.*')),";
  111. $themedef .= ");";
  112. sugar_file_put_contents("custom/themes/$themename/themedef.php",$themedef);
  113. self::$_createdThemes[] = $themename;
  114. SugarThemeRegistry::buildRegistry();
  115. return $themename;
  116. }
  117. public static function createAnonymousChildTheme(
  118. $parentTheme
  119. )
  120. {
  121. $themename = 'TestThemeChild'.mt_rand();
  122. sugar_mkdir("themes/$themename/images",null,true);
  123. sugar_mkdir("themes/$themename/css",null,true);
  124. sugar_mkdir("themes/$themename/js",null,true);
  125. sugar_file_put_contents("themes/$themename/css/style.css","h3 { display: inline; }");
  126. sugar_file_put_contents("themes/$themename/css/yui.css",".yui { display: inline; }");
  127. sugar_file_put_contents("themes/$themename/js/style.js",'var bird = "frog";');
  128. $themedef = "<?php\n";
  129. $themedef .= "\$themedef = array(\n";
  130. $themedef .= "'name' => '$themename',";
  131. $themedef .= "'dirName' => '$themename',";
  132. $themedef .= "'parentTheme' => '".$parentTheme."',";
  133. $themedef .= "'description' => '$themename',";
  134. $themedef .= "'version' => array('regex_matches' => array('.*')),";
  135. $themedef .= ");";
  136. sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
  137. self::$_createdThemes[] = $themename;
  138. SugarThemeRegistry::buildRegistry();
  139. return $themename;
  140. }
  141. public static function createAnonymousRTLTheme()
  142. {
  143. $themename = 'TestTheme'.mt_rand();
  144. sugar_mkdir("themes/$themename/images",null,true);
  145. sugar_mkdir("themes/$themename/css",null,true);
  146. sugar_mkdir("themes/$themename/js",null,true);
  147. sugar_mkdir("themes/$themename/tpls",null,true);
  148. sugar_file_put_contents("themes/$themename/css/style.css","h2 { display: inline; }");
  149. sugar_file_put_contents("themes/$themename/css/yui.css",".yui { display: inline; }");
  150. sugar_file_put_contents("themes/$themename/js/style.js",'var dog = "cat";');
  151. sugar_touch("themes/$themename/images/Accounts.gif");
  152. sugar_touch("themes/$themename/images/fonts.big.icon.gif");
  153. sugar_touch("themes/$themename/tpls/header.tpl");
  154. $themedef = "<?php\n";
  155. $themedef .= "\$themedef = array(\n";
  156. $themedef .= "'name' => '$themename',";
  157. $themedef .= "'dirName' => '$themename',";
  158. $themedef .= "'description' => '$themename',";
  159. $themedef .= "'directionality' => 'rtl',";
  160. $themedef .= "'version' => array('regex_matches' => array('.*')),";
  161. $themedef .= ");";
  162. sugar_file_put_contents("themes/$themename/themedef.php",$themedef);
  163. self::$_createdThemes[] = $themename;
  164. SugarThemeRegistry::buildRegistry();
  165. return $themename;
  166. }
  167. public static function removeAllCreatedAnonymousThemes()
  168. {
  169. foreach (self::getCreatedThemeNames() as $name ) {
  170. if ( is_dir('themes/'.$name) )
  171. rmdir_recursive('themes/'.$name);
  172. if ( is_dir('custom/themes/'.$name) )
  173. rmdir_recursive('custom/themes/'.$name);
  174. if ( is_dir('cache/themes/'.$name) )
  175. rmdir_recursive('cache/themes/'.$name);
  176. }
  177. SugarThemeRegistry::buildRegistry();
  178. }
  179. public static function getCreatedThemeNames()
  180. {
  181. return self::$_createdThemes;
  182. }
  183. }