2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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';
39 class DashletTest extends Sugar_PHPUnit_Framework_TestCase
41 public function testConstructor()
43 $dashlet = new Dashlet('unit_test_run');
45 $this->assertEquals('unit_test_run',$dashlet->id);
48 public function testSetConfigureIconIfConfigurable()
50 $dashlet = new Dashlet('unit_test_run');
51 $dashlet->isConfigurable = true;
53 $this->assertContains('SUGAR.mySugar.configureDashlet',$dashlet->setConfigureIcon());
56 public function testSetConfigureIconIfNotConfigurable()
58 $dashlet = new Dashlet('unit_test_run');
59 $dashlet->isConfigurable = false;
61 $this->assertNotContains('SUGAR.mySugar.configureDashlet',$dashlet->setConfigureIcon());
64 public function testSetRefreshIconIfRefreshable()
66 $dashlet = new Dashlet('unit_test_run');
67 $dashlet->isRefreshable = true;
69 $this->assertContains('SUGAR.mySugar.retrieveDashlet',$dashlet->setRefreshIcon());
72 public function testSetRefreshIconIfNotRefreshable()
74 $dashlet = new Dashlet('unit_test_run');
75 $dashlet->isRefreshable = false;
77 $this->assertNotContains('SUGAR.mySugar.retrieveDashlet',$dashlet->setRefreshIcon());
80 public function testSetDeleteIconIfHomepageNotLocked()
82 $dashlet = new Dashlet('unit_test_run');
83 if ( isset($GLOBALS['sugar_config']['lock_homepage']) ) {
84 $oldlock_homepage = $GLOBALS['sugar_config']['lock_homepage'];
86 $GLOBALS['sugar_config']['lock_homepage'] = false;
88 $result = $dashlet->setDeleteIcon();
90 if ( isset($oldlock_homepage) ) {
91 $GLOBALS['sugar_config']['lock_homepage'] = $oldlock_homepage;
94 $this->assertContains('SUGAR.mySugar.deleteDashlet',$result);
97 public function testSetDeleteIconIfHomepageLocked()
99 $dashlet = new Dashlet('unit_test_run');
100 if ( isset($GLOBALS['sugar_config']['lock_homepage']) ) {
101 $oldlock_homepage = $GLOBALS['sugar_config']['lock_homepage'];
103 $GLOBALS['sugar_config']['lock_homepage'] = true;
105 $result = $dashlet->setDeleteIcon();
107 if ( isset($oldlock_homepage) ) {
108 $GLOBALS['sugar_config']['lock_homepage'] = $oldlock_homepage;
111 $this->assertNotContains('SUGAR.mySugar.deleteDashlet',$result);
114 public function testGetTitleDoesNothing()
116 $dashlet = new Dashlet('unit_test_run');
118 $this->assertEmpty($dashlet->getTitle('foo'));
121 public function testGetHeaderIfHomePageIsNotLocked()
123 $dashlet = $this->getMock('Dashlet',
124 array('setConfigureIcon','setRefreshIcon','setDeleteIcon'),
125 array('unit_test_run')
127 $dashlet->expects($this->any())
128 ->method('setConfigureIcon')
129 ->will($this->returnValue('successconfigure'));
130 $dashlet->expects($this->any())
131 ->method('setRefreshIcon')
132 ->will($this->returnValue('successrefresh'));
133 $dashlet->expects($this->any())
134 ->method('setDeleteIcon')
135 ->will($this->returnValue('successdelete'));
136 if ( isset($GLOBALS['sugar_config']['lock_homepage']) ) {
137 $oldlock_homepage = $GLOBALS['sugar_config']['lock_homepage'];
139 $GLOBALS['sugar_config']['lock_homepage'] = false;
141 $result = $dashlet->getHeader('sometext');
143 if ( isset($oldlock_homepage) ) {
144 $GLOBALS['sugar_config']['lock_homepage'] = $oldlock_homepage;
147 $this->assertContains(
148 '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td width="99%">sometext</td>'
149 . 'successconfiguresuccessrefreshsuccessdelete',
153 $this->assertContains(
154 '<div onmouseover="this.style.cursor = \'move\';" id="dashlet_header_unit_test_run"',
159 public function testGetHeaderIfHomePageIsLocked()
161 $dashlet = $this->getMock('Dashlet',
162 array('setConfigureIcon','setRefreshIcon','setDeleteIcon'),
163 array('unit_test_run')
165 $dashlet->expects($this->any())
166 ->method('setConfigureIcon')
167 ->will($this->returnValue('successconfigure'));
168 $dashlet->expects($this->any())
169 ->method('setRefreshIcon')
170 ->will($this->returnValue('successrefresh'));
171 $dashlet->expects($this->any())
172 ->method('setDeleteIcon')
173 ->will($this->returnValue('successdelete'));
174 if ( isset($GLOBALS['sugar_config']['lock_homepage']) ) {
175 $oldlock_homepage = $GLOBALS['sugar_config']['lock_homepage'];
177 $GLOBALS['sugar_config']['lock_homepage'] = true;
179 $result = $dashlet->getHeader('sometext');
181 if ( isset($oldlock_homepage) ) {
182 $GLOBALS['sugar_config']['lock_homepage'] = $oldlock_homepage;
185 $this->assertContains(
186 '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td width="99%">sometext</td>'
187 . 'successconfiguresuccessrefreshsuccessdelete',
190 $this->assertContains(
191 '<div id="dashlet_header_unit_test_run"',
196 public function testGetFooter()
198 $dashlet = new Dashlet('unit_test_run');
201 '</div><div class="mr"></div></div><div class="ft"><div class="bl"></div><div class="ft-center"></div><div class="br"></div></div>',
202 $dashlet->getFooter()
206 public function testDisplayReturnsNothing()
208 $dashlet = new Dashlet('unit_test_run');
210 $this->assertEmpty($dashlet->display('foo'));
213 public function testHasAccessReturnsTrue()
215 $dashlet = new Dashlet('unit_test_run');
217 $this->assertTrue($dashlet->hasAccess());
220 public function testDisplayOptionsDoesNothing()
222 $dashlet = new Dashlet('unit_test_run');
224 $this->assertNull($dashlet->displayOptions());
227 public function testProcessDoesNothing()
229 $dashlet = new Dashlet('unit_test_run');
231 $this->assertNull($dashlet->process());
234 public function testSaveOptionsDoesNothing()
236 $dashlet = new Dashlet('unit_test_run');
238 $this->assertNull($dashlet->saveOptions(array()));