2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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 SugarThemeRegistryTest extends Sugar_PHPUnit_Framework_TestCase
44 private $_oldDefaultTheme;
46 public function setup()
48 $this->_themeName = SugarTestThemeUtilities::createAnonymousTheme();
49 if ( isset($GLOBALS['sugar_config']['default_theme']) ) {
50 $this->_oldDefaultTheme = $GLOBALS['sugar_config']['default_theme'];
52 $GLOBALS['sugar_config']['default_theme'] = $this->_themeName;
53 SugarThemeRegistry::buildRegistry();
56 public function tearDown()
58 SugarTestThemeUtilities::removeAllCreatedAnonymousThemes();
59 if ( isset($this->_oldDefaultTheme) ) {
60 $GLOBALS['sugar_config']['default_theme'] = $this->_oldDefaultTheme;
64 public function testThemesRegistered()
66 $this->assertTrue(SugarThemeRegistry::exists($this->_themeName));
69 public function testGetThemeObject()
71 $object = SugarThemeRegistry::get($this->_themeName);
73 $this->assertInstanceOf('SugarTheme',$object);
74 $this->assertEquals($object->__toString(),$this->_themeName);
80 public function testGetDefaultThemeObject()
82 $GLOBALS['sugar_config']['default_theme'] = $this->_themeName;
84 $object = SugarThemeRegistry::getDefault();
86 $this->assertInstanceOf('SugarTheme',$object);
87 $this->assertEquals($object->__toString(),$this->_themeName);
93 public function testGetDefaultThemeObjectWhenDefaultThemeIsNotSet()
95 unset($GLOBALS['sugar_config']['default_theme']);
97 $themename = array_pop(array_keys(SugarThemeRegistry::availableThemes()));
99 $object = SugarThemeRegistry::getDefault();
101 $this->assertInstanceOf('SugarTheme',$object);
102 $this->assertEquals($object->__toString(),$themename);
105 public function testSetCurrentTheme()
107 SugarThemeRegistry::set($this->_themeName);
109 $this->assertInstanceOf('SugarTheme',SugarThemeRegistry::current());
110 $this->assertEquals(SugarThemeRegistry::current()->__toString(),$this->_themeName);
113 public function testInListOfAvailableThemes()
115 if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) {
116 $disabled_themes = $GLOBALS['sugar_config']['disabled_themes'];
117 unset($GLOBALS['sugar_config']['disabled_themes']);
120 $themes = SugarThemeRegistry::availableThemes();
121 $this->assertTrue(isset($themes[$this->_themeName]));
122 $themes = SugarThemeRegistry::unAvailableThemes();
123 $this->assertTrue(!isset($themes[$this->_themeName]));
124 $themes = SugarThemeRegistry::allThemes();
125 $this->assertTrue(isset($themes[$this->_themeName]));
127 if ( isset($disabled_themes) )
128 $GLOBALS['sugar_config']['disabled_themes'] = $disabled_themes;
131 public function testDisabledThemeNotInListOfAvailableThemes()
133 if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) {
134 $disabled_themes = $GLOBALS['sugar_config']['disabled_themes'];
135 unset($GLOBALS['sugar_config']['disabled_themes']);
138 $GLOBALS['sugar_config']['disabled_themes'] = $this->_themeName;
140 $themes = SugarThemeRegistry::availableThemes();
141 $this->assertTrue(!isset($themes[$this->_themeName]));
142 $themes = SugarThemeRegistry::unAvailableThemes();
143 $this->assertTrue(isset($themes[$this->_themeName]));
144 $themes = SugarThemeRegistry::allThemes();
145 $this->assertTrue(isset($themes[$this->_themeName]));
147 if ( isset($disabled_themes) )
148 $GLOBALS['sugar_config']['disabled_themes'] = $disabled_themes;
151 public function testCustomThemeLoaded()
153 $customTheme = SugarTestThemeUtilities::createAnonymousCustomTheme($this->_themeName);
155 SugarThemeRegistry::buildRegistry();
158 SugarThemeRegistry::get($customTheme)->name,
159 'custom ' . $customTheme
163 public function testDefaultThemedefFileHandled()
165 create_custom_directory('themes/default/');
166 sugar_file_put_contents('custom/themes/default/themedef.php','<?php $themedef = array("group_tabs" => false);');
168 SugarThemeRegistry::buildRegistry();
171 SugarThemeRegistry::get($this->_themeName)->group_tabs,
175 unlink('custom/themes/default/themedef.php');
178 public function testClearCacheAllThemes()
180 SugarThemeRegistry::get($this->_themeName)->getCSSURL('style.css');
181 $this->assertTrue(isset(SugarThemeRegistry::get($this->_themeName)->_cssCache['style.css']),
182 'File style.css should exist in cache');
184 SugarThemeRegistry::clearAllCaches();
185 SugarThemeRegistry::buildRegistry();
187 $this->assertFalse(isset(SugarThemeRegistry::get($this->_themeName)->_cssCache['style.css']),
188 'File style.css shouldn\'t exist in cache');
194 public function testOldThemeIsNotRecognized()
196 $themename = SugarTestThemeUtilities::createAnonymousOldTheme();
198 $this->assertNull(SugarThemeRegistry::get($themename));