]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/Dashlets/DashletAutoRefreshTest.php
Release 6.2.0
[Github/sugarcrm.git] / tests / include / Dashlets / DashletAutoRefreshTest.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 require_once 'include/Dashlets/Dashlet.php';
38
39 /**
40  * @ticket 33948
41  */
42 class DashletAutoRefreshTest extends Sugar_PHPUnit_Framework_TestCase
43 {
44     public function setup()
45     {
46         if ( isset($GLOBALS['sugar_config']['dashlet_auto_refresh_min']) ) {
47             $this->backup_dashlet_auto_refresh_min = $GLOBALS['sugar_config']['dashlet_auto_refresh_min'];
48         }
49         unset($GLOBALS['sugar_config']['dashlet_auto_refresh_min']);
50     }
51     
52     public function tearDown()
53     {
54         if ( isset($this->backup_dashlet_auto_refresh_min) ) {
55             $GLOBALS['sugar_config']['dashlet_auto_refresh_min'] = $this->backup_dashlet_auto_refresh_min;
56         }
57     }
58     
59     public function testIsAutoRefreshableIfRefreshable() 
60     {
61         $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
62         $dashlet->isRefreshable = true;
63         
64         $this->assertTrue($dashlet->isAutoRefreshable());
65     }
66     
67     public function testIsNotAutoRefreshableIfNotRefreshable() 
68     {
69         $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
70         $dashlet->isRefreshable = false;
71         
72         $this->assertFalse($dashlet->isAutoRefreshable());
73     }
74   
75     public function testReturnCorrectAutoRefreshOptionsWhenMinIsSet() 
76     {
77         $langpack = new SugarTestLangPackCreator();
78         $langpack->setAppListString('dashlet_auto_refresh_options',
79             array(
80                 '-1'    => 'Never',
81                 '30'    => 'Every 30 seconds',
82                 '60'    => 'Every 1 minute',
83                 '180'   => 'Every 3 minutes',
84                 '300'   => 'Every 5 minutes',
85                 '600'   => 'Every 10 minutes',
86                 )
87             );
88         $langpack->save();
89     
90         $GLOBALS['sugar_config']['dashlet_auto_refresh_min'] = 60;
91         
92         $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
93         $options = $dashlet->getAutoRefreshOptions();
94         $this->assertEquals(
95             array(
96                 '-1'    => 'Never',
97                 '60'    => 'Every 1 minute',
98                 '180'   => 'Every 3 minutes',
99                 '300'   => 'Every 5 minutes',
100                 '600'   => 'Every 10 minutes',
101                 ),
102             $options
103             );
104         
105         unset($langpack);
106     }
107     
108     public function testReturnCorrectAutoRefreshOptionsWhenMinIsNotSet() 
109     {
110         $langpack = new SugarTestLangPackCreator();
111         $langpack->setAppListString('dashlet_auto_refresh_options',
112             array(
113                 '-1'    => 'Never',
114                 '30'    => 'Every 30 seconds',
115                 '60'    => 'Every 1 minute',
116                 '180'   => 'Every 3 minutes',
117                 '300'   => 'Every 5 minutes',
118                 '600'   => 'Every 10 minutes',
119                 )
120             );
121         $langpack->save();
122     
123         $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
124         $options = $dashlet->getAutoRefreshOptions();
125         $this->assertEquals(
126             array(
127                 '-1'    => 'Never',
128                 '30'    => 'Every 30 seconds',
129                 '60'    => 'Every 1 minute',
130                 '180'   => 'Every 3 minutes',
131                 '300'   => 'Every 5 minutes',
132                 '600'   => 'Every 10 minutes',
133                 ),
134             $options
135             );
136         
137         unset($langpack);
138     }
139     
140     public function testProcessAutoRefreshReturnsAutoRefreshTemplateNormally()
141     {
142         $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
143         $dashlet->isRefreshable = true;
144         $_REQUEST['module'] = 'unit_test';
145         $_REQUEST['action'] = 'unit_test';
146         $dashlet->seedBean = new stdClass;
147         $dashlet->seedBean->object_name = 'unit_test';
148         
149         $this->assertNotEmpty($dashlet->processAutoRefresh());
150     }
151     
152     public function testProcessAutoRefreshReturnsNothingIfDashletIsNotRefreshable()
153     {
154         $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
155         $dashlet->isRefreshable = false;
156         $_REQUEST['module'] = 'unit_test';
157         $_REQUEST['action'] = 'unit_test';
158         $dashlet->seedBean = new stdClass;
159         $dashlet->seedBean->object_name = 'unit_test';
160         
161         $this->assertEmpty($dashlet->processAutoRefresh());
162     }
163     
164     public function testProcessAutoRefreshReturnsNothingIfAutoRefreshingIsDisabled()
165     {
166         $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
167         $GLOBALS['sugar_config']['dashlet_auto_refresh_min'] = -1;
168         $_REQUEST['module'] = 'unit_test';
169         $_REQUEST['action'] = 'unit_test';
170         $dashlet->seedBean = new stdClass;
171         $dashlet->seedBean->object_name = 'unit_test';
172         
173         $this->assertEmpty($dashlet->processAutoRefresh());
174     }
175 }
176
177 class DashletAutoRefreshTestMock extends Dashlet
178 {
179     public function isAutoRefreshable() 
180     {
181         return parent::isAutoRefreshable();
182     }
183     
184     public function getAutoRefreshOptions() 
185     {
186         return parent::getAutoRefreshOptions();
187     }
188     
189     public function processAutoRefresh() 
190     {
191         return parent::processAutoRefresh();
192     }
193 }