]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SugarTheme/SugarThemeRegistryTest.php
Release 6.2.0
[Github/sugarcrm.git] / tests / include / SugarTheme / SugarThemeRegistryTest.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 SugarThemeRegistryTest extends Sugar_PHPUnit_Framework_TestCase
42 {
43     private $_themeName;
44     private $_oldDefaultTheme;
45     
46     public function setup()
47     {
48         $this->_themeName = SugarTestThemeUtilities::createAnonymousTheme();
49         if ( isset($GLOBALS['sugar_config']['default_theme']) ) {
50             $this->_oldDefaultTheme = $GLOBALS['sugar_config']['default_theme'];
51         }
52         $GLOBALS['sugar_config']['default_theme'] = $this->_themeName;
53         SugarThemeRegistry::buildRegistry();
54     }
55     
56     public function tearDown()
57     {
58         SugarTestThemeUtilities::removeAllCreatedAnonymousThemes();
59         if ( isset($this->_oldDefaultTheme) ) {
60             $GLOBALS['sugar_config']['default_theme'] = $this->_oldDefaultTheme;
61         }
62     }
63     
64     public function testThemesRegistered()
65     {
66         $this->assertTrue(SugarThemeRegistry::exists($this->_themeName));
67     }
68     
69     public function testGetThemeObject()
70     {
71         $object = SugarThemeRegistry::get($this->_themeName);
72         
73         $this->assertInstanceOf('SugarTheme',$object);
74         $this->assertEquals($object->__toString(),$this->_themeName);
75     }
76     
77     /**
78      * @ticket 41635
79      */
80     public function testGetDefaultThemeObject()
81     {
82         $GLOBALS['sugar_config']['default_theme'] = $this->_themeName;
83         
84         $object = SugarThemeRegistry::getDefault();
85         
86         $this->assertInstanceOf('SugarTheme',$object);
87         $this->assertEquals($object->__toString(),$this->_themeName);
88     }
89     
90     /**
91      * @ticket 41635
92      */
93     public function testGetDefaultThemeObjectWhenDefaultThemeIsNotSet()
94     {
95         unset($GLOBALS['sugar_config']['default_theme']);
96         
97         $themename = array_pop(array_keys(SugarThemeRegistry::availableThemes()));
98         
99         $object = SugarThemeRegistry::getDefault();
100         
101         $this->assertInstanceOf('SugarTheme',$object);
102         $this->assertEquals($object->__toString(),$themename);
103     }
104     
105     public function testSetCurrentTheme()
106     {
107         SugarThemeRegistry::set($this->_themeName);
108         
109         $this->assertInstanceOf('SugarTheme',SugarThemeRegistry::current());
110         $this->assertEquals(SugarThemeRegistry::current()->__toString(),$this->_themeName);
111     }
112     
113     public function testInListOfAvailableThemes()
114     {
115         if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) {
116             $disabled_themes = $GLOBALS['sugar_config']['disabled_themes'];
117             unset($GLOBALS['sugar_config']['disabled_themes']);
118         }
119         
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]));
126         
127         if ( isset($disabled_themes) )
128             $GLOBALS['sugar_config']['disabled_themes'] = $disabled_themes;
129     }
130     
131     public function testDisabledThemeNotInListOfAvailableThemes()
132     {
133         if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) {
134             $disabled_themes = $GLOBALS['sugar_config']['disabled_themes'];
135             unset($GLOBALS['sugar_config']['disabled_themes']);
136         }
137         
138         $GLOBALS['sugar_config']['disabled_themes'] = $this->_themeName;
139         
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]));
146         
147         if ( isset($disabled_themes) )
148             $GLOBALS['sugar_config']['disabled_themes'] = $disabled_themes;
149     }
150     
151     public function testCustomThemeLoaded()
152     {
153         $customTheme = SugarTestThemeUtilities::createAnonymousCustomTheme($this->_themeName);
154         
155         SugarThemeRegistry::buildRegistry();
156         
157         $this->assertEquals(
158             SugarThemeRegistry::get($customTheme)->name,
159             'custom ' . $customTheme
160             );
161     }
162     
163     public function testDefaultThemedefFileHandled()
164     {
165         create_custom_directory('themes/default/');
166         sugar_file_put_contents('custom/themes/default/themedef.php','<?php $themedef = array("group_tabs" => false);');
167         
168         SugarThemeRegistry::buildRegistry();
169         
170         $this->assertEquals(
171             SugarThemeRegistry::get($this->_themeName)->group_tabs,
172             false
173             );
174         
175         unlink('custom/themes/default/themedef.php');
176     }
177     
178     public function testClearCacheAllThemes()
179     {
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');
183         
184         SugarThemeRegistry::clearAllCaches();
185         SugarThemeRegistry::buildRegistry();
186         
187         $this->assertFalse(isset(SugarThemeRegistry::get($this->_themeName)->_cssCache['style.css']),
188                             'File style.css shouldn\'t exist in cache');
189     }
190     
191     /**
192      * @ticket 35307
193      */
194     public function testOldThemeIsNotRecognized()
195     {
196         $themename = SugarTestThemeUtilities::createAnonymousOldTheme();
197         
198         $this->assertNull(SugarThemeRegistry::get($themename));
199     }
200 }