public function testSavesCustomReport()
 {
     $reportName = 'reportName';
     $ownerId = 12;
     $startRange = '2010-01-01';
     $endRange = '2010-01-02';
     $timezone = 'America/Chicago';
     $startDate = Date::Parse($startRange, $timezone);
     $endDate = Date::Parse($endRange, $timezone);
     $resourceId = 1;
     $scheduleId = 2;
     $userId = 3;
     $groupId = 4;
     $accessoryId = 5;
     $participantId = 6;
     $usage = new Report_Usage(Report_Usage::ACCESSORIES);
     $selection = new Report_ResultSelection(Report_ResultSelection::COUNT);
     $groupBy = new Report_GroupBy(Report_GroupBy::RESOURCE);
     $range = new Report_Range(Report_Range::DATE_RANGE, $startRange, $endRange, $timezone);
     $filter = new Report_Filter($resourceId, $scheduleId, $userId, $groupId, $accessoryId, $participantId);
     $report = new SavedReport($reportName, $ownerId, $usage, $selection, $groupBy, $range, $filter);
     $this->repository->SaveCustomReport($report);
     $serializedCriteria = "usage=ACCESSORIES;selection=COUNT;groupby=RESOURCE;range=DATE_RANGE;range_start={$startDate->ToDatabase()};range_end={$endDate->ToDatabase()};resourceid={$resourceId};scheduleid={$scheduleId};userid={$userId};groupid={$groupId};accessoryid={$accessoryId};participantid={$participantId}";
     $expectedCommand = new AddSavedReportCommand($reportName, $ownerId, $report->DateCreated(), $serializedCriteria);
     $this->assertEquals($expectedCommand, $this->db->_LastCommand);
 }
Example #2
0
 /**
  * @param string $dateString
  * @param UserSession $session
  * @return Date
  */
 public static function GetDate($dateString, UserSession $session)
 {
     if (BookedStringHelper::Contains($dateString, 'T')) {
         return Date::ParseExact($dateString);
     }
     return Date::Parse($dateString, $session->Timezone);
 }
 public function testBuildsCustomResourceReport()
 {
     $start = '2010-01-01';
     $end = '2010-01-02';
     $resourceId = 1;
     $scheduleId = 2;
     $userId = 3;
     $groupId = 4;
     $accessoryId = 5;
     $participantId = 6;
     $usage = new Report_Usage(Report_Usage::RESOURCES);
     $selection = new Report_ResultSelection(Report_ResultSelection::FULL_LIST);
     $groupBy = new Report_GroupBy(Report_GroupBy::GROUP);
     $range = new Report_Range(Report_Range::DATE_RANGE, $start, $end, 'UTC');
     $filter = new Report_Filter($resourceId, $scheduleId, $userId, $groupId, $accessoryId, $participantId);
     $commandBuilder = new ReportCommandBuilder();
     $commandBuilder->SelectFullList()->OfResources()->Within(Date::Parse($start, 'UTC'), Date::Parse($end, 'UTC'))->WithResourceId($resourceId)->WithUserId($userId)->WithParticipantId($participantId)->WithScheduleId($scheduleId)->WithGroupId($groupId)->WithAccessoryId($accessoryId)->GroupByGroup();
     $rows = array(array(ColumnNames::OWNER_FIRST_NAME => 'value', ColumnNames::OWNER_LAST_NAME => 'value', ColumnNames::OWNER_USER_ID => 'value'));
     $this->reportingRepository->expects($this->once())->method('GetCustomReport')->with($this->equalTo($commandBuilder))->will($this->returnValue($rows));
     $report = $this->rs->GenerateCustomReport($usage, $selection, $groupBy, $range, $filter);
     $cols = new ReportColumns();
     $cols->Add(ColumnNames::OWNER_FIRST_NAME);
     $cols->Add(ColumnNames::OWNER_LAST_NAME);
     $cols->Add(ColumnNames::OWNER_USER_ID);
     $this->assertEquals($cols, $report->GetColumns());
     $this->assertEquals(new CustomReportData($rows), $report->GetData());
 }
 public function testEnsuresThatStartMustBeBeforeEnd()
 {
     $start = Date::Parse('2010-01-01');
     $reservationDate = new DateRange($start, $start->AddDays(-1));
     $reservationSeries = new TestReservationSeries();
     $reservationSeries->WithDuration($reservationDate);
     $rule = new ReservationDateTimeRule();
     $result = $rule->Validate($reservationSeries);
     $this->assertFalse($result->IsValid());
 }
Example #5
0
 public function testCanGetSpecificInstanceByDate()
 {
     $startDate = Date::Parse('2010-02-02 12:15', 'UTC');
     $endDate = $startDate->AddDays(1);
     $dateRange = new DateRange($startDate, $endDate);
     $repeatOptions = $this->getMock('IRepeatOptions');
     $series = ReservationSeries::Create(1, new FakeBookableResource(1), null, null, $dateRange, $repeatOptions, new FakeUserSession());
     $instance = $series->CurrentInstance();
     $this->assertEquals($startDate, $instance->StartDate());
     $this->assertEquals($endDate, $instance->EndDate());
 }
Example #6
0
 public function testWhenFirstDayOfTheWeekIsNotSunday()
 {
     $timezone = 'America/Chicago';
     $next = Date::Parse('2014-07-14', $timezone);
     $prev = Date::Parse('2014-06-30', $timezone);
     $expectedFirstDay = Date::Parse('2014-07-07', $timezone);
     $expectedLastDay = Date::Parse('2014-07-13', $timezone);
     $week = CalendarWeek::FromDate(2014, 7, 12, $timezone, 1);
     $this->assertEquals($expectedFirstDay, $week->FirstDay(), $week->FirstDay()->__toString());
     $this->assertEquals($expectedLastDay, $week->LastDay(), $week->LastDay()->__toString());
     $this->assertEquals($next, $week->GetNextDate(), $week->GetNextDate()->__toString());
     $this->assertEquals($prev, $week->GetPreviousDate(), $week->GetPreviousDate()->__toString());
 }
 public function testBindsDefaultScheduleByMonthWhenNothingSelected()
 {
     $showInaccessible = true;
     $this->fakeConfig->SetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, 'true');
     $userId = $this->fakeUser->UserId;
     $defaultScheduleId = 10;
     $userTimezone = "America/New_York";
     $calendarType = CalendarTypes::Month;
     $requestedDay = 4;
     $requestedMonth = 3;
     $requestedYear = 2011;
     $month = new CalendarMonth($requestedMonth, $requestedYear, $userTimezone);
     $startDate = Date::Parse('2011-01-01', 'UTC');
     $endDate = Date::Parse('2011-01-02', 'UTC');
     $summary = 'foo summary';
     $resourceId = 3;
     $fname = 'fname';
     $lname = 'lname';
     $referenceNumber = 'refnum';
     $resourceName = 'resource name';
     //$res = new ScheduleReservation(1, $startDate, $endDate, null, $summary, $resourceId, $userId, $fname, $lname, $referenceNumber, ReservationStatus::Created);
     $res = new ReservationItemView($referenceNumber, $startDate, $endDate, 'resource name', $resourceId, 1, null, null, $summary, null, $fname, $lname, $userId);
     $r1 = new FakeBookableResource(1, 'dude1');
     $r2 = new FakeBookableResource($resourceId, $resourceName);
     $reservations = array($res);
     $resources = array($r1, $r2);
     /** @var Schedule[] $schedules */
     $schedules = array(new Schedule(1, null, false, 2, null), new Schedule($defaultScheduleId, null, true, 3, null));
     $this->scheduleRepository->expects($this->atLeastOnce())->method('GetAll')->will($this->returnValue($schedules));
     $this->resourceService->expects($this->atLeastOnce())->method('GetAllResources')->with($this->equalTo($showInaccessible), $this->equalTo($this->fakeUser))->will($this->returnValue($resources));
     $this->resourceService->expects($this->atLeastOnce())->method('GetResourceGroups')->with($this->equalTo(null), $this->equalTo($this->fakeUser))->will($this->returnValue(new ResourceGroupTree()));
     $this->page->expects($this->atLeastOnce())->method('GetScheduleId')->will($this->returnValue(null));
     $this->page->expects($this->atLeastOnce())->method('GetResourceId')->will($this->returnValue(null));
     $this->repository->expects($this->atLeastOnce())->method('GetReservationList')->with($this->equalTo($month->FirstDay()), $this->equalTo($month->LastDay()->AddDays(1)), $this->equalTo(null), $this->equalTo(null), $this->equalTo(null), $this->equalTo(null))->will($this->returnValue($reservations));
     $this->page->expects($this->atLeastOnce())->method('GetCalendarType')->will($this->returnValue($calendarType));
     $this->page->expects($this->atLeastOnce())->method('GetDay')->will($this->returnValue($requestedDay));
     $this->page->expects($this->atLeastOnce())->method('GetMonth')->will($this->returnValue($requestedMonth));
     $this->page->expects($this->atLeastOnce())->method('GetYear')->will($this->returnValue($requestedYear));
     $this->page->expects($this->atLeastOnce())->method('SetFirstDay')->with($this->equalTo($schedules[1]->GetWeekdayStart()));
     $this->calendarFactory->expects($this->atLeastOnce())->method('Create')->with($this->equalTo($calendarType), $this->equalTo($requestedYear), $this->equalTo($requestedMonth), $this->equalTo($requestedDay), $this->equalTo($userTimezone))->will($this->returnValue($month));
     $this->page->expects($this->atLeastOnce())->method('BindCalendar')->with($this->equalTo($month));
     $details = new CalendarSubscriptionDetails(true);
     $this->subscriptionService->expects($this->once())->method('ForSchedule')->with($this->equalTo($defaultScheduleId))->will($this->returnValue($details));
     $this->page->expects($this->atLeastOnce())->method('BindSubscription')->with($this->equalTo($details));
     $calendarFilters = new CalendarFilters($schedules, $resources, null, null, new ResourceGroupTree());
     $this->page->expects($this->atLeastOnce())->method('BindFilters')->with($this->equalTo($calendarFilters));
     $this->presenter->PageLoad($this->fakeUser, $userTimezone);
     $actualReservations = $month->Reservations();
     $expectedReservations = CalendarReservation::FromScheduleReservationList($reservations, $resources, $this->fakeUser);
     $this->assertEquals($expectedReservations, $actualReservations);
 }
 public function testRuleIsValidIfBeginsAndEndsOnSameDayInScheduleTimezone()
 {
     $start = Date::Parse('2013-01-01 12:00', 'UTC');
     $end = $start->AddHours(2);
     $reservation = new TestReservationSeries();
     $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end)));
     $resource = new FakeBookableResource(1);
     $resource->SetAllowMultiday(false);
     $reservation->WithResource($resource);
     $this->scheduleRepository->expects($this->once())->method('LoadById')->with($this->equalTo($reservation->ScheduleId()))->will($this->returnValue($this->schedule));
     $rule = new ResourceCrossDayRule($this->scheduleRepository);
     $result = $rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }
 public function ChangeAnnouncement()
 {
     $user = ServiceLocator::GetServer()->GetUserSession();
     $id = $this->page->GetAnnouncementId();
     $text = $this->page->GetText();
     $start = Date::Parse($this->page->GetStart(), $user->Timezone);
     $end = Date::Parse($this->page->GetEnd(), $user->Timezone);
     $priority = $this->page->GetPriority();
     Log::Debug('Changing Announcement with id %s', $id);
     $announcement = $this->announcementRepository->LoadById($id);
     $announcement->SetText($text);
     $announcement->SetDates($start, $end);
     $announcement->SetPriority($priority);
     $this->announcementRepository->Update($announcement);
 }
Example #10
0
 /**
  * @param $range string|Report_Range
  * @param $startString
  * @param $endString
  * @param string $timezone
  */
 public function __construct($range, $startString, $endString, $timezone = 'UTC')
 {
     $this->range = $range;
     $this->start = empty($startString) ? Date::Min() : Date::Parse($startString, $timezone);
     $this->end = empty($endString) ? Date::Max() : Date::Parse($endString, $timezone);
     $now = Date::Now()->ToTimezone($timezone);
     if ($this->range == self::CURRENT_MONTH) {
         $this->start = Date::Create($now->Year(), $now->Month(), 1, 0, 0, 0, $timezone);
         $this->end = $this->start->AddMonths(1);
     }
     if ($this->range == self::CURRENT_WEEK) {
         $this->start = $now->GetDate()->AddDays(-$now->Weekday());
         $this->end = $this->Start()->AddDays(8);
     }
     if ($this->range == self::TODAY) {
         $this->start = Date::Create($now->Year(), $now->Month(), $now->Day(), 0, 0, 0, $timezone);
         $this->end = $this->start->AddDays(1);
     }
 }
 public function testBindsToClosestPeriodFromReservationDates()
 {
     $page = $this->getMock('IExistingReservationPage');
     $binder = $this->getMock('IReservationComponentBinder');
     $timezone = $this->fakeUser->Timezone;
     $dateString = Date::Now()->AddDays(1)->SetTimeString('02:55:22')->Format('Y-m-d H:i:s');
     $endDateString = Date::Now()->AddDays(1)->SetTimeString('4:55:22')->Format('Y-m-d H:i:s');
     $dateInUserTimezone = Date::Parse($dateString, $timezone);
     $startDate = Date::Parse($dateString, $timezone);
     $endDate = Date::Parse($endDateString, $timezone);
     $expectedStartPeriod = new SchedulePeriod($dateInUserTimezone->SetTime(new Time(3, 30, 0)), $dateInUserTimezone->SetTime(new Time(4, 30, 0)));
     $expectedEndPeriod = new SchedulePeriod($dateInUserTimezone->SetTime(new Time(4, 30, 0)), $dateInUserTimezone->SetTime(new Time(7, 30, 0)));
     $periods = array(new SchedulePeriod($dateInUserTimezone->SetTime(new Time(1, 0, 0)), $dateInUserTimezone->SetTime(new Time(2, 0, 0))), new SchedulePeriod($dateInUserTimezone->SetTime(new Time(2, 0, 0)), $dateInUserTimezone->SetTime(new Time(3, 0, 0))), new NonSchedulePeriod($dateInUserTimezone->SetTime(new Time(3, 0, 0)), $dateInUserTimezone->SetTime(new Time(3, 30, 0))), $expectedStartPeriod, $expectedEndPeriod, new SchedulePeriod($dateInUserTimezone->SetTime(new Time(7, 30, 0)), $dateInUserTimezone->SetTime(new Time(17, 30, 0))), new SchedulePeriod($dateInUserTimezone->SetTime(new Time(17, 30, 0)), $dateInUserTimezone->SetTime(new Time(0, 0, 0))));
     $page->expects($this->once())->method('SetSelectedStart')->with($this->equalTo($expectedStartPeriod), $this->equalTo($startDate));
     $page->expects($this->once())->method('SetSelectedEnd')->with($this->equalTo($expectedEndPeriod), $this->equalTo($endDate));
     $reservationView = new ReservationView();
     $reservationView->StartDate = $startDate;
     $reservationView->EndDate = $endDate;
     $anything = Date::Now();
     $initializer = new ExistingReservationInitializer($page, $binder, $binder, $binder, $binder, $binder, $reservationView, $this->fakeUser);
     $initializer->SetDates($anything, $anything, $periods, $periods);
 }
 public function testGroupsReservations()
 {
     $now = Date::Parse('2011-03-24');
     // thursday
     Date::_SetNow($now);
     $today = new ReservationItemView('1', $now, $now);
     $tomorrow = new ReservationItemView('2', $now->AddDays(1), $now->AddDays(1));
     // friday
     $thisWeek = new ReservationItemView('3', $now->AddDays(2), $now->AddDays(2));
     // saturday
     $nextWeek = new ReservationItemView('3', $now->AddDays(3), $now->AddDays(3));
     // sunday of next week
     $reservations[] = $today;
     $reservations[] = $tomorrow;
     $reservations[] = $thisWeek;
     $reservations[] = $nextWeek;
     $this->repository->expects($this->once())->method('GetReservationList')->with($this->anything(), $this->anything(), $this->anything())->will($this->returnValue($reservations));
     $this->control->expects($this->once())->method('BindToday')->with($this->equalTo(array($today)));
     $this->control->expects($this->once())->method('BindTomorrow')->with($this->equalTo(array($tomorrow)));
     $this->control->expects($this->once())->method('BindThisWeek')->with($this->equalTo(array($thisWeek)));
     $this->control->expects($this->once())->method('BindNextWeek')->with($this->equalTo(array($nextWeek)));
     $presenter = new UpcomingReservationsPresenter($this->control, $this->repository);
     $presenter->PageLoad();
 }
Example #13
0
 public function testGetsToday()
 {
     $range = new Report_Range(Report_Range::TODAY, null, null, $this->timezone);
     $this->isTrue(Date::Parse('2011-07-20', 'America/Chicago')->Equals($range->Start()));
     $this->isTrue(Date::Parse('2011-07-21', 'America/Chicago')->Equals($range->End()));
 }
 public function testGetsConflictingReservationTimesForSingleDateSingleResourceWithBufferTimes()
 {
     $startDate = Date::Parse('2010-04-04 06:00', 'UTC');
     $endDate = Date::Parse('2010-04-04 07:00', 'UTC');
     $bufferTime = 60 * 60;
     $reservation = new TestReservationSeries();
     $resource1 = new FakeBookableResource(100, null);
     $resource1->SetBufferTime($bufferTime);
     $reservation->WithDuration(new DateRange($startDate, $endDate));
     $reservation->WithResource($resource1);
     $conflict1 = new TestReservationItemView(2, Date::Parse('2010-04-04 04:00', 'UTC'), Date::Parse('2010-04-04 05:30', 'UTC'), $resource1->GetId());
     $conflict1->WithBufferTime($bufferTime);
     $conflict2 = new TestReservationItemView(3, Date::Parse('2010-04-04 07:30', 'UTC'), Date::Parse('2010-04-04 08:00', 'UTC'), $resource1->GetId());
     $conflict2->WithBufferTime($bufferTime);
     $nonConflict1 = new TestReservationItemView(4, Date::Parse('2010-04-04 06:00', 'UTC'), Date::Parse('2010-04-04 07:30', 'UTC'), 2);
     $nonConflict1->WithBufferTime($bufferTime);
     $nonConflict2 = new TestReservationItemView(5, Date::Parse('2010-04-04 02:30', 'UTC'), Date::Parse('2010-04-04 05:00', 'UTC'), $resource1->GetId());
     $nonConflict2->WithBufferTime($bufferTime);
     $nonConflict3 = new TestReservationItemView(6, Date::Parse('2010-04-04 08:00', 'UTC'), Date::Parse('2010-04-04 09:00', 'UTC'), $resource1->GetId());
     $nonConflict3->WithBufferTime($bufferTime);
     $strategy = $this->getMock('IResourceAvailabilityStrategy');
     $strategy->expects($this->once())->method('GetItemsBetween')->with($this->equalTo($startDate->AddMinutes(-60)), $this->equalTo($endDate->AddMinutes(60)))->will($this->returnValue(array($conflict1, $conflict2, $nonConflict1, $nonConflict2, $nonConflict3)));
     $rule = new ExistingResourceAvailabilityRule($strategy, 'UTC');
     $result = $rule->Validate($reservation);
     $this->assertFalse($result->IsValid());
 }
 public function testValidatesEachDateThatAReservationRepeatsOn()
 {
     $start = Date::Parse('2010-01-01');
     $end = Date::Parse('2010-01-02');
     $reservationDates = new DateRange($start, $end);
     $twoRepetitions = new RepeatWeekly(1, $start->AddDays(14), array($start->Weekday()));
     $repeatDates = $twoRepetitions->GetDates($reservationDates);
     $reservation = new TestReservationSeries();
     $reservation->WithResource(new FakeBookableResource(1));
     $reservation->WithDuration($reservationDates);
     $reservation->WithRepeatOptions($twoRepetitions);
     $strategy = $this->getMock('IResourceAvailabilityStrategy');
     $strategy->expects($this->exactly(1 + count($repeatDates)))->method('GetItemsBetween')->with($this->anything(), $this->anything())->will($this->returnValue(array()));
     $rule = new ResourceAvailabilityRule($strategy, 'UTC');
     $result = $rule->Validate($reservation);
 }
Example #16
0
Booked Scheduler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Booked Scheduler.  If not, see <http://www.gnu.org/licenses/>.
*/
define('ROOT_DIR', dirname(__FILE__) . '/../');
require_once ROOT_DIR . "lib/Email/namespace.php";
require_once ROOT_DIR . "lib/Email/Messages/ReservationCreatedEmail.php";
require_once ROOT_DIR . "lib/Email/Messages/ReservationUpdatedEmail.php";
require_once ROOT_DIR . "Domain/namespace.php";
require_once ROOT_DIR . "tests/fakes/namespace.php";
$start = Date::Parse('2010-10-05 03:30:00', 'UTC');
$end = Date::Parse('2010-10-06 13:30:00', 'UTC');
$resourceRepo = new ResourceRepository();
$resources = $resourceRepo->GetResourceList();
$builder = new ExistingReservationSeriesBuilder();
$builder->WithPrimaryResource($resources[1]);
$reservation = $builder->Build();
//$reservation->WithCurrentInstance(new TestReservation("ref", new TestDateRange()));
//$reservation->Update(1, new FakeBookableResource(1, 'name'), 'crazy title', 'super description', new FakeUserSession());
//$reservation->UpdateDuration(new DateRange($start, $end));
$reservation->Repeats(new RepeatDayOfMonth(1, $end->AddDays(100), new DateRange($start, $end)));
$user = new FakeUser();
//$user->SetLanguage('en_gb');
$email = new ReservationUpdatedEmail($user, $reservation, 'en_us', new AttributeRepository());
echo $email->Body();
//$emailService = new EmailService();
//$emailService->Send($email);
 public function testFacadeProvidesDataFromRequestAndCollectsResponses()
 {
     $session = new FakeWebServiceUserSession(123);
     $timezone = 'America/Chicago';
     $session->Timezone = $timezone;
     $request = new ReservationRequest();
     $endDate = Date::Parse('2012-11-20 05:30', 'UTC');
     $endDateUserTz = $endDate->ToTimezone($timezone);
     $startDate = Date::Parse('2012-11-18 02:30', 'UTC');
     $startDateUserTz = $startDate->ToTimezone($timezone);
     $repeatTerminationDate = Date::Parse('2012-12-13', 'UTC');
     $repeatTerminationUserTz = $repeatTerminationDate->ToTimezone($timezone);
     $accessoryId = 8912;
     $quantity = 1232;
     $attributeId = 3393;
     $attributeValue = '23232';
     $description = 'reservation description';
     $invitees = array(9, 8);
     $participants = array(99, 88);
     $repeatInterval = 1;
     $repeatMonthlyType = null;
     $repeatType = RepeatType::Weekly;
     $repeatWeekdays = array(0, 4, 5);
     $resourceId = 122;
     $resources = array(22, 23, 33);
     $title = 'reservation title';
     $userId = 1;
     $startReminderValue = 15;
     $startReminderInterval = ReservationReminderInterval::Minutes;
     $endReminderValue = 2;
     $endReminderInterval = ReservationReminderInterval::Hours;
     $request->accessories = array(new ReservationAccessoryRequest($accessoryId, $quantity));
     $request->customAttributes = array(new AttributeValueRequest($attributeId, $attributeValue));
     $request->description = $description;
     $request->endDateTime = $endDate->ToIso();
     $request->invitees = $invitees;
     $request->participants = $participants;
     $recurrence = new RecurrenceRequestResponse($repeatType, $repeatInterval, $repeatMonthlyType, $repeatWeekdays, $repeatTerminationDate->ToIso());
     $request->recurrenceRule = $recurrence;
     $request->resourceId = $resourceId;
     $request->resources = $resources;
     $request->startDateTime = $startDate->ToIso();
     $request->title = $title;
     $request->userId = $userId;
     $request->startReminder = new ReminderRequestResponse($startReminderValue, $startReminderInterval);
     $request->endReminder = new ReminderRequestResponse($endReminderValue, $endReminderInterval);
     $facade = new ReservationRequestResponseFacade($request, $session);
     $referenceNumber = uniqid();
     $errors = array('error', 'error2');
     $facade->SetReferenceNumber($referenceNumber);
     $facade->SetErrors($errors);
     $facade->SetRequiresApproval(true);
     $accessories = array(AccessoryFormElement::Create($accessoryId, $quantity));
     $attributes = array(new AttributeFormElement($attributeId, $attributeValue));
     $this->assertEquals($accessories, $facade->GetAccessories());
     $this->assertEquals(array(), $facade->GetAttachments());
     $this->assertEquals($attributes, $facade->GetAttributes());
     $this->assertEquals($description, $facade->GetDescription());
     $this->assertEquals($endDateUserTz->Format('Y-m-d'), $facade->GetEndDate());
     $this->assertEquals($endDateUserTz->Format('H:i'), $facade->GetEndTime());
     $this->assertEquals($invitees, $facade->GetInvitees());
     $this->assertEquals($participants, $facade->GetParticipants());
     $this->assertEquals($repeatInterval, $facade->GetRepeatInterval());
     $this->assertEquals($repeatMonthlyType, $facade->GetRepeatMonthlyType());
     $this->assertEquals($repeatType, $facade->GetRepeatType());
     $this->assertEquals($repeatWeekdays, $facade->GetRepeatWeekdays());
     $this->assertEquals($repeatTerminationUserTz->Format('Y-m-d'), $facade->GetRepeatTerminationDate());
     $this->assertEquals($resourceId, $facade->GetResourceId());
     $this->assertEquals($resources, $facade->GetResources());
     $this->assertEquals($startDateUserTz->Format('Y-m-d'), $facade->GetStartDate());
     $this->assertEquals($startDateUserTz->Format('H:i'), $facade->GetStartTime());
     $this->assertEquals($title, $facade->GetTitle());
     $this->assertEquals($userId, $facade->GetUserId());
     $this->assertTrue($facade->HasStartReminder());
     $this->assertTrue($facade->HasEndReminder());
     $this->assertEquals($startReminderValue, $facade->GetStartReminderValue());
     $this->assertEquals($startReminderInterval, $facade->GetStartReminderInterval());
     $this->assertEquals($endReminderValue, $facade->GetEndReminderValue());
     $this->assertEquals($endReminderInterval, $facade->GetEndReminderInterval());
     $this->assertEquals($referenceNumber, $facade->ReferenceNumber());
     $this->assertEquals($errors, $facade->Errors());
     $this->assertEquals(true, $facade->RequiresApproval());
 }
Example #18
0
 public function testRepeatFirstFridayWhenTheFirstDayOfTheMonthIsAFriday()
 {
     $firstFriday = DateRange::Create('2014-04-04 08:00', '2014-04-04 08:00', 'UTC');
     $repeat = new RepeatWeekDayOfMonth(1, Date::Parse('2015-01-01', 'UTC'));
     /** @var $dates DateRange[] */
     $dates = $repeat->GetDates($firstFriday);
     $this->assertEquals(1, $dates[3]->GetBegin()->Day());
 }
 public function testWhenNotConstrainedByTime()
 {
     $this->fakeConfig->SetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_START_TIME_CONSTRAINT, ReservationStartTimeConstraint::NONE);
     $now = Date::Parse('2011-04-04 12:13:15', 'UTC');
     Date::_SetNow($now);
     $start = Date::Parse('2011-04-04 12:13:14', 'UTC');
     $end = $start->AddDays(5);
     $reservation = new TestReservationSeries();
     $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end)));
     $rule = new ReservationStartTimeRule($this->scheduleRepository);
     $result = $rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }
Example #20
0
 public function testAddsReservationsToCalendar()
 {
     $startsBeforeMonth = new ReservationItemView();
     $startsBeforeMonth->StartDate = Date::Parse('2011-11-25', 'UTC');
     $startsBeforeMonth->EndDate = Date::Parse('2011-12-01 12:25', 'UTC');
     $startsBeforeMonth->ResourceName = 'Something Fun';
     $startsBeforeMonth->UserLevelId = ReservationUserLevel::OWNER;
     $endsAfterMonth = new ReservationItemView();
     $endsAfterMonth->StartDate = Date::Parse('2011-12-25', 'UTC');
     $endsAfterMonth->EndDate = Date::Parse('2012-01-25', 'UTC');
     $endsAfterMonth->ResourceName = 'Something Fun';
     $endsAfterMonth->UserLevelId = ReservationUserLevel::PARTICIPANT;
     $firstDayOnly = new ReservationItemView();
     $firstDayOnly->StartDate = Date::Parse('2011-12-01 14:00', 'UTC');
     $firstDayOnly->EndDate = Date::Parse('2011-12-01 16:25', 'UTC');
     $firstDayOnly->ResourceName = 'Something Fun';
     $firstDayOnly->UserLevelId = ReservationUserLevel::OWNER;
     $secondAndThirdDay = new ReservationItemView();
     $secondAndThirdDay->StartDate = Date::Parse('2011-12-02 14:00', 'UTC');
     $secondAndThirdDay->EndDate = Date::Parse('2011-12-03 16:25', 'UTC');
     $secondAndThirdDay->ResourceName = 'Something Fun';
     $secondAndThirdDay->UserLevelId = ReservationUserLevel::INVITEE;
     $notInMonth = new ReservationItemView();
     $notInMonth->StartDate = Date::Parse('2011-11-02 14:00', 'UTC');
     $notInMonth->EndDate = Date::Parse('2011-11-03 16:25', 'UTC');
     $notInMonth->ResourceName = 'Something Fun';
     $notInMonth->UserLevelId = ReservationUserLevel::OWNER;
     $reservations = array($startsBeforeMonth, $endsAfterMonth, $firstDayOnly, $secondAndThirdDay, $notInMonth);
     $timezone = 'America/Chicago';
     $calendarReservations = CalendarReservation::FromViewList($reservations, $timezone, $this->fakeUser);
     $month = new CalendarMonth(12, 2011, $timezone);
     $month->AddReservations($calendarReservations);
     $expectedFirstDay = Date::Parse('2011-12-01', $timezone);
     $expectedLastDay = Date::Parse('2012-01-01', $timezone);
     $this->assertEquals($expectedFirstDay, $month->FirstDay());
     $this->assertEquals($expectedLastDay, $month->LastDay());
     $nullDay = CalendarDay::Null();
     $day1 = new CalendarDay($expectedFirstDay);
     $day1->AddReservation(CalendarReservation::FromView($startsBeforeMonth, $timezone, $this->fakeUser));
     $day1->AddReservation(CalendarReservation::FromView($firstDayOnly, $timezone, $this->fakeUser));
     $day2 = new CalendarDay($expectedFirstDay->AddDays(1));
     $day2->AddReservation(CalendarReservation::FromView($secondAndThirdDay, $timezone, $this->fakeUser));
     $day3 = new CalendarDay($expectedFirstDay->AddDays(2));
     $day3->AddReservation(CalendarReservation::FromView($secondAndThirdDay, $timezone, $this->fakeUser));
     $weeks = $month->Weeks();
     /** @var $actualWeek1 CalendarWeek */
     $actualWeek1 = $weeks[0];
     /** @var $actualDays array|CalendarDay[] */
     $actualDays = $actualWeek1->Days();
     $this->assertEquals(5, count($weeks));
     $this->assertEquals(7, count($actualDays));
     $this->assertEquals($nullDay, $actualDays[0]);
     $this->assertEquals($nullDay, $actualDays[1]);
     $this->assertEquals($nullDay, $actualDays[2]);
     $this->assertEquals($nullDay, $actualDays[3]);
     $this->assertEquals(2, count($actualDays[4]->Reservations()));
     $this->assertEquals($day1, $actualDays[4]);
     $this->assertEquals($day2, $actualDays[5]);
     $this->assertEquals($day3, $actualDays[6]);
     $lastWeekDays = $weeks[4]->Days();
     $lastDayReservations = $lastWeekDays[6]->Reservations();
     $this->assertEquals(CalendarReservation::FromView($endsAfterMonth, $timezone, $this->fakeUser), $lastDayReservations[0]);
     $next = Date::Parse('2012-01-01', $timezone);
     $prev = Date::Parse('2011-11-01', $timezone);
     $this->assertEquals($next, $month->GetNextDate());
     $this->assertEquals($prev, $month->GetPreviousDate());
 }
Example #21
0
 /**
  * @param string $expirationTime
  * @return bool
  */
 public static function IsExpired($expirationTime)
 {
     return Date::Parse($expirationTime, 'UTC')->LessThan(Date::Now());
 }
Example #22
0
 public function testWhenHourlyLimitIsExceededInYear()
 {
     $duration = new QuotaDurationYear();
     $limit = new QuotaLimitHours(1.5);
     $startDate = Date::Parse('2011-04-03 0:30', $this->schedule->GetTimezone());
     $endDate = Date::Parse('2011-04-03 1:30', $this->schedule->GetTimezone());
     $series = $this->GetHourLongReservation($startDate, $endDate);
     $quota = new Quota(1, $duration, $limit, $series->ResourceId());
     $res1 = new ReservationItemView('ref1', $startDate->SetTimeString('00:00'), $endDate->SetTimeString('00:31'), '', $series->ResourceId(), 98712);
     $res1->ScheduleId = $series->ScheduleId();
     $reservations = array($res1);
     $this->SearchReturns($reservations);
     $exceeds = $quota->ExceedsQuota($series, $this->user, $this->schedule, $this->reservationViewRepository);
     $this->assertTrue($exceeds);
 }
 public function testBindsReservationDetails()
 {
     $page = $this->getMock('IExistingReservationPage');
     $reservationAuthorization = $this->getMock('IReservationAuthorization');
     $privacyFilter = $this->getMock('IPrivacyFilter');
     $initializer = $this->getMock('IReservationComponentInitializer');
     $timezone = 'UTC';
     $repeatType = RepeatType::Monthly;
     $repeatInterval = 2;
     $repeatWeekdays = array(1, 2, 3);
     $repeatMonthlyType = 'dayOfMonth';
     $repeatTerminationDate = Date::Parse('2010-01-04', 'UTC');
     $title = 'title';
     $description = 'description';
     $firstName = 'fname';
     $lastName = 'lastName';
     $reservationId = 928;
     $resourceId = 10;
     $scheduleId = 100;
     $referenceNumber = '1234';
     $startDateUtc = '2010-01-01 10:11:12';
     $endDateUtc = '2010-01-02 10:11:12';
     $ownerId = 987;
     $additionalResourceIds = array(10, 20, 30);
     $participants = array(new ReservationUserView(10, 'p1', 'l', null, ReservationUserLevel::PARTICIPANT), new ReservationUserView(11, 'p2', 'l', null, ReservationUserLevel::PARTICIPANT));
     $invitees = array(new ReservationUserView($this->fakeUser->UserId, 'i1', 'l', null, ReservationUserLevel::INVITEE), new ReservationUserView(110, 'i2', 'l', null, ReservationUserLevel::INVITEE));
     $accessories = array(new ReservationAccessory(1, 2));
     $attachments = array(new ReservationAttachmentView(1, 2, 'filename'));
     $expectedStartDate = Date::Parse($startDateUtc, 'UTC');
     $expectedEndDate = Date::Parse($endDateUtc, 'UTC');
     $startReminderValue = 15;
     $startReminderInterval = ReservationReminderInterval::Minutes;
     $reservationView = new ReservationView();
     $reservationView->ReservationId = $reservationId;
     $reservationView->ReferenceNumber = $referenceNumber;
     $reservationView->ResourceId = $resourceId;
     $reservationView->ScheduleId = $scheduleId;
     $reservationView->StartDate = $expectedStartDate;
     $reservationView->EndDate = $expectedEndDate;
     $reservationView->OwnerId = $ownerId;
     $reservationView->OwnerFirstName = $firstName;
     $reservationView->OwnerLastName = $lastName;
     $reservationView->AdditionalResourceIds = $additionalResourceIds;
     $reservationView->Participants = $participants;
     $reservationView->Invitees = $invitees;
     $reservationView->Title = $title;
     $reservationView->Description = $description;
     $reservationView->RepeatType = $repeatType;
     $reservationView->RepeatInterval = $repeatInterval;
     $reservationView->RepeatWeekdays = $repeatWeekdays;
     $reservationView->RepeatMonthlyType = $repeatMonthlyType;
     $reservationView->RepeatTerminationDate = $repeatTerminationDate;
     $reservationView->StatusId = ReservationStatus::Pending;
     $reservationView->Accessories = $accessories;
     $reservationView->Attachments = $attachments;
     $reservationView->StartReminder = new ReservationReminderView($startReminderValue);
     $reservationView->EndReminder = null;
     $page->expects($this->once())->method('SetAdditionalResources')->with($this->equalTo($additionalResourceIds));
     $page->expects($this->once())->method('SetParticipants')->with($this->equalTo($participants));
     $page->expects($this->once())->method('SetInvitees')->with($this->equalTo($invitees));
     $page->expects($this->once())->method('SetTitle')->with($this->equalTo($title));
     $page->expects($this->once())->method('SetDescription')->with($this->equalTo($description));
     $page->expects($this->once())->method('SetRepeatType')->with($this->equalTo($repeatType));
     $page->expects($this->once())->method('SetRepeatInterval')->with($this->equalTo($repeatInterval));
     $page->expects($this->once())->method('SetRepeatMonthlyType')->with($this->equalTo($repeatMonthlyType));
     $page->expects($this->any())->method('SetRepeatTerminationDate')->with($repeatTerminationDate->ToTimezone($timezone));
     $page->expects($this->once())->method('SetRepeatWeekdays')->with($this->equalTo($repeatWeekdays));
     $page->expects($this->once())->method('SetAccessories')->with($this->equalTo($accessories));
     $page->expects($this->once())->method('SetAttachments')->with($this->equalTo($attachments));
     $isEditable = false;
     $reservationAuthorization->expects($this->once())->method('CanEdit')->with($this->equalTo($reservationView), $this->equalTo($this->fakeUser))->will($this->returnValue($isEditable));
     $page->expects($this->once())->method('SetIsEditable')->with($this->equalTo($isEditable));
     $isApprovable = true;
     $reservationAuthorization->expects($this->once())->method('CanApprove')->with($this->equalTo($reservationView), $this->equalTo($this->fakeUser))->will($this->returnValue($isApprovable));
     $page->expects($this->once())->method('SetIsApprovable')->with($this->equalTo($isApprovable));
     $isParticipating = false;
     $page->expects($this->once())->method('SetCurrentUserParticipating')->with($this->equalTo($isParticipating));
     $page->expects($this->once())->method('SetStartReminder')->with($this->equalTo($startReminderValue), $this->equalTo($startReminderInterval));
     $page->expects($this->never())->method('SetEndReminder');
     $isInvited = true;
     $page->expects($this->once())->method('SetCurrentUserInvited')->with($this->equalTo($isInvited));
     $initializer->expects($this->atLeastOnce())->method('GetTimezone')->will($this->returnValue($timezone));
     $initializer->expects($this->atLeastOnce())->method('CurrentUser')->will($this->returnValue($this->fakeUser));
     $canViewDetails = true;
     $canViewUser = true;
     $privacyFilter->expects($this->once())->method('CanViewDetails')->with($this->equalTo($this->fakeUser), $this->equalTo($reservationView))->will($this->returnValue($canViewDetails));
     $privacyFilter->expects($this->once())->method('CanViewUser')->with($this->equalTo($this->fakeUser), $this->equalTo($reservationView))->will($this->returnValue($canViewUser));
     $initializer->expects($this->once())->method('ShowUserDetails')->with($this->equalTo($canViewDetails));
     $initializer->expects($this->once())->method('ShowReservationDetails')->with($this->equalTo($canViewDetails));
     $binder = new ReservationDetailsBinder($reservationAuthorization, $page, $reservationView, $privacyFilter);
     $binder->Bind($initializer);
 }
 public function testGetsReservationListForDateRangeAndUser()
 {
     $startDate = Date::Parse('2011-01-01');
     $endDate = Date::Parse('2011-01-01');
     $referenceNumber1 = "ref1";
     $resource1 = "resource1";
     $start1 = Date::Parse('2011-08-09', 'UTC');
     $end1 = Date::Parse('2011-08-10', 'UTC');
     $resourceId = 929;
     $instanceId = 1000;
     $userLevelId = 2;
     $title = 'title';
     $description = 'description';
     $scheduleId = 213;
     $fname = 'fn';
     $lname = 'ln';
     $userId = 111;
     $phone = 'phone';
     $organization = 'organization';
     $position = 'position';
     $participant_list = '100=p 1!sep!200=p 2!sep!500=p 3';
     $invitee_list = '700=i 1!sep!800=1 2';
     $attributes = 'a1=av1,a2=av2';
     $preferences = 'p1=pv1,p2=pv2';
     $bufferTime = 3600;
     $rows[] = $this->GetReservationListRow($referenceNumber1, $resource1, $start1, $end1, $resourceId, $instanceId, $userLevelId, $title, $description, $scheduleId, $fname, $lname, $userId, $phone, $organization, $position, $participant_list, $invitee_list, $attributes, $preferences, $bufferTime);
     $rows[] = $this->GetReservationListRow("2", "resource", Date::Now(), Date::Now(), 1, 1, 1, null, null, 1, null, null, null, null, null, null);
     $this->db->SetRows($rows);
     $expectedCommand = new GetReservationListCommand($startDate, $endDate, $userId, ReservationUserLevel::OWNER, $scheduleId, $resourceId);
     $reservations = $this->repository->GetReservationList($startDate, $endDate, $userId, null, $scheduleId, $resourceId);
     $actualCommand = $this->db->_LastCommand;
     $this->assertEquals($expectedCommand, $actualCommand);
     $this->assertEquals(count($rows), count($reservations));
     $expectedItem1 = ReservationItemView::Populate($rows[0]);
     $this->assertEquals($expectedItem1, $reservations[0]);
 }
 public function testCanGetLayoutForScheduleOnDate()
 {
     $user = $this->fakeUser;
     $page = $this->getMock('ISchedulePage');
     $scheduleService = $this->getMock('IScheduleService');
     $resourceService = $this->getMock('IResourceService');
     $pageBuilder = $this->getMock('ISchedulePageBuilder');
     $reservationService = $this->getMock('IReservationService');
     $dailyLayoutFactory = $this->getMock('IDailyLayoutFactory');
     $layout = $this->getMock('IScheduleLayout');
     $dateString = '2013-01-07';
     $date = Date::Parse($dateString, $user->Timezone);
     $periods = array();
     $scheduleId = 1928;
     $expectedLayoutResponse = new ScheduleLayoutSerializable($periods);
     $page->expects($this->once())->method('GetScheduleId')->will($this->returnValue($scheduleId));
     $page->expects($this->once())->method('GetLayoutDate')->will($this->returnValue($dateString));
     $scheduleService->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($user->Timezone)))->will($this->returnValue($layout));
     $layout->expects($this->once())->method('GetLayout')->with($this->equalTo($date))->will($this->returnValue($periods));
     $page->expects($this->once())->method('SetLayoutResponse')->with($this->equalTo($expectedLayoutResponse));
     $presenter = new SchedulePresenter($page, $scheduleService, $resourceService, $pageBuilder, $reservationService, $dailyLayoutFactory);
     $presenter->GetLayout($user);
 }
Example #26
0
 /**
  * @static
  * @return Date
  */
 public static function Max()
 {
     return Date::Parse('9999-01-01', 'UTC');
 }
Example #27
0
 /**
  * @param string $beginString
  * @param string $endString
  * @param string $timezoneString
  * @return DateRange
  */
 public static function Create($beginString, $endString, $timezoneString)
 {
     return new DateRange(Date::Parse($beginString, $timezoneString), Date::Parse($endString, $timezoneString), $timezoneString);
 }
Example #28
0
 public function GetLayout(UserSession $user)
 {
     $scheduleId = $this->_page->GetScheduleId();
     $layoutDate = $this->_page->GetLayoutDate();
     $requestedDate = Date::Parse($layoutDate, $user->Timezone);
     $layout = $this->_scheduleService->GetLayout($scheduleId, new ScheduleLayoutFactory($user->Timezone));
     $periods = $layout->GetLayout($requestedDate);
     //		Log::Debug('Getting layout for scheduleId=%s, layoutDate=%s, periods=%s', $scheduleId, $layoutDate,var_export($periods, true));
     $this->_page->SetLayoutResponse(new ScheduleLayoutSerializable($periods));
 }
 private function GetDate($dateString, $timezone, $defaultDays)
 {
     $date = null;
     if (empty($defaultDays)) {
         return null;
     }
     if (is_null($dateString)) {
         $date = Date::Now()->AddDays($defaultDays)->ToTimezone($timezone)->GetDate();
     } elseif (!empty($dateString)) {
         $date = Date::Parse($dateString, $timezone);
     }
     return $date;
 }
 public function testUnlimitedQuantity()
 {
     $accessory1 = new ReservationAccessory(1, 5);
     $quantityAvailable = null;
     $startDate = Date::Parse('2010-04-04', 'UTC');
     $endDate = Date::Parse('2010-04-05', 'UTC');
     $reservation = new TestReservationSeries();
     $reservation->WithAccessory($accessory1);
     $dr1 = new DateRange($startDate, $endDate);
     $reservation->WithDuration($dr1);
     $this->accessoryRepository->expects($this->at(0))->method('LoadById')->with($accessory1->AccessoryId)->will($this->returnValue(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable)));
     $result = $this->rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }