]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Meetings/Bug45287_2Test.php
Release 6.5.10
[Github/sugarcrm.git] / tests / modules / Meetings / Bug45287_2Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 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
38 require_once 'modules/Accounts/Account.php';
39 require_once 'modules/Meetings/Meeting.php';
40 require_once 'include/SearchForm/SearchForm2.php';
41
42
43 class Bug45287_2Test extends Sugar_PHPUnit_Framework_TestCase
44 {
45     var $meetingsArr;
46     var $searchDefs;
47     var $searchFields;
48     var $timedate;
49
50
51     public function setup()
52     {
53         SugarTestHelper::setUp('app_strings');
54         global $current_user;
55         // Create Anon User setted on PDT TimeZone
56         $current_user = SugarTestUserUtilities::createAnonymousUser();
57         $current_user->setPreference('datef', "d/m/Y");
58         $current_user->setPreference('timef', "H:i:s");
59         $current_user->setPreference('timezone', "America/Los_Angeles");
60
61         // new object to avoid TZ caching
62         $this->timedate = new TimeDate();
63
64         $this->meetingsArr = array();
65
66         // Create a Bunch of Meetings
67         $d = 12;
68         $cnt = 0;
69         while ($d < 15)
70         {
71           $this->meetingsArr[$cnt] = new Meeting();
72           $this->meetingsArr[$cnt]->name = 'Bug45287 Meeting ' . ($cnt + 1);
73           $this->meetingsArr[$cnt]->date_start = $this->timedate->to_display_date_time(gmdate("Y-m-d H:i:s", mktime(10+$cnt, 30, 00, 7, $d, 2011)));
74           $this->meetingsArr[$cnt]->save();
75           $d++;
76           $cnt++;
77         }
78
79         $this->searchDefs = array("Meetings" => array("layout" => array("basic_search" => array("name" => array("name" => "name",
80                                                                                                                 "default" => true,
81                                                                                                                 "width" => "10%",
82                                                                                                                ),
83                                                                                                 "date_start" => array("name" => "date_start",
84                                                                                                                       "default" => true,
85                                                                                                                       "width" => "10%",
86                                                                                                                       "type" => "datetimecombo",
87                                                                                                                      ),
88                                                                                                ),
89                                                                        ),
90                                                      ),
91                                  );
92
93         $this->searchFields = array("Meetings" => array("name" => array("query_type" => "default"),
94                                                         "date_start" => array("query_type" => "default"),
95                                                         "range_date_start" => array("query_type" => "default",
96                                                                                     "enable_range_search" => 1,
97                                                                                     "is_date_field" => 1),
98                                                         "range_date_start" => array("query_type" => "default",
99                                                                                     "enable_range_search" => 1,
100                                                                                     "is_date_field" => 1),
101                                                         "start_range_date_start" => array("query_type" => "default",
102                                                                                           "enable_range_search" => 1,
103                                                                                           "is_date_field" => 1),
104                                                         "end_range_date_start" => array("query_type" => "default",
105                                                                                         "enable_range_search" => 1,
106                                                                                         "is_date_field" => 1),
107                                                        ),
108                                    );
109     }
110
111     public function tearDown()
112     {
113
114         foreach ($this->meetingsArr as $m)
115         {
116             $GLOBALS['db']->query('DELETE FROM meetings WHERE id = \'' . $m->id . '\' ');
117         }
118
119         unset($m);
120         unset($this->meetingsArr);
121         unset($this->searchDefs);
122         unset($this->searchFields);
123         unset($this->timezone);
124
125         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
126         SugarTestHelper::tearDown();
127     }
128
129
130     public function testRetrieveByExactDate()
131     {
132         global $current_user;
133
134         $_REQUEST = $_POST = array("module" => "Meetings",
135                                    "action" => "index",
136                                    "searchFormTab" => "basic_search",
137                                    "query" => "true",
138                                    "name_basic" => "",
139                                    "current_user_only_basic" => "0",
140                                    "favorites_only_basic" => "0",
141                                    "open_only_basic" => "0",
142                                    "date_start_basic_range_choice" => "=",
143                                    "range_date_start_basic" => "14/07/2011",
144                                    "start_range_date_start_basic" => "",
145                                    "end_range_date_start_basic" => "",
146                                    "button" => "Search",
147                                   );
148
149         $srch = new SearchForm(new Meeting(), "Meetings");
150         $srch->setup($this->searchDefs, $this->searchFields, "");
151         $srch->populateFromRequest();
152         $w = $srch->generateSearchWhere();
153
154         // Due to daylight savings, I cannot hardcode intervals...
155         $GMTDates = $this->timedate->getDayStartEndGMT("2011-07-14");
156
157         // Current User is on GMT-7.
158         // Asking for meeting of 14 July 2011, I expect to search (GMT) from 14 July at 07:00 until 15 July at 07:00 (excluded)
159         $expectedWhere = "meetings.date_start >= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDates['start']), 'datetime') .
160                 " AND meetings.date_start <= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDates['end']), 'datetime');
161         $this->assertContains($expectedWhere, $w[0]);
162     }
163
164
165     public function testRetrieveByDaterange()
166     {
167         global $current_user;
168
169         $_REQUEST = $_POST = array("module" => "Meetings",
170                                    "action" => "index",
171                                    "searchFormTab" => "basic_search",
172                                    "query" => "true",
173                                    "name_basic" => "",
174                                    "current_user_only_basic" => "0",
175                                    "favorites_only_basic" => "0",
176                                    "open_only_basic" => "0",
177                                    "date_start_basic_range_choice" => "between",
178                                    "range_date_start_basic" => "",
179                                    "start_range_date_start_basic" => "13/07/2011",
180                                    "end_range_date_start_basic" => "14/07/2011",
181                                    "button" => "Search",
182                                   );
183
184
185         $srch = new SearchForm(new Meeting(), "Meetings");
186         $srch->setup($this->searchDefs, $this->searchFields, "");
187         $srch->populateFromRequest();
188         $w = $srch->generateSearchWhere();
189
190         // Due to daylight savings, I cannot hardcode intervals...
191         $GMTDatesStart = $this->timedate->getDayStartEndGMT("2011-07-13");
192         $GMTDatesEnd = $this->timedate->getDayStartEndGMT("2011-07-14");
193  
194         // Current User is on GMT-7.
195         // Asking for meeting between 13 and 14 July 2011, I expect to search from 13 July at 07:00 until 15 July at 07:00 (excluded)
196         $expectedWhere = "meetings.date_start >= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDatesStart['start']), 'datetime') .
197                 " AND meetings.date_start <= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDatesEnd['end']), 'datetime');
198         $this->assertContains($expectedWhere, $w[0]);
199     }
200
201
202 }