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
49 public function setup()
51 global $current_user, $timedate;
52 // Create Anon User setted on GMT+2 TimeZone
53 $current_user = SugarTestUserUtilities::createAnonymousUser();
54 $current_user->setPreference('datef', "d/m/Y");
55 $current_user->setPreference('timef', "H:i:s");
56 $current_user->setPreference('timezone', "Europe/Rome");
58 // new object to avoid TZ caching
59 $timedate = new TimeDate();
61 $this->meetingsArr = array();
63 // Create a Bunch of Meetings
68 $this->meetingsArr[$cnt] = new Meeting();
69 $this->meetingsArr[$cnt]->name = 'Bug45287 Meeting ' . ($cnt + 1);
70 $this->meetingsArr[$cnt]->date_start = $timedate->to_display_date_time(gmdate("Y-m-d H:i:s", mktime(10+$cnt, 30, 00, 7, $d, 2011)));
71 $this->meetingsArr[$cnt]->save();
76 $this->searchDefs = array("Meetings" => array("layout" => array("basic_search" => array("name" => array("name" => "name",
80 "date_start" => array("name" => "date_start",
83 "type" => "datetimecombo",
90 $this->searchFields = array("Meetings" => array("name" => array("query_type" => "default"),
91 "date_start" => array("query_type" => "default"),
92 "range_date_start" => array("query_type" => "default",
93 "enable_range_search" => 1,
94 "is_date_field" => 1),
95 "range_date_start" => array("query_type" => "default",
96 "enable_range_search" => 1,
97 "is_date_field" => 1),
98 "start_range_date_start" => array("query_type" => "default",
99 "enable_range_search" => 1,
100 "is_date_field" => 1),
101 "end_range_date_start" => array("query_type" => "default",
102 "enable_range_search" => 1,
103 "is_date_field" => 1),
108 public function tearDown()
111 foreach ($this->meetingsArr as $m)
113 $GLOBALS['db']->query('DELETE FROM meetings WHERE id = \'' . $m->id . '\' ');
117 unset($this->meetingsArr);
118 unset($this->searchDefs);
119 unset($this->searchFields);
121 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
125 public function testRetrieveByExactDate()
127 global $current_user, $timedate;
129 $_REQUEST = $_POST = array("module" => "Meetings",
131 "searchFormTab" => "basic_search",
134 "current_user_only_basic" => "0",
135 "favorites_only_basic" => "0",
136 "open_only_basic" => "0",
137 "date_start_basic_range_choice" => "=",
138 "range_date_start_basic" => "14/07/2011",
139 "start_range_date_start_basic" => "",
140 "end_range_date_start_basic" => "",
141 "button" => "Search",
144 $srch = new SearchForm(new Meeting(), "Meetings");
145 $srch->setup($this->searchDefs, $this->searchFields, "");
146 $srch->populateFromRequest();
147 $w = $srch->generateSearchWhere();
149 // Due to daylight savings, I cannot hardcode intervals...
150 $GMTDates = $timedate->getDayStartEndGMT("2011-07-14");
152 // Current User is on GMT+2.
153 // 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)
154 $expectedWhere = "meetings.date_start >= '" . $GMTDates['start'] . "' AND meetings.date_start <= '" . $GMTDates['end'] . "'";
155 $this->assertEquals($w[0], $expectedWhere);
159 public function testRetrieveByDaterange()
161 global $current_user, $timedate;
163 $_REQUEST = $_POST = array("module" => "Meetings",
165 "searchFormTab" => "basic_search",
168 "current_user_only_basic" => "0",
169 "favorites_only_basic" => "0",
170 "open_only_basic" => "0",
171 "date_start_basic_range_choice" => "between",
172 "range_date_start_basic" => "",
173 "start_range_date_start_basic" => "13/07/2011",
174 "end_range_date_start_basic" => "14/07/2011",
175 "button" => "Search",
179 $srch = new SearchForm(new Meeting(), "Meetings");
180 $srch->setup($this->searchDefs, $this->searchFields, "");
181 $srch->populateFromRequest();
182 $w = $srch->generateSearchWhere();
184 // Due to daylight savings, I cannot hardcode intervals...
185 $GMTDatesStart = $timedate->getDayStartEndGMT("2011-07-13");
186 $GMTDatesEnd = $timedate->getDayStartEndGMT("2011-07-14");
188 // Current User is on GMT+2.
189 // 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)
190 $expectedWhere = "meetings.date_start >= '" . $GMTDatesStart['start'] . "' AND meetings.date_start <= '" . $GMTDatesEnd['end'] . "'";
191 $this->assertEquals($w[0], $expectedWhere);