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 Bug45287_2Test extends Sugar_PHPUnit_Framework_TestCase
51 public function setup()
54 // Create Anon User setted on PDT TimeZone
55 $current_user = SugarTestUserUtilities::createAnonymousUser();
56 $current_user->setPreference('datef', "d/m/Y");
57 $current_user->setPreference('timef', "H:i:s");
58 $current_user->setPreference('timezone', "America/Los_Angeles");
60 // new object to avoid TZ caching
61 $this->timedate = new TimeDate();
63 $this->meetingsArr = array();
65 // Create a Bunch of Meetings
70 $this->meetingsArr[$cnt] = new Meeting();
71 $this->meetingsArr[$cnt]->name = 'Bug45287 Meeting ' . ($cnt + 1);
72 $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)));
73 $this->meetingsArr[$cnt]->save();
78 $this->searchDefs = array("Meetings" => array("layout" => array("basic_search" => array("name" => array("name" => "name",
82 "date_start" => array("name" => "date_start",
85 "type" => "datetimecombo",
92 $this->searchFields = array("Meetings" => array("name" => array("query_type" => "default"),
93 "date_start" => array("query_type" => "default"),
94 "range_date_start" => array("query_type" => "default",
95 "enable_range_search" => 1,
96 "is_date_field" => 1),
97 "range_date_start" => array("query_type" => "default",
98 "enable_range_search" => 1,
99 "is_date_field" => 1),
100 "start_range_date_start" => array("query_type" => "default",
101 "enable_range_search" => 1,
102 "is_date_field" => 1),
103 "end_range_date_start" => array("query_type" => "default",
104 "enable_range_search" => 1,
105 "is_date_field" => 1),
110 public function tearDown()
113 foreach ($this->meetingsArr as $m)
115 $GLOBALS['db']->query('DELETE FROM meetings WHERE id = \'' . $m->id . '\' ');
119 unset($this->meetingsArr);
120 unset($this->searchDefs);
121 unset($this->searchFields);
122 unset($this->timezone);
124 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
128 public function testRetrieveByExactDate()
130 global $current_user;
132 $_REQUEST = $_POST = array("module" => "Meetings",
134 "searchFormTab" => "basic_search",
137 "current_user_only_basic" => "0",
138 "favorites_only_basic" => "0",
139 "open_only_basic" => "0",
140 "date_start_basic_range_choice" => "=",
141 "range_date_start_basic" => "14/07/2011",
142 "start_range_date_start_basic" => "",
143 "end_range_date_start_basic" => "",
144 "button" => "Search",
147 $srch = new SearchForm(new Meeting(), "Meetings");
148 $srch->setup($this->searchDefs, $this->searchFields, "");
149 $srch->populateFromRequest();
150 $w = $srch->generateSearchWhere();
152 // Due to daylight savings, I cannot hardcode intervals...
153 $GMTDates = $this->timedate->getDayStartEndGMT("2011-07-14");
155 // Current User is on GMT-7.
156 // 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)
157 $expectedWhere = "meetings.date_start >= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDates['start']), 'datetime') .
158 " AND meetings.date_start <= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDates['end']), 'datetime');
159 $this->assertContains($expectedWhere, $w[0]);
163 public function testRetrieveByDaterange()
165 global $current_user;
167 $_REQUEST = $_POST = array("module" => "Meetings",
169 "searchFormTab" => "basic_search",
172 "current_user_only_basic" => "0",
173 "favorites_only_basic" => "0",
174 "open_only_basic" => "0",
175 "date_start_basic_range_choice" => "between",
176 "range_date_start_basic" => "",
177 "start_range_date_start_basic" => "13/07/2011",
178 "end_range_date_start_basic" => "14/07/2011",
179 "button" => "Search",
183 $srch = new SearchForm(new Meeting(), "Meetings");
184 $srch->setup($this->searchDefs, $this->searchFields, "");
185 $srch->populateFromRequest();
186 $w = $srch->generateSearchWhere();
188 // Due to daylight savings, I cannot hardcode intervals...
189 $GMTDatesStart = $this->timedate->getDayStartEndGMT("2011-07-13");
190 $GMTDatesEnd = $this->timedate->getDayStartEndGMT("2011-07-14");
192 // Current User is on GMT-7.
193 // 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)
194 $expectedWhere = "meetings.date_start >= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDatesStart['start']), 'datetime') .
195 " AND meetings.date_start <= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDatesEnd['end']), 'datetime');
196 $this->assertContains($expectedWhere, $w[0]);