Exemplo n.º 1
0
 public function testGetEndDate()
 {
     $endDateTime = CalendarUtil::getEndDate(SavedCalendar::DATERANGE_TYPE_MONTH);
     $this->assertEquals(date('Y-m-d', strtotime('first day of next month')), $endDateTime);
     $endDateTime = CalendarUtil::getEndDate(SavedCalendar::DATERANGE_TYPE_WEEK);
     $this->assertEquals(date('Y-m-d', strtotime('Monday next week')), $endDateTime);
     $endDateTime = CalendarUtil::getEndDate(SavedCalendar::DATERANGE_TYPE_DAY);
     $this->assertEquals(date('Y-m-d', strtotime('tomorrow')), $endDateTime);
 }
Exemplo n.º 2
0
 /**
  * Process user calendars and get data provider.
  * @param null|string $myCalendarIds
  * @param null|string $mySubscribedCalendarIds
  * @param null|string $dateRangeType
  * @param null|string $startDate
  * @param null|string $endDate
  * @return CalendarItemsDataProvider
  */
 public static function processUserCalendarsAndMakeDataProviderForCombinedView($myCalendarIds = null, $mySubscribedCalendarIds = null, $dateRangeType = null, $startDate = null, $endDate = null)
 {
     $savedCalendarSubscriptions = SavedCalendarSubscriptions::makeByUser(Yii::app()->user->userModel, $myCalendarIds, $mySubscribedCalendarIds);
     if ($dateRangeType == null) {
         $dateRangeType = CalendarUtil::getDateRangeType();
         ZurmoConfigurationUtil::setByUserAndModuleName(Yii::app()->user->userModel, 'CalendarsModule', 'myCalendarDateRangeType', $dateRangeType);
     }
     if ($startDate == null) {
         $startDate = CalendarUtil::getStartDate($dateRangeType);
         ZurmoConfigurationUtil::setByUserAndModuleName(Yii::app()->user->userModel, 'CalendarsModule', 'myCalendarStartDate', $startDate);
     }
     if ($endDate == null) {
         $endDate = CalendarUtil::getEndDate($dateRangeType);
         ZurmoConfigurationUtil::setByUserAndModuleName(Yii::app()->user->userModel, 'CalendarsModule', 'myCalendarEndDate', $endDate);
     }
     return CalendarItemsDataProviderFactory::getDataProviderByDateRangeType($savedCalendarSubscriptions, $startDate, $endDate, $dateRangeType);
 }
 public function testSuperUserAllDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->runControllerWithRedirectExceptionAndGetContent('calendars/default/details');
     $this->runControllerWithNoExceptionsAndGetContent('calendars/default/combinedDetails');
     //Default Controller actions requiring some sort of parameter via POST or GET
     //Load Model Edit Views
     $calendars = SavedCalendar::getAll();
     $this->assertEquals(2, count($calendars));
     $superCalId = self::getModelIdByModelNameAndName('SavedCalendar', 'My Cal 1');
     $superCalId2 = self::getModelIdByModelNameAndName('SavedCalendar', 'My Cal 2');
     $this->setGetArray(array('id' => $superCalId));
     $this->runControllerWithNoExceptionsAndGetContent('calendars/default/edit');
     //Save Calendar
     SavedCalendar::getById($superCalId);
     $this->setPostArray(array('SavedCalendar' => array('name' => 'My New Cal 1')));
     //Test having a failed validation on the saved calendar during save.
     $this->setGetArray(array('id' => $superCalId));
     $this->setPostArray(array('SavedCalendar' => array('name' => ''), 'ajax' => 'edit-form', 'RowsAndColumnsReportWizardForm' => array('filtersStructure' => '', 'Filters' => array(array('attributeIndexOrDerivedType' => 'createdDateTime', 'structurePosition' => '1', 'valueType' => 'After', 'value' => '2/18/2014', 'availableAtRunTime' => '0')))));
     $content = $this->runControllerWithExitExceptionAndGetContent('calendars/default/edit');
     $this->assertContains('Name cannot be blank', $content);
     //Filter validation
     $this->setGetArray(array('id' => $superCalId));
     $this->setPostArray(array('SavedCalendar' => array('name' => 'Test'), 'ajax' => 'edit-form', 'RowsAndColumnsReportWizardForm' => array('filtersStructure' => '1', 'Filters' => array(array('attributeIndexOrDerivedType' => 'createdDateTime', 'structurePosition' => '1', 'valueType' => 'After', 'value' => '', 'availableAtRunTime' => '0')))));
     $content = $this->runControllerWithExitExceptionAndGetContent('calendars/default/edit');
     $this->assertContains('Value cannot be blank', $content);
     //Valid case
     $this->setGetArray(array('id' => $superCalId));
     $this->setPostArray(array('SavedCalendar' => array('name' => 'My New Cal 1'), 'ajax' => 'edit-form', 'RowsAndColumnsReportWizardForm' => array('filtersStructure' => '1', 'Filters' => array(array('attributeIndexOrDerivedType' => 'createdDateTime', 'structurePosition' => '1', 'valueType' => 'After', 'value' => '2/18/2014', 'availableAtRunTime' => '0')))));
     $this->runControllerWithExitExceptionAndGetContent('calendars/default/edit');
     //Load Model Detail Views
     $this->resetPostArray();
     $this->runControllerWithRedirectExceptionAndGetContent('calendars/default/details');
     $this->resetGetArray();
     $this->runControllerWithNoExceptionsAndGetContent('calendars/default/modalList');
     //Month view
     $this->setGetArray(array('selectedMyCalendarIds' => $superCalId . ',' . $superCalId2, 'selectedSharedCalendarIds' => null, 'startDate' => CalendarUtil::getStartDate(SavedCalendar::DATERANGE_TYPE_MONTH), 'endDate' => CalendarUtil::getEndDate(SavedCalendar::DATERANGE_TYPE_MONTH), 'dateRangeType' => SavedCalendar::DATERANGE_TYPE_MONTH));
     $content = $this->runControllerWithNoExceptionsAndGetContent('calendars/default/getEvents');
     $this->assertContains('My First Prod', $content);
     //Week view
     $this->setGetArray(array('selectedMyCalendarIds' => $superCalId . ',' . $superCalId2, 'selectedSharedCalendarIds' => null, 'startDate' => CalendarUtil::getStartDate(SavedCalendar::DATERANGE_TYPE_WEEK), 'endDate' => CalendarUtil::getEndDate(SavedCalendar::DATERANGE_TYPE_WEEK), 'dateRangeType' => SavedCalendar::DATERANGE_TYPE_WEEK));
     $content = $this->runControllerWithNoExceptionsAndGetContent('calendars/default/getEvents');
     $this->assertContains('My First Prod', $content);
     //Day view
     $this->setGetArray(array('selectedMyCalendarIds' => $superCalId . ',' . $superCalId2, 'selectedSharedCalendarIds' => null, 'startDate' => CalendarUtil::getStartDate(SavedCalendar::DATERANGE_TYPE_DAY), 'endDate' => CalendarUtil::getEndDate(SavedCalendar::DATERANGE_TYPE_DAY), 'dateRangeType' => SavedCalendar::DATERANGE_TYPE_DAY));
     $this->runControllerWithNoExceptionsAndGetContent('calendars/default/getEvents');
     $this->runControllerWithNoExceptionsAndGetContent('calendars/default/getDayEvents');
     $this->setGetArray(array('modelClass' => 'Product', 'modelId' => $superCalId));
     $this->runControllerWithNoExceptionsAndGetContent('calendars/default/getCalendarItemDetail');
     //Add subscribed calendar
     $user = UserTestHelper::createBasicUser('jim');
     $subscribedCalendar = CalendarTestHelper::createSavedCalendarByName("My Subscribed Cal", '#315AB0');
     $subscribedCalendar->owner = $user;
     $subscribedCalendar->save();
     $this->setGetArray(array('id' => $subscribedCalendar->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('calendars/default/addSubsriptionForCalendar');
     $this->assertContains('My Subscribed Cal', $content);
     $subscribedCalendars = CalendarUtil::getUserSubscribedCalendars($super);
     $this->setGetArray(array('id' => $subscribedCalendars[0]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('calendars/default/unsubscribe');
     $this->assertNotContains('My Subscribed Cal', $content);
 }