]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Meetings/Bug45287Test.php
Release 6.2.3
[Github/sugarcrm.git] / tests / modules / Meetings / Bug45287Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37
38 require_once 'modules/Accounts/Account.php';
39 require_once 'modules/Meetings/Meeting.php';
40 require_once 'include/SearchForm/SearchForm2.php';
41
42
43 class Bug45287Test extends Sugar_PHPUnit_Framework_TestCase
44 {
45     var $meetingsArr;
46     var $searchDefs;
47     var $searchFields;
48     
49     public function setup()
50     {
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");
57
58         // new object to avoid TZ caching
59         $timedate = new TimeDate();
60
61         $this->meetingsArr = array();
62
63         // Create a Bunch of Meetings
64         $d = 12;
65         $cnt = 0;
66         while ($d < 15)
67         {
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();
72           $d++;
73           $cnt++;
74         }
75
76         $this->searchDefs = array("Meetings" => array("layout" => array("basic_search" => array("name" => array("name" => "name",
77                                                                                                                 "default" => true,
78                                                                                                                 "width" => "10%",
79                                                                                                                ),
80                                                                                                 "date_start" => array("name" => "date_start",
81                                                                                                                       "default" => true,
82                                                                                                                       "width" => "10%",
83                                                                                                                       "type" => "datetimecombo",
84                                                                                                                      ), 
85                                                                                                ),
86                                                                        ),
87                                                      ),
88                                  );
89
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),
104                                                        ),
105                                    );
106     }
107     
108     public function tearDown()
109     {
110
111         foreach ($this->meetingsArr as $m)
112         {
113             $GLOBALS['db']->query('DELETE FROM meetings WHERE id = \'' . $m->id . '\' ');
114         }
115
116         unset($m);
117         unset($this->meetingsArr);
118         unset($this->searchDefs);
119         unset($this->searchFields);
120
121         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
122     }
123         
124     
125     public function testRetrieveByExactDate()
126     {
127         global $current_user, $timedate;
128
129         $_REQUEST = $_POST = array("module" => "Meetings",
130                                    "action" => "index",
131                                    "searchFormTab" => "basic_search",
132                                    "query" => "true",
133                                    "name_basic" => "",
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",
142                                   );
143
144         $srch = new SearchForm(new Meeting(), "Meetings");
145         $srch->setup($this->searchDefs, $this->searchFields, "");
146         $srch->populateFromRequest();
147         $w = $srch->generateSearchWhere();
148
149         // Due to daylight savings, I cannot hardcode intervals...
150         $GMTDates = $timedate->getDayStartEndGMT("2011-07-14");
151
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);
156     }
157         
158
159     public function testRetrieveByDaterange()
160     {
161         global $current_user, $timedate;
162
163         $_REQUEST = $_POST = array("module" => "Meetings",
164                                    "action" => "index",
165                                    "searchFormTab" => "basic_search",
166                                    "query" => "true",
167                                    "name_basic" => "",
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",
176                                   );
177
178
179         $srch = new SearchForm(new Meeting(), "Meetings");
180         $srch->setup($this->searchDefs, $this->searchFields, "");
181         $srch->populateFromRequest();
182         $w = $srch->generateSearchWhere();
183
184         // Due to daylight savings, I cannot hardcode intervals...
185         $GMTDatesStart = $timedate->getDayStartEndGMT("2011-07-13");
186         $GMTDatesEnd = $timedate->getDayStartEndGMT("2011-07-14");
187
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);
192    }
193         
194
195 }