]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Calls/CallHelperTest.php
Release 6.2.0
[Github/sugarcrm.git] / tests / modules / Calls / CallHelperTest.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('modules/Calls/Call.php');
38 require_once('modules/Calls/CallHelper.php');
39
40 class CallHelperTest extends Sugar_PHPUnit_Framework_TestCase
41 {
42     public function setup()
43     {
44         $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
45     }
46     
47     public function tearDown()
48     {
49         unset($GLOBALS['app_list_strings']);
50     }
51     
52     public function providerGetDurationMinutesOptions()
53     {
54         return array(
55             array('EditView',<<<EOHTML
56 <select id="duration_minutes"onchange="SugarWidgetScheduler.update_time();"tabindex="1" name="duration_minutes">
57 <OPTION value='0'>00</OPTION>
58 <OPTION selected value='15'>15</OPTION>
59 <OPTION value='30'>30</OPTION>
60 <OPTION value='45'>45</OPTION></select>
61 EOHTML
62                 ),
63             array('MassUpdate',<<<EOHTML
64 <select id="duration_minutes"tabindex="1" name="duration_minutes">
65 <OPTION value='0'>00</OPTION>
66 <OPTION selected value='15'>15</OPTION>
67 <OPTION value='30'>30</OPTION>
68 <OPTION value='45'>45</OPTION></select>
69 EOHTML
70                 ),
71             array('QuickCreate',<<<EOHTML
72 <select id="duration_minutes"onchange="SugarWidgetScheduler.update_time();"tabindex="1" name="duration_minutes">
73 <OPTION value='0'>00</OPTION>
74 <OPTION selected value='15'>15</OPTION>
75 <OPTION value='30'>30</OPTION>
76 <OPTION value='45'>45</OPTION></select>
77 EOHTML
78                 ),
79
80             array('DetailView','15'),
81         );
82     }
83     
84     /**
85      * @dataProvider providerGetDurationMinutesOptions
86      */
87         public function testGetDurationMinutesOptions(
88             $view,
89             $returnValue
90             )
91     {
92         $focus = new Call();
93         
94         $this->assertEquals(
95             getDurationMinutesOptions($focus,'','',$view),
96             $returnValue
97             );
98     }
99     
100     public function testGetDurationMinutesOptionsNonDefaultValue()
101     {
102         $focus = new Call();
103         $focus->duration_minutes = '30';
104         
105         $this->assertEquals(
106             getDurationMinutesOptions($focus,'','','DetailView'),
107             $focus->duration_minutes
108             );
109     }
110     
111     public function testGetDurationMinutesOptionsFromRequest()
112     {
113         $focus = new Call();
114         $_REQUEST['duration_minutes'] = '45';
115         
116         $this->assertEquals(
117             getDurationMinutesOptions($focus,'','','DetailView'),
118             $_REQUEST['duration_minutes']
119             );
120         
121         unset($_REQUEST['duration_minutes']);
122     }
123     
124     public function testGetDurationMinutesOptionsOtherValues()
125     {
126         $focus = new Call();
127         $focus->date_start = null;
128         $focus->duration_hours = null;
129         $focus->minutes_value_default = null;
130         
131         getDurationMinutesOptions($focus,'','','DetailView');
132         
133         $this->assertEquals($focus->date_start,$GLOBALS['timedate']->to_display_date(gmdate($GLOBALS['timedate']->get_date_time_format())));
134         $this->assertEquals($focus->duration_hours,'0');
135         $this->assertEquals($focus->duration_minutes,'1');
136     }
137     
138     public function providerGetReminderTime()
139     {
140         return array(
141             array('EditView',<<<EOHTML
142 <select id="reminder_time" name="reminder_time">
143 <OPTION value='60'>1 minute prior</OPTION>
144 <OPTION value='300'>5 minutes prior</OPTION>
145 <OPTION value='600'>10 minutes prior</OPTION>
146 <OPTION value='900'>15 minutes prior</OPTION>
147 <OPTION value='1800'>30 minutes prior</OPTION>
148 <OPTION value='3600'>1 hour prior</OPTION></select>
149 EOHTML
150                 ),
151             array('MassUpdate',<<<EOHTML
152 <select id="reminder_time" name="reminder_time">
153 <OPTION value='60'>1 minute prior</OPTION>
154 <OPTION value='300'>5 minutes prior</OPTION>
155 <OPTION value='600'>10 minutes prior</OPTION>
156 <OPTION value='900'>15 minutes prior</OPTION>
157 <OPTION value='1800'>30 minutes prior</OPTION>
158 <OPTION value='3600'>1 hour prior</OPTION></select>
159 EOHTML
160                 ),
161             array('SubpanelCreates',<<<EOHTML
162 <select id="reminder_time" name="reminder_time">
163 <OPTION value='60'>1 minute prior</OPTION>
164 <OPTION value='300'>5 minutes prior</OPTION>
165 <OPTION value='600'>10 minutes prior</OPTION>
166 <OPTION value='900'>15 minutes prior</OPTION>
167 <OPTION value='1800'>30 minutes prior</OPTION>
168 <OPTION value='3600'>1 hour prior</OPTION></select>
169 EOHTML
170                 ),
171             array('QuickCreate',<<<EOHTML
172 <select id="reminder_time" name="reminder_time">
173 <OPTION value='60'>1 minute prior</OPTION>
174 <OPTION value='300'>5 minutes prior</OPTION>
175 <OPTION value='600'>10 minutes prior</OPTION>
176 <OPTION value='900'>15 minutes prior</OPTION>
177 <OPTION value='1800'>30 minutes prior</OPTION>
178 <OPTION value='3600'>1 hour prior</OPTION></select>
179 EOHTML
180                 ),
181
182             array('DetailView',''),
183         );
184     }
185     
186     /**
187      * @dataProvider providerGetReminderTime
188      */
189         public function testGetReminderTime(
190             $view,
191             $returnValue
192             )
193     {
194         $focus = new Call();
195         
196         $this->assertEquals(
197             getReminderTime($focus,'','',$view),
198             $returnValue
199             );
200     }
201     
202     public function testGetReminderTimeNonDefaultValue()
203     {
204         $focus = new Call();
205         $focus->reminder_time = '600';
206         
207         $this->assertEquals(
208             getReminderTime($focus,'','','EditView'),
209             <<<EOHTML
210 <select id="reminder_time" name="reminder_time">
211 <OPTION value='60'>1 minute prior</OPTION>
212 <OPTION value='300'>5 minutes prior</OPTION>
213 <OPTION selected value='600'>10 minutes prior</OPTION>
214 <OPTION value='900'>15 minutes prior</OPTION>
215 <OPTION value='1800'>30 minutes prior</OPTION>
216 <OPTION value='3600'>1 hour prior</OPTION></select>
217 EOHTML
218             );
219     }
220     
221     public function testGetReminderTimeNonDefaultValueDetailView()
222     {
223         $focus = new Call();
224         $focus->reminder_time = '300';
225         
226         $this->assertEquals(
227             getReminderTime($focus,'','','DetailView'),
228             '5 minutes prior'
229             );
230     }
231     
232     public function testGetReminderTimeFromRequest()
233     {
234         $focus = new Call();
235         $_REQUEST['reminder_time'] = '900';
236         $_REQUEST['full_form'] = true;
237         
238         $this->assertEquals(
239             getReminderTime($focus,'','','EditView'),
240             <<<EOHTML
241 <select id="reminder_time" name="reminder_time">
242 <OPTION value='60'>1 minute prior</OPTION>
243 <OPTION value='300'>5 minutes prior</OPTION>
244 <OPTION value='600'>10 minutes prior</OPTION>
245 <OPTION selected value='900'>15 minutes prior</OPTION>
246 <OPTION value='1800'>30 minutes prior</OPTION>
247 <OPTION value='3600'>1 hour prior</OPTION></select>
248 EOHTML
249             );
250         
251         unset($_REQUEST['reminder_time']);
252         unset($_REQUEST['full_form']);
253     }
254     
255     public function testGetReminderTimeFromValue()
256     {
257         $focus = new Call();
258         unset($focus->reminder_time);
259         
260         $this->assertEquals(
261             getReminderTime($focus,'','1800','EditView'),
262             <<<EOHTML
263 <select id="reminder_time" name="reminder_time">
264 <OPTION value='60'>1 minute prior</OPTION>
265 <OPTION value='300'>5 minutes prior</OPTION>
266 <OPTION value='600'>10 minutes prior</OPTION>
267 <OPTION value='900'>15 minutes prior</OPTION>
268 <OPTION selected value='1800'>30 minutes prior</OPTION>
269 <OPTION value='3600'>1 hour prior</OPTION></select>
270 EOHTML
271             );
272     }
273 }