Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SavedCalendarTest.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 
38  {
39  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  SecurityTestHelper::createSuperAdmin();
43  SecurityTestHelper::createUsers();
44  }
45 
46  public function setUp()
47  {
48  parent::setUp();
49  Yii::app()->user->userModel = User::getByUsername('super');
50  }
51 
52  public function testCreateAndGetSavedCalendarById()
53  {
54  $calendar = CalendarTestHelper::createSavedCalendarByName('My first calendar', '#ccccc');
55 
56  $id = $calendar->id;
57  $calendar->forget();
58  unset($calendar);
59  $calendar = SavedCalendar::getById($id);
60  $this->assertEquals('My first calendar', $calendar->name);
61  $this->assertEquals('America/Chicago', $calendar->timeZone);
62  $this->assertEquals('Newyork', $calendar->location);
63  $this->assertEquals('ProductsModule', $calendar->moduleClassName);
64  $this->assertEquals('createdDateTime', $calendar->startAttributeName);
65  $this->assertEquals('#ccccc', $calendar->color);
66  }
67 
71  public function testGetSavedCalendarsByName()
72  {
73  Yii::app()->user->userModel = User::getByUsername('super');
74  $savedCalendars = SavedCalendar::getByName('My first calendar');
75  $this->assertEquals(1, count($savedCalendars));
76  $this->assertEquals('My first calendar', $savedCalendars[0]->name);
77  }
78 
82  public function testGetLabel()
83  {
84  Yii::app()->user->userModel = User::getByUsername('super');
85  $savedCalendars = SavedCalendar::getByName('My first calendar');
86  $this->assertEquals(1, count($savedCalendars));
87  $this->assertEquals('Calendar', $savedCalendars[0]::getModelLabelByTypeAndLanguage('Singular'));
88  $this->assertEquals('Calendars', $savedCalendars[0]::getModelLabelByTypeAndLanguage('Plural'));
89  }
90 
95  {
96  Yii::app()->user->userModel = User::getByUsername('super');
97  $savedCalendars = SavedCalendar::getByName('Red Widget 1');
98  $this->assertEquals(0, count($savedCalendars));
99  }
100 
104  public function testGetAll()
105  {
106  Yii::app()->user->userModel = User::getByUsername('super');
107  $savedCalendars = SavedCalendar::getAll();
108  $this->assertEquals(1, count($savedCalendars));
109  }
110 
115  {
116  Yii::app()->user->userModel = User::getByUsername('super');
117  $savedCalendars = SavedCalendar::getAll();
118  $savedCalendar = $savedCalendars[0];
119  $savedCalendar->serializedData = 'a:2:{s:7:"Filters";a:1:{i:0;a:5:{s:17:"structurePosition";s:1:"1";s:27:"attributeIndexOrDerivedType";s:15:"createdDateTime";s:9:"valueType";s:5:"After";s:5:"value";s:10:"2014-01-18";s:18:"availableAtRunTime";s:1:"0";}}s:16:"filtersStructure";s:1:"1";}';
120  $report = SavedCalendarToReportAdapter::makeReportBySavedCalendar($savedCalendars[0]);
121  $this->assertEquals($report->getDescription(), $savedCalendars[0]->description);
122  $this->assertEquals($report->getName(), $savedCalendars[0]->name);
123  $this->assertEquals($report->getModuleClassName(), $savedCalendars[0]->moduleClassName);
124  $this->assertEquals($report->getOwner(), $savedCalendars[0]->owner);
125  $this->assertEquals($report->getType(), Report::TYPE_ROWS_AND_COLUMNS);
126  $this->assertEquals($report->getFiltersStructure(), "1");
127  }
128 
129  public function testDeleteSavedCalendar()
130  {
131  Yii::app()->user->userModel = User::getByUsername('super');
132 
133  $savedCalendars = SavedCalendar::getAll();
134  $this->assertEquals(1, count($savedCalendars));
135  $savedCalendars[0]->delete();
136 
137  $savedCalendars = SavedCalendar::getAll();
138  $this->assertEquals(0, count($savedCalendars));
139  }
140 
141  public function testGetAllWhenThereAreNone()
142  {
143  Yii::app()->user->userModel = User::getByUsername('super');
144  $savedCalendars = SavedCalendar::getAll();
145  $this->assertEquals(0, count($savedCalendars));
146  }
147 
156  {
157  Yii::app()->user->userModel = User::getByUsername('super');
158  $product = ProductTestHelper::createProductByNameForOwner('Test Product', Yii::app()->user->userModel);
159  $savedCalendar = CalendarTestHelper::createSavedCalendarByName('Test Cal', '#315AB0');
160  $currentDateTime = new DateTime('NOW');
161  $currentDateTime->add(new DateInterval('P1D'));
162  $savedCalendarSubscriptions = SavedCalendarSubscriptions::makeByUser(Yii::app()->user->userModel, (string)$savedCalendar->id);
164  '2014-01-01',
165  $currentDateTime->format('Y-m-d'),
167  $this->assertInstanceOf('CalendarItemsDataProvider', $dp);
168  $this->assertEquals('2014-01-01', $dp->getStartDate());
169  $this->assertEquals($currentDateTime->format('Y-m-d'), $dp->getEndDate());
170  $this->assertEquals(SavedCalendar::DATERANGE_TYPE_MONTH, $dp->getDateRangeType());
171  $savedCalendarsData = $dp->getSavedCalendarSubscriptions()->getMySavedCalendarsAndSelected();
172  $keys = array_keys($savedCalendarsData);
173  $this->assertEquals($savedCalendar->id, $keys[0]);
175  $this->assertCount(1, $items);
176  $this->assertEquals($product->id, $items[0]['modelId']);
177  }
178  }
179 ?>
testGetSavedCalendarsByNameForNonExistentName()
static getByUsername($username)
Definition: User.php:49
static getDataProviderByDateRangeType($savedCalendarSubscriptions, $startDate, $endDate, $dateRangeType)
static makeReportBySavedCalendar(SavedCalendar $savedCalendar)
static makeByUser(User $user, $selectedCalendarIds=null, $subscribedCalendarIds=null)
static getByName($name)
const DATERANGE_TYPE_MONTH
const TYPE_ROWS_AND_COLUMNS
Definition: Report.php:51
static getById($id, $modelClassName=null)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static getFullCalendarItems(CalendarItemsDataProvider $dataProvider)
Generated on Tue Aug 4 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.