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