]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/Dashlets/DashletTest.php
Release 6.2.0
[Github/sugarcrm.git] / tests / include / Dashlets / DashletTest.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 class DashletTest extends Sugar_PHPUnit_Framework_TestCase
40 {
41     public function testConstructor() 
42     {
43         $dashlet = new Dashlet('unit_test_run');
44         
45         $this->assertEquals('unit_test_run',$dashlet->id);
46     }
47
48     public function testSetConfigureIconIfConfigurable()
49     {
50         $dashlet = new Dashlet('unit_test_run');
51         $dashlet->isConfigurable = true;
52         
53         $this->assertContains('SUGAR.mySugar.configureDashlet',$dashlet->setConfigureIcon());
54     }
55     
56     public function testSetConfigureIconIfNotConfigurable()
57     {
58         $dashlet = new Dashlet('unit_test_run');
59         $dashlet->isConfigurable = false;
60         
61         $this->assertNotContains('SUGAR.mySugar.configureDashlet',$dashlet->setConfigureIcon());
62     }
63     
64     public function testSetRefreshIconIfRefreshable()
65     {
66         $dashlet = new Dashlet('unit_test_run');
67         $dashlet->isRefreshable = true;
68         
69         $this->assertContains('SUGAR.mySugar.retrieveDashlet',$dashlet->setRefreshIcon());
70     }
71     
72     public function testSetRefreshIconIfNotRefreshable()
73     {
74         $dashlet = new Dashlet('unit_test_run');
75         $dashlet->isRefreshable = false;
76         
77         $this->assertNotContains('SUGAR.mySugar.retrieveDashlet',$dashlet->setRefreshIcon());
78     }
79     
80     public function testSetDeleteIconIfHomepageNotLocked()
81     {
82         $dashlet = new Dashlet('unit_test_run');
83         if ( isset($GLOBALS['sugar_config']['lock_homepage']) ) {
84             $oldlock_homepage = $GLOBALS['sugar_config']['lock_homepage'];
85         }
86         $GLOBALS['sugar_config']['lock_homepage'] = false;
87         
88         $result = $dashlet->setDeleteIcon();
89         
90         if ( isset($oldlock_homepage) ) {
91             $GLOBALS['sugar_config']['lock_homepage'] = $oldlock_homepage;
92         }
93         
94         $this->assertContains('SUGAR.mySugar.deleteDashlet',$result);
95     }
96     
97     public function testSetDeleteIconIfHomepageLocked()
98     {
99         $dashlet = new Dashlet('unit_test_run');
100         if ( isset($GLOBALS['sugar_config']['lock_homepage']) ) {
101             $oldlock_homepage = $GLOBALS['sugar_config']['lock_homepage'];
102         }
103         $GLOBALS['sugar_config']['lock_homepage'] = true;
104         
105         $result = $dashlet->setDeleteIcon();
106         
107         if ( isset($oldlock_homepage) ) {
108             $GLOBALS['sugar_config']['lock_homepage'] = $oldlock_homepage;
109         }
110         
111         $this->assertNotContains('SUGAR.mySugar.deleteDashlet',$result);
112     }
113     
114     public function testGetTitleDoesNothing()
115     {
116         $dashlet = new Dashlet('unit_test_run');
117         
118         $this->assertEmpty($dashlet->getTitle('foo'));
119     }
120     
121     public function testGetHeaderIfHomePageIsNotLocked()
122     {
123         $dashlet = $this->getMock('Dashlet',
124                                     array('setConfigureIcon','setRefreshIcon','setDeleteIcon'),
125                                     array('unit_test_run')
126                                     );
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'];
138         }
139         $GLOBALS['sugar_config']['lock_homepage'] = false;
140         
141         $result = $dashlet->getHeader('sometext');
142         
143         if ( isset($oldlock_homepage) ) {
144             $GLOBALS['sugar_config']['lock_homepage'] = $oldlock_homepage;
145         }
146         
147         $this->assertContains(
148             '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td width="99%">sometext</td>'
149                 . 'successconfiguresuccessrefreshsuccessdelete',
150             $result
151             );
152         
153         $this->assertContains(
154             '<div onmouseover="this.style.cursor = \'move\';" id="dashlet_header_unit_test_run"',
155             $result
156             );
157     }
158     
159     public function testGetHeaderIfHomePageIsLocked()
160     {
161         $dashlet = $this->getMock('Dashlet',
162                                     array('setConfigureIcon','setRefreshIcon','setDeleteIcon'),
163                                     array('unit_test_run')
164                                     );
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'];
176         }
177         $GLOBALS['sugar_config']['lock_homepage'] = true;
178         
179         $result = $dashlet->getHeader('sometext');
180         
181         if ( isset($oldlock_homepage) ) {
182             $GLOBALS['sugar_config']['lock_homepage'] = $oldlock_homepage;
183         }
184         
185         $this->assertContains(
186             '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td width="99%">sometext</td>'
187                 . 'successconfiguresuccessrefreshsuccessdelete',
188             $result
189             );
190         $this->assertContains(
191             '<div id="dashlet_header_unit_test_run"',
192             $result
193             );
194     }
195     
196     public function testGetFooter()
197     {
198         $dashlet = new Dashlet('unit_test_run');
199         
200         $this->assertEquals(
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()
203             );
204     }
205     
206     public function testDisplayReturnsNothing()
207     {
208         $dashlet = new Dashlet('unit_test_run');
209         
210         $this->assertEmpty($dashlet->display('foo'));
211     }
212     
213     public function testHasAccessReturnsTrue()
214     {
215         $dashlet = new Dashlet('unit_test_run');
216         
217         $this->assertTrue($dashlet->hasAccess());
218     }
219     
220     public function testDisplayOptionsDoesNothing()
221     {
222         $dashlet = new Dashlet('unit_test_run');
223         
224         $this->assertNull($dashlet->displayOptions());
225     }
226     
227     public function testProcessDoesNothing()
228     {
229         $dashlet = new Dashlet('unit_test_run');
230         
231         $this->assertNull($dashlet->process());
232     }
233     
234     public function testSaveOptionsDoesNothing()
235     {
236         $dashlet = new Dashlet('unit_test_run');
237         
238         $this->assertNull($dashlet->saveOptions(array()));
239     }
240 }