public function testWhenScheduleNotFound() { $scheduleId = 89181; $this->scheduleRepository->expects($this->once())->method('LoadById')->with($this->equalTo($scheduleId))->will($this->returnValue(null)); $this->service->GetSchedule($scheduleId); $this->assertEquals(RestResponse::NotFound(), $this->server->_LastResponse); }
public function testGetsScheduleByPublicId() { $expected = new FakeSchedule(); $publicId = uniqid(); $this->scheduleRepo->expects($this->once())->method('LoadByPublicId')->with($this->equalTo($publicId))->will($this->returnValue($expected)); $actual = $this->service->GetSchedule($publicId); $this->assertEquals($expected, $actual); }
public function testSucceedsWhenStartAndEndTimeMatchPeriods() { $date = Date::Now(); $dates = new DateRange($date, $date); $scheduleId = 1232; $resource = new FakeBookableResource(1); $resource->SetScheduleId($scheduleId); $series = ReservationSeries::Create(1, $resource, null, null, $dates, new RepeatNone(), $this->fakeUser); $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($this->fakeUser->Timezone)))->will($this->returnValue($this->layout)); $period = new SchedulePeriod($date, $date); $this->layout->expects($this->at(0))->method('GetPeriod')->with($this->equalTo($series->CurrentInstance()->StartDate()))->will($this->returnValue($period)); $this->layout->expects($this->at(1))->method('GetPeriod')->with($this->equalTo($series->CurrentInstance()->EndDate()))->will($this->returnValue($period)); $result = $this->rule->Validate($series); $this->assertTrue($result->IsValid()); }
public function testWhenInitializing() { $groups = array(); $bookableResources = array(); $schedules = array(); $groupResult = new PageableData($groups); $quotaList = array(); $this->resourceRepository->expects($this->once())->method('GetResourceList')->will($this->returnValue($bookableResources)); $this->page->expects($this->once())->method('BindResources')->with($this->equalTo($bookableResources)); $this->groupRepository->expects($this->once())->method('GetList')->will($this->returnValue($groupResult)); $this->page->expects($this->once())->method('BindGroups')->with($this->equalTo($groups)); $this->scheduleRepository->expects($this->once())->method('GetAll')->will($this->returnValue($schedules)); $this->page->expects($this->once())->method('BindSchedules')->with($this->equalTo($schedules)); $this->quotaRepository->expects($this->once())->method('GetAll')->will($this->returnValue($quotaList)); $this->presenter->PageLoad(); }
public function testFirstQuotaExceeded() { $scheduleId = 971243; $timezone = 'America/New_York'; $userId = 10; $groupId1 = 8287; $groupId2 = 102; $user = new FakeUser(); $user->SetGroups(array($groupId1, $groupId2)); $schedule = new Schedule(1, null, null, null, null, $timezone); $resource = new FakeBookableResource(20); $resource->SetScheduleId($scheduleId); $series = ReservationSeries::Create($userId, $resource, null, null, new TestDateRange(), new RepeatNone(), new FakeUserSession()); $series->AddResource(new FakeBookableResource(22)); $quota1 = $this->mockQuota('IQuota'); $quota2 = $this->mockQuota('IQuota'); $quotas = array($quota1, $quota2); $this->quotaRepository->expects($this->once())->method('LoadAll')->will($this->returnValue($quotas)); $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->scheduleRepository->expects($this->once())->method('LoadById')->with($this->equalTo($scheduleId))->will($this->returnValue($schedule)); $this->ChecksAgainstQuota($quota1, $series, $this->reservationViewRepository, $schedule, $user, true); $quota2->expects($this->never())->method('ExceedsQuota'); $rule = new QuotaRule($this->quotaRepository, $this->reservationViewRepository, $this->userRepository, $this->scheduleRepository); $result = $rule->Validate($series); $this->assertFalse($result->IsValid(), 'first quotas was exceeded'); }
public function testRuleIsInValidIfReservationCrossesDayInScheduleTimezone() { $start = Date::Now(); $end = Date::Now()->AddDays(1); $reservation = new TestReservationSeries(); $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end))); $resource = new FakeBookableResource(1); $resource->SetAllowMultiday(true); $resource2 = new FakeBookableResource(2); $resource2->SetAllowMultiday(false); $reservation->WithResource($resource); $reservation->AddResource($resource2); $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->assertFalse($result->IsValid()); }
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 testWhenPeriodStartTimeIsInPast() { $this->fakeConfig->SetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_START_TIME_CONSTRAINT, ReservationStartTimeConstraint::CURRENT); $scheduleId = 123; $now = Date::Parse('2011-04-04 12:13:15', 'UTC'); Date::_SetNow($now); $start = $now->AddDays(-5); $end = $now->AddDays(5); $periodStart = Date::Parse('2011-04-04 12:13:14', 'UTC'); $periodEnd = Date::Parse('2011-04-04 12:13:16', 'UTC'); $reservation = new TestReservationSeries(); $reservation->WithScheduleId($scheduleId); $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end))); $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory('UTC')))->will($this->returnValue($this->layout)); $period = new SchedulePeriod($periodStart, $periodEnd); $this->layout->expects($this->once())->method('GetPeriod')->with($this->equalTo($end))->will($this->returnValue($period)); $rule = new ReservationStartTimeRule($this->scheduleRepository); $result = $rule->Validate($reservation); $this->assertFalse($result->IsValid()); }
public function testBindsEmptyCalendarToPageWhenNoReservationsAreFound() { $userId = 10; $this->fakeUser->UserId = $userId; $userTimezone = "America/New_York"; $calendarType = CalendarTypes::Month; $requestedDay = 4; $requestedMonth = 3; $requestedYear = 2011; $month = new CalendarMonth($requestedMonth, $requestedYear, $userTimezone); $reservations = array(); $showInaccessible = true; $this->fakeConfig->SetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, 'true'); $resourceId = 1; $resourceName = 'rn'; $defaultScheduleId = 12; $r1 = new FakeBookableResource(1, 'dude1'); $r2 = new FakeBookableResource($resourceId, $resourceName); $resources = array($r1, $r2); $resourceGroupTree = new ResourceGroupTree(); $schedules = array(new Schedule(1, null, false, 2, null), new Schedule($defaultScheduleId, null, true, 3, null)); $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->once())->method('GetReservationList')->with($this->equalTo($month->FirstDay()), $this->equalTo($month->LastDay()->AddDays(1)), $this->equalTo($userId), $this->equalTo(ReservationUserLevel::ALL), $this->isNull(), $this->isNull())->will($this->returnValue($reservations)); $this->page->expects($this->once())->method('GetCalendarType')->will($this->returnValue($calendarType)); $this->page->expects($this->once())->method('GetDay')->will($this->returnValue($requestedDay)); $this->page->expects($this->once())->method('GetMonth')->will($this->returnValue($requestedMonth)); $this->page->expects($this->once())->method('GetYear')->will($this->returnValue($requestedYear)); $this->calendarFactory->expects($this->once())->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->once())->method('BindCalendar')->with($this->equalTo($month)); $details = new CalendarSubscriptionDetails(true); $this->subscriptionService->expects($this->once())->method('ForUser')->with($this->equalTo($userId))->will($this->returnValue($details)); $this->page->expects($this->once())->method('BindSubscription')->with($this->equalTo($details)); $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->anything(), $this->equalTo($this->fakeUser))->will($this->returnValue($resourceGroupTree)); $this->page->expects($this->atLeastOnce())->method('SetFirstDay')->with($this->equalTo($schedules[1]->GetWeekdayStart())); $calendarFilters = new CalendarFilters($schedules, $resources, null, null, $resourceGroupTree); $this->page->expects($this->atLeastOnce())->method('BindFilters')->with($this->equalTo($calendarFilters)); $this->presenter->PageLoad($this->fakeUser, $userTimezone); }
public function testMovesFirstPeriodToEndIfTimeIsLaterInTheDay() { $timezone = 'UTC'; $scheduleId = 1; $dateString = Date::Now()->AddDays(1)->SetTimeString('02:55:22')->Format('Y-m-d H:i:s'); $dateInUserTimezone = Date::Parse($dateString, $timezone); $requestedDate = Date::Parse($dateString, $timezone); $this->initializer->expects($this->any())->method('CurrentUser')->will($this->returnValue($this->fakeUser)); $this->initializer->expects($this->any())->method('GetTimezone')->will($this->returnValue($timezone)); $this->initializer->expects($this->any())->method('GetReservationDate')->will($this->returnValue($dateInUserTimezone)); $this->initializer->expects($this->any())->method('GetStartDate')->will($this->returnValue($requestedDate)); $this->initializer->expects($this->any())->method('GetEndDate')->will($this->returnValue($requestedDate)); $this->initializer->expects($this->any())->method('GetScheduleId')->will($this->returnValue($scheduleId)); $periods = array(new SchedulePeriod(Date::Parse('2012-01-22 22:00', $timezone), Date::Parse('2012-01-22 10:00', $timezone)), new SchedulePeriod(Date::Parse('2012-01-22 10:00', $timezone), Date::Parse('2012-01-23 22:00', $timezone))); $startPeriods = array($periods[1], $periods[0]); $layout = $this->getMock('IScheduleLayout'); $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ReservationLayoutFactory($timezone)))->will($this->returnValue($layout)); $layout->expects($this->any())->method('GetLayout')->with($this->equalTo($requestedDate))->will($this->returnValue($periods)); $this->initializer->expects($this->once())->method('SetDates')->with($this->equalTo($requestedDate), $this->equalTo($requestedDate), $this->equalTo($startPeriods), $this->equalTo($periods)); $binder = new ReservationDateBinder($this->scheduleRepository); $binder->Bind($this->initializer); }