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 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;
61 SugarThemeRegistry::set($GLOBALS['sugar_config']['default_theme']);
65 public function testThemesRegistered()
67 $this->assertTrue(SugarThemeRegistry::exists($this->_themeName));
70 public function testGetThemeObject()
72 $object = SugarThemeRegistry::get($this->_themeName);
74 $this->assertInstanceOf('SugarTheme',$object);
75 $this->assertEquals($object->__toString(),$this->_themeName);
81 public function testGetDefaultThemeObject()
83 $GLOBALS['sugar_config']['default_theme'] = $this->_themeName;
85 $object = SugarThemeRegistry::getDefault();
87 $this->assertInstanceOf('SugarTheme',$object);
88 $this->assertEquals($object->__toString(),$this->_themeName);
94 public function testGetDefaultThemeObjectWhenDefaultThemeIsNotSet()
96 unset($GLOBALS['sugar_config']['default_theme']);
98 $themename = array_pop(array_keys(SugarThemeRegistry::availableThemes()));
100 $object = SugarThemeRegistry::getDefault();
102 $this->assertInstanceOf('SugarTheme',$object);
103 $this->assertEquals($object->__toString(),$themename);
106 public function testSetCurrentTheme()
108 SugarThemeRegistry::set($this->_themeName);
110 $this->assertInstanceOf('SugarTheme',SugarThemeRegistry::current());
111 $this->assertEquals(SugarThemeRegistry::current()->__toString(),$this->_themeName);
114 public function testInListOfAvailableThemes()
116 if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) {
117 $disabled_themes = $GLOBALS['sugar_config']['disabled_themes'];
118 unset($GLOBALS['sugar_config']['disabled_themes']);
121 $themes = SugarThemeRegistry::availableThemes();
122 $this->assertTrue(isset($themes[$this->_themeName]));
123 $themes = SugarThemeRegistry::unAvailableThemes();
124 $this->assertTrue(!isset($themes[$this->_themeName]));
125 $themes = SugarThemeRegistry::allThemes();
126 $this->assertTrue(isset($themes[$this->_themeName]));
128 if ( isset($disabled_themes) )
129 $GLOBALS['sugar_config']['disabled_themes'] = $disabled_themes;
132 public function testDisabledThemeNotInListOfAvailableThemes()
134 if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) {
135 $disabled_themes = $GLOBALS['sugar_config']['disabled_themes'];
136 unset($GLOBALS['sugar_config']['disabled_themes']);
139 $GLOBALS['sugar_config']['disabled_themes'] = $this->_themeName;
141 $themes = SugarThemeRegistry::availableThemes();
142 $this->assertTrue(!isset($themes[$this->_themeName]));
143 $themes = SugarThemeRegistry::unAvailableThemes();
144 $this->assertTrue(isset($themes[$this->_themeName]));
145 $themes = SugarThemeRegistry::allThemes();
146 $this->assertTrue(isset($themes[$this->_themeName]));
148 if ( isset($disabled_themes) )
149 $GLOBALS['sugar_config']['disabled_themes'] = $disabled_themes;
152 public function testCustomThemeLoaded()
154 $customTheme = SugarTestThemeUtilities::createAnonymousCustomTheme($this->_themeName);
156 SugarThemeRegistry::buildRegistry();
159 SugarThemeRegistry::get($customTheme)->name,
160 'custom ' . $customTheme
164 public function testDefaultThemedefFileHandled()
166 create_custom_directory('themes/default/');
167 sugar_file_put_contents('custom/themes/default/themedef.php','<?php $themedef = array("group_tabs" => false);');
169 SugarThemeRegistry::buildRegistry();
172 SugarThemeRegistry::get($this->_themeName)->group_tabs,
176 unlink('custom/themes/default/themedef.php');
179 public function testClearCacheAllThemes()
181 SugarThemeRegistry::get($this->_themeName)->getCSSURL('style.css');
182 $this->assertTrue(isset(SugarThemeRegistry::get($this->_themeName)->_cssCache['style.css']),
183 'File style.css should exist in cache');
185 SugarThemeRegistry::clearAllCaches();
186 SugarThemeRegistry::buildRegistry();
188 $this->assertFalse(isset(SugarThemeRegistry::get($this->_themeName)->_cssCache['style.css']),
189 'File style.css shouldn\'t exist in cache');
195 public function testOldThemeIsNotRecognized()
197 $themename = SugarTestThemeUtilities::createAnonymousOldTheme();
199 $this->assertNull(SugarThemeRegistry::get($themename));