2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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()
53 SugarTestHelper::setUp('app_strings');
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");
61 // new object to avoid TZ caching
62 $this->timedate = new TimeDate();
64 $this->meetingsArr = array();
66 // Create a Bunch of Meetings
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();
79 $this->searchDefs = array("Meetings" => array("layout" => array("basic_search" => array("name" => array("name" => "name",
83 "date_start" => array("name" => "date_start",
86 "type" => "datetimecombo",
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),
111 public function tearDown()
114 foreach ($this->meetingsArr as $m)
116 $GLOBALS['db']->query('DELETE FROM meetings WHERE id = \'' . $m->id . '\' ');
120 unset($this->meetingsArr);
121 unset($this->searchDefs);
122 unset($this->searchFields);
123 unset($this->timezone);
125 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
126 SugarTestHelper::tearDown();
130 public function testRetrieveByExactDate()
132 global $current_user;
134 $_REQUEST = $_POST = array("module" => "Meetings",
136 "searchFormTab" => "basic_search",
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",
149 $srch = new SearchForm(new Meeting(), "Meetings");
150 $srch->setup($this->searchDefs, $this->searchFields, "");
151 $srch->populateFromRequest();
152 $w = $srch->generateSearchWhere();
154 // Due to daylight savings, I cannot hardcode intervals...
155 $GMTDates = $this->timedate->getDayStartEndGMT("2011-07-14");
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]);
165 public function testRetrieveByDaterange()
167 global $current_user;
169 $_REQUEST = $_POST = array("module" => "Meetings",
171 "searchFormTab" => "basic_search",
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",
185 $srch = new SearchForm(new Meeting(), "Meetings");
186 $srch->setup($this->searchDefs, $this->searchFields, "");
187 $srch->populateFromRequest();
188 $w = $srch->generateSearchWhere();
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");
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]);