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