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 Bug45287Test extends Sugar_PHPUnit_Framework_TestCase
50 public function setup()
52 SugarTestHelper::setUp('app_strings');
54 // Create Anon User setted on GMT+2 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', "Europe/Rome");
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->timedate);
124 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
125 SugarTestHelper::tearDown();
129 public function testRetrieveByExactDate()
131 global $current_user;
133 $_REQUEST = $_POST = array("module" => "Meetings",
135 "searchFormTab" => "basic_search",
138 "current_user_only_basic" => "0",
139 "favorites_only_basic" => "0",
140 "open_only_basic" => "0",
141 "date_start_basic_range_choice" => "=",
142 "range_date_start_basic" => "14/07/2011",
143 "start_range_date_start_basic" => "",
144 "end_range_date_start_basic" => "",
145 "button" => "Search",
148 $srch = new SearchForm(new Meeting(), "Meetings");
149 $srch->setup($this->searchDefs, $this->searchFields, "");
150 $srch->populateFromRequest();
151 $w = $srch->generateSearchWhere();
153 // Due to daylight savings, I cannot hardcode intervals...
154 $GMTDates = $this->timedate->getDayStartEndGMT("2011-07-14");
156 // Current User is on GMT+2.
157 // 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)
158 $expectedWhere = "meetings.date_start >= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDates['start']), 'datetime') .
159 " AND meetings.date_start <= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDates['end']), 'datetime');
160 $this->assertContains($expectedWhere, $w[0]);
164 public function testRetrieveByDaterange()
166 global $current_user;
168 $_REQUEST = $_POST = array("module" => "Meetings",
170 "searchFormTab" => "basic_search",
173 "current_user_only_basic" => "0",
174 "favorites_only_basic" => "0",
175 "open_only_basic" => "0",
176 "date_start_basic_range_choice" => "between",
177 "range_date_start_basic" => "",
178 "start_range_date_start_basic" => "13/07/2011",
179 "end_range_date_start_basic" => "14/07/2011",
180 "button" => "Search",
184 $srch = new SearchForm(new Meeting(), "Meetings");
185 $srch->setup($this->searchDefs, $this->searchFields, "");
186 $srch->populateFromRequest();
187 $w = $srch->generateSearchWhere();
189 // Due to daylight savings, I cannot hardcode intervals...
190 $GMTDatesStart = $this->timedate->getDayStartEndGMT("2011-07-13");
191 $GMTDatesEnd = $this->timedate->getDayStartEndGMT("2011-07-14");
193 // Current User is on GMT+2.
194 // 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)
195 $expectedWhere = "meetings.date_start >= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDatesStart['start']), 'datetime') .
196 " AND meetings.date_start <= " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($GMTDatesEnd['end']), 'datetime');
197 $this->assertContains($expectedWhere, $w[0]);