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 ********************************************************************************/
38 require_once 'modules/Accounts/Account.php';
39 require_once 'modules/Meetings/Meeting.php';
40 require_once 'include/SearchForm/SearchForm2.php';
43 class Bug45287Test extends Sugar_PHPUnit_Framework_TestCase
50 public function setup()
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");
59 // new object to avoid TZ caching
60 $this->timedate = new TimeDate();
62 $this->meetingsArr = array();
64 // Create a Bunch of Meetings
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();
77 $this->searchDefs = array("Meetings" => array("layout" => array("basic_search" => array("name" => array("name" => "name",
81 "date_start" => array("name" => "date_start",
84 "type" => "datetimecombo",
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),
109 public function tearDown()
112 foreach ($this->meetingsArr as $m)
114 $GLOBALS['db']->query('DELETE FROM meetings WHERE id = \'' . $m->id . '\' ');
118 unset($this->meetingsArr);
119 unset($this->searchDefs);
120 unset($this->searchFields);
121 unset($this->timedate);
123 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
127 public function testRetrieveByExactDate()
129 global $current_user;
131 $_REQUEST = $_POST = array("module" => "Meetings",
133 "searchFormTab" => "basic_search",
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",
146 $srch = new SearchForm(new Meeting(), "Meetings");
147 $srch->setup($this->searchDefs, $this->searchFields, "");
148 $srch->populateFromRequest();
149 $w = $srch->generateSearchWhere();
151 // Due to daylight savings, I cannot hardcode intervals...
152 $GMTDates = $this->timedate->getDayStartEndGMT("2011-07-14");
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]);
162 public function testRetrieveByDaterange()
164 global $current_user;
166 $_REQUEST = $_POST = array("module" => "Meetings",
168 "searchFormTab" => "basic_search",
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",
182 $srch = new SearchForm(new Meeting(), "Meetings");
183 $srch->setup($this->searchDefs, $this->searchFields, "");
184 $srch->populateFromRequest();
185 $w = $srch->generateSearchWhere();
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");
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]);