All Data Structures Functions Variables Pages
CalendarUtilTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo 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 ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo 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 Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified 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 Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
37  class CalendarUtilTest extends BaseTest
38  {
39  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  SecurityTestHelper::createSuperAdmin();
43  ProductTestHelper::createProductByNameForOwner('First Product', User::getByUsername('super'));
44  sleep(3);
45  ProductTestHelper::createProductByNameForOwner('Second Product', User::getByUsername('super'));
46  }
47 
48  public function setup()
49  {
50  parent::setup();
51  Yii::app()->user->userModel = User::getByUsername('super');
52  }
53 
54  public function testGetStartDate()
55  {
57  $this->assertEquals(date('Y-m-01'), $startDateTime);
58  $startDateTime = CalendarUtil::getStartDate(SavedCalendar::DATERANGE_TYPE_WEEK);
59  $days = date('w') - 1;
60  $this->assertEquals(date('Y-m-d', strtotime("-{$days} days")), $startDateTime);
61  $startDateTime = CalendarUtil::getStartDate(SavedCalendar::DATERANGE_TYPE_DAY);
62  $this->assertEquals(date('Y-m-d'), $startDateTime);
63  }
64 
65  public function testGetEndDate()
66  {
68  $this->assertEquals(date('Y-m-d', strtotime('first day of next month')), $endDateTime);
69  $endDateTime = CalendarUtil::getEndDate(SavedCalendar::DATERANGE_TYPE_WEEK);
70  $this->assertEquals(date('Y-m-d', strtotime('Monday next week')), $endDateTime);
71  $endDateTime = CalendarUtil::getEndDate(SavedCalendar::DATERANGE_TYPE_DAY);
72  $this->assertEquals(date('Y-m-d', strtotime('tomorrow')), $endDateTime);
73  }
74 
75  public function testGetUserSavedCalendars()
76  {
77  $savedCalendar = CalendarTestHelper::createSavedCalendarByName('Test Cal', '#315AB0');
78  $calendars = CalendarUtil::getUserSavedCalendars(Yii::app()->user->userModel);
79  $this->assertCount(1, $calendars);
80  }
81 
82  public function testGetFullCalendarFormattedDateTimeElement()
83  {
84  $startDateTime = CalendarUtil::getFullCalendarFormattedDateTimeElement('2014-01-10');
85  $this->assertEquals('2014-01-10', date('Y-m-d', strtotime($startDateTime)));
86  }
87 
88  public function testGetUserSubscribedCalendars()
89  {
90  $savedCalendar = CalendarTestHelper::createSavedCalendarByName('Test Cal New', '#c05d91');
91  $savedCalendarSubscription = CalendarTestHelper::createSavedCalendarSubscription('Test Cal New', '#66367b', Yii::app()->user->userModel);
92  $calendars = CalendarUtil::getUserSubscribedCalendars(Yii::app()->user->userModel);
93  $this->assertCount(1, $calendars);
94  }
95 
96  public function testGetUsedCalendarColorsByUser()
97  {
98  $colors = CalendarUtil::getAlreadyUsedColorsByUser(Yii::app()->user->userModel);
99  $this->assertContains('#66367b', $colors);
100  $this->assertContains('#315AB0', $colors);
101  }
102 
103  public function testMakeCalendarItemsList()
104  {
105  $savedCalendarSubscriptions = SavedCalendarSubscriptions::makeByUser(Yii::app()->user->userModel);
106  $content = CalendarUtil::makeCalendarItemsList($savedCalendarSubscriptions->getMySavedCalendarsAndSelected(),
107  'mycalendar[]', 'mycalendar', 'saved');
108  $this->assertContains('Test Cal', $content);
109  $content = CalendarUtil::makeCalendarItemsList($savedCalendarSubscriptions->getSubscribedToSavedCalendarsAndSelected(),
110  'sharedcalendar[]', 'sharedcalendar', 'shared');
111  $this->assertContains('Test Cal New', $content);
112  }
113 
122  {
123  $savedCalendars = SavedCalendar::getByName('Test Cal');
124  $subscribedCalendars = CalendarUtil::getUserSubscribedCalendars(Yii::app()->user->userModel);
125  $dp = CalendarUtil::processAndGetDataProviderForEventsData(strval($savedCalendars[0]->id),
126  strval($subscribedCalendars[0]->savedcalendar->id),
127  null,
128  null,
129  null,
130  false);
131  $calendarItems = $dp->getData();
132  $this->assertCount(2, $calendarItems);
133  $this->assertEquals('First Product', $calendarItems[0]->getTitle());
134  $this->assertEquals('Second Product', $calendarItems[1]->getTitle());
135 
136  //Check getFullCalendarItems
138  $this->assertCount(2, $items);
139  $this->assertEquals('First Product', $items[0]['title']);
140  $this->assertFalse(isset($items[0]['detailsUrl']));
141  $this->assertEquals('Second Product', $items[1]['title']);
142 
144  $this->assertTrue(isset($items[0]['detailsUrl']));
145  $this->assertEquals(Yii::app()->createUrl('/products/default/details', array('id' => $savedCalendars[0]->id)),
146  $items[0]['detailsUrl']);
147  }
148 
149  public function testGetUsersSubscribedForCalendar()
150  {
151  $user = UserTestHelper::createBasicUser('sam');
152  $savedCalendarSubscription = CalendarTestHelper::createSavedCalendarSubscription('Test Cal New', '#66367b', $user);
153  $savedCalendar = SavedCalendar::getByName('Test Cal New');
154  $subscribedUsers = CalendarUtil::getUsersSubscribedForCalendar($savedCalendar[0]);
155  $this->assertCount(2, $subscribedUsers);
156  }
157 
158  public function testSetMyCalendarColor()
159  {
160  $savedCalendar = CalendarTestHelper::createSavedCalendarByName('Color Cal', null);
161  CalendarUtil::setMyCalendarColor($savedCalendar, Yii::app()->user->userModel);
162  $this->assertNotEquals('#66367b', $savedCalendar->color);
163  $this->assertNotEquals('#315AB0', $savedCalendar->color);
164  }
165 
166  public function testSetMySharedCalendarColor()
167  {
168  $user = User::getByUsername('sam');
169  $savedCalendarSubscription = CalendarTestHelper::createSavedCalendarSubscription('Color Cal', null, $user);
170  CalendarUtil::setSharedCalendarColor($savedCalendarSubscription);
171  $this->assertNotEquals('#66367b', $savedCalendarSubscription->color);
172  }
173 
178  {
179  $selectedAttributes = CalendarUtil::getModelAttributesForSelectedModule('ProductsModule');
180  $this->assertContains('Created Date Time', $selectedAttributes);
181  $this->assertContains('Modified Date Time', $selectedAttributes);
182  }
183 
188  {
189  $availableModuleClassNames = CalendarUtil::getAvailableModulesForCalendar();
190  $this->assertGreaterThan(2, count($availableModuleClassNames));
191  $this->assertTrue(in_array('Meetings', $availableModuleClassNames));
192  $this->assertTrue(in_array('Tasks', $availableModuleClassNames));
193  }
194 
195  public function testLoadDefaultCalendars()
196  {
197  $user = UserTestHelper::createBasicUser('jim');
198  Yii::app()->user->userModel = $user;
199  $this->assertEquals(0, count(CalendarUtil::getUserSavedCalendars($user)));
201  $this->assertEquals(2, count(CalendarUtil::getUserSavedCalendars($user)));
202  $calendars = CalendarUtil::getUserSavedCalendars($user);
203  $model = $calendars[0];
204  $data = unserialize($model->serializedData);
205  $filtersData = $data[ComponentForReportForm::TYPE_FILTERS];
206  $this->assertEquals(strval($user), $filtersData[0]['stringifiedModelForValue']);
207  $this->assertEquals($user->id, $filtersData[0]['value']);
208  $this->assertEquals('1', $data['filtersStructure']);
209  }
210  }
211 ?>
static getModelAttributesForSelectedModule($moduleClassName)
static getUserSubscribedCalendars(User $user)
static makeCalendarItemsList($data, $field, $itemClass, $type)
static getByUsername($username)
Definition: User.php:49
static setMyCalendarColor(SavedCalendar $savedCalendar, User $user)
static getUserSavedCalendars(User $user)
static getAvailableModulesForCalendar()
static getStartDate($dateRangeType)
static processAndGetDataProviderForEventsData($selectedMyCalendarIds=null, $selectedSharedCalendarIds=null, $startDate=null, $endDate=null, $dateRangeType=null, $isSticky=true)
testProcessUserCalendarsAndMakeDataProviderForCombinedView()
static getEndDate($dateRangeType)
static populateDetailsUrlForCalendarItems($items)
static getFullCalendarFormattedDateTimeElement($dateTime)
static makeByUser(User $user, $selectedCalendarIds=null, $subscribedCalendarIds=null)
static getByName($name)
const DATERANGE_TYPE_MONTH
static getFullCalendarItems(CalendarItemsDataProvider $dataProvider)
static setSharedCalendarColor(SavedCalendarSubscription $sharedCalendar)
static getUsersSubscribedForCalendar(SavedCalendar $subscribedCalendar)
static getAlreadyUsedColorsByUser(User $user)
Generated on Fri Feb 21 2020 07:10:31