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 ********************************************************************************/
40 require_once "modules/Calendar/Calendar.php";
41 require_once "modules/Calendar/CalendarUtils.php";
42 require_once('modules/Meetings/Meeting.php');
44 class CalendarTest extends Sugar_PHPUnit_Framework_TestCase {
51 protected $meeting_id = null;
53 public static function setUpBeforeClass(){
54 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
57 public static function tearDownAfterClass(){
58 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
59 unset($GLOBALS['current_user']);
62 public function setUp(){
63 $this->time_date = new TimeDate();
64 $_REQUEST['module'] = 'Calendar';
65 $_REQUEST['year'] = '2012';
66 $_REQUEST['month'] = '01';
67 $_REQUEST['day'] = '02';
70 public function tearDown(){
71 unset($_REQUEST['module']);
72 unset($_REQUEST['year']);
73 unset($_REQUEST['month']);
74 unset($_REQUEST['day']);
76 if(isset($this->meeting_id)){
77 $GLOBALS['db']->query("DELETE FROM meetings WHERE id = '{$this->meeting_id}'");
78 $GLOBALS['db']->query("DELETE FROM meetings_users WHERE meeting_id = '{$this->meeting_id}'");
79 unset($this->meeting_id);
83 public function testCalendarDate(){
84 $cal = new Calendar('week');
85 $this->assertEquals('2012',$cal->date_time->year);
88 public function testCalendarAddActivity(){
89 $cal = new Calendar('week');
90 $cal->add_activities($GLOBALS['current_user']);
91 $count1 = count($cal->acts_arr[$GLOBALS['current_user']->id]);
92 $cal->acts_arr = array();
94 $this->meeting_id = uniqid();
97 $db->query("INSERT INTO meetings (id,date_start,assigned_user_id) VALUES(".
98 $db->quoted($this->meeting_id) . ", " .
99 $db->convert($db->quoted("2012-01-02 00:00:00"), 'datetime') . ", " .
100 $db->quoted($GLOBALS['current_user']->id) .")");
102 $db->query("INSERT INTO meetings_users (id,meeting_id,user_id) VALUES (".
103 $db->quoted(uniqid()).", ".
104 $db->quoted($this->meeting_id).", ".
105 $db->quoted($GLOBALS['current_user']->id).")");
107 $cal->add_activities($GLOBALS['current_user']);
108 $count2 = count($cal->acts_arr[$GLOBALS['current_user']->id]);
110 $this->assertEquals($count1 + 1, $count2, "Count of records should be one more after meeting added");
113 public function testCalendarLoadActivities(){
114 $cal = new Calendar('month');
115 $cal->add_activities($GLOBALS['current_user']);
116 $format = $GLOBALS['current_user']->getUserDateTimePreferences();
117 $meeting = new Meeting();
118 $meeting->meeting_id = uniqid();
119 $meeting->date_start = $this->time_date->swap_formats("2012-01-01 11:00pm" , 'Y-m-d h:ia', $format['date'].' '.$format['time']);
120 $meeting->name = "test";
121 $cal->acts_arr = array();
122 $cal->acts_arr[$GLOBALS['current_user']->id] = array();
123 $cal->acts_arr[$GLOBALS['current_user']->id][] = new CalendarActivity($meeting);
124 $cal->load_activities();
126 $this->assertEquals($cal->items[0]['time_start'],$this->time_date->swap_formats("2012-01-01 11:00pm" , 'Y-m-d h:ia', $format['time']),"Time should remain the same after load_activities");
129 public function testHandleOffset(){
130 $gmt_today = $this->time_date->nowDb();
131 $date1 = $this->time_date->handle_offset($gmt_today, $GLOBALS['timedate']->get_db_date_time_format());
132 $date2 = $this->time_date->nowDb();
133 $this->assertEquals($date1, $date2, "HandleOffset should be equaivalent to nowDb");
136 public function testUserDateFormat(){
137 $gmt_default_date_start = $this->time_date->get_gmt_db_datetime();
138 $date1 = $this->time_date->handle_offset($gmt_default_date_start, $GLOBALS['timedate']->get_date_time_format());
139 $date2 = $this->time_date->asUser($this->time_date->getNow());
140 $this->assertEquals($date1, $date2, "HandleOffset should be equaivalent to nowDb");