2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 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 ********************************************************************************/
37 require_once 'include/Dashlets/Dashlet.php';
42 class DashletAutoRefreshTest extends Sugar_PHPUnit_Framework_TestCase
44 public function setup()
46 if ( isset($GLOBALS['sugar_config']['dashlet_auto_refresh_min']) ) {
47 $this->backup_dashlet_auto_refresh_min = $GLOBALS['sugar_config']['dashlet_auto_refresh_min'];
49 unset($GLOBALS['sugar_config']['dashlet_auto_refresh_min']);
52 public function tearDown()
54 if ( isset($this->backup_dashlet_auto_refresh_min) ) {
55 $GLOBALS['sugar_config']['dashlet_auto_refresh_min'] = $this->backup_dashlet_auto_refresh_min;
59 public function testIsAutoRefreshableIfRefreshable()
61 $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
62 $dashlet->isRefreshable = true;
64 $this->assertTrue($dashlet->isAutoRefreshable());
67 public function testIsNotAutoRefreshableIfNotRefreshable()
69 $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
70 $dashlet->isRefreshable = false;
72 $this->assertFalse($dashlet->isAutoRefreshable());
75 public function testReturnCorrectAutoRefreshOptionsWhenMinIsSet()
77 $langpack = new SugarTestLangPackCreator();
78 $langpack->setAppListString('dashlet_auto_refresh_options',
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',
90 $GLOBALS['sugar_config']['dashlet_auto_refresh_min'] = 60;
92 $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
93 $options = $dashlet->getAutoRefreshOptions();
97 '60' => 'Every 1 minute',
98 '180' => 'Every 3 minutes',
99 '300' => 'Every 5 minutes',
100 '600' => 'Every 10 minutes',
108 public function testReturnCorrectAutoRefreshOptionsWhenMinIsNotSet()
110 $langpack = new SugarTestLangPackCreator();
111 $langpack->setAppListString('dashlet_auto_refresh_options',
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',
123 $dashlet = new DashletAutoRefreshTestMock('unit_test_run');
124 $options = $dashlet->getAutoRefreshOptions();
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',
140 public function testProcessAutoRefreshReturnsAutoRefreshTemplateNormally()
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';
149 $this->assertNotEmpty($dashlet->processAutoRefresh());
152 public function testProcessAutoRefreshReturnsNothingIfDashletIsNotRefreshable()
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';
161 $this->assertEmpty($dashlet->processAutoRefresh());
164 public function testProcessAutoRefreshReturnsNothingIfAutoRefreshingIsDisabled()
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';
173 $this->assertEmpty($dashlet->processAutoRefresh());
177 class DashletAutoRefreshTestMock extends Dashlet
179 public function isAutoRefreshable()
181 return parent::isAutoRefreshable();
184 public function getAutoRefreshOptions()
186 return parent::getAutoRefreshOptions();
189 public function processAutoRefresh()
191 return parent::processAutoRefresh();