public function testCannotSeeReservationDetailsIfConfiguredOff() { $referenceNumber = 'ref'; $reservationResult = new ReservationView(); $this->validator->expects($this->atLeastOnce())->method('IsValid')->will($this->returnValue(true)); $this->page->expects($this->once())->method('GetReferenceNumber')->will($this->returnValue($referenceNumber)); $this->repo->expects($this->once())->method('GetReservationForEditing')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservationResult)); $this->page->expects($this->once())->method('SetReservations')->with($this->arrayHasKey(0)); $this->presenter->PageLoad($this->fakeUser); }
public function testLoadsReservationIfTheUserCanEdit() { $reservation = new ReservationView(); $user = $this->fakeUser; $referenceNumber = 'rn'; $this->reservationViewRepository->expects($this->once())->method('GetReservationForEditing')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservation)); $this->reservationAuthorization->expects($this->once())->method('CanEdit')->with($this->equalTo($reservation), $this->equalTo($user))->will($this->returnValue(true)); $res = $this->service->LoadByReferenceNumber($referenceNumber, $user); $this->assertEquals($reservation, $res); }
public function testPullsReservationViewFromRepository() { $referenceNumber = '1234'; $reservationView = new ReservationView(); $this->page->expects($this->once())->method('GetReferenceNumber')->will($this->returnValue($referenceNumber)); $this->reservationViewRepository->expects($this->once())->method('GetReservationForEditing')->with($referenceNumber)->will($this->returnValue($reservationView)); $this->preconditionService->expects($this->once())->method('CheckAll')->with($this->page, $this->user, $reservationView); $this->initializerFactory->expects($this->once())->method('GetExistingInitializer')->with($this->equalTo($this->page), $this->equalTo($reservationView))->will($this->returnValue($this->initializer)); $this->initializer->expects($this->once())->method('Initialize'); $presenter = new EditReservationPresenter($this->page, $this->initializerFactory, $this->preconditionService, $this->reservationViewRepository); $presenter->PageLoad(); }
public function testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingReservations() { $pageNumber = 1; $pageSize = 40; $groups = array(new UserGroup(1, '1'), new UserGroup(5, '5'), new UserGroup(9, '9'), new UserGroup(22, '22')); $myGroups = array(1, 5, 9, 22); $this->userRepository->expects($this->once())->method('LoadGroups')->with($this->equalTo($this->fakeUser->UserId), $this->equalTo(RoleLevel::RESOURCE_ADMIN))->will($this->returnValue($groups)); $filter = new ReservationFilter(); $expectedFilter = $filter->GetFilter(); $expectedFilter->_And(new SqlFilterIn(new SqlFilterColumn(TableNames::RESOURCES, ColumnNames::RESOURCE_ADMIN_GROUP_ID), $myGroups)); $data = new PageableData(); $this->reservationViewRepository->expects($this->once())->method('GetList')->with($pageNumber, $pageSize, null, null, $expectedFilter)->will($this->returnValue($data)); $actualData = $this->service->LoadFiltered($pageNumber, $pageSize, $filter, $this->fakeUser); $this->assertEquals($data, $actualData); }
public function testConflictHandlerReportsConflictingReservationAndDoesNotUpdateBlackout() { $userId = $this->fakeUser->UserId; $start = Date::Parse('2011-01-01 01:01:01'); $end = Date::Parse('2011-02-02 02:02:02'); $date = new DateRange($start, $end); $resourceId = 2; $resourceIds = array($resourceId); $title = 'title'; $seriesId = 111; $blackoutInstanceId = 10; $series = BlackoutSeries::Create(1, 'old title', new TestDateRange()); $series->WithId($seriesId); $user = $this->getMock('User'); $user->expects($this->any())->method('IsResourceAdminFor')->with($this->anything())->will($this->returnValue(true)); $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->reservationViewRepository->expects($this->once())->method('GetBlackoutsWithin')->with($this->equalTo($date))->will($this->returnValue(array())); $reservation1 = new TestReservationItemView(1, $start, $end, 2); $reservation2 = new TestReservationItemView(2, $start, $end, 2); $this->reservationViewRepository->expects($this->once())->method('GetReservationList')->with($this->equalTo($start), $this->equalTo($end))->will($this->returnValue(array($reservation1, $reservation2))); $this->conflictHandler->expects($this->at(0))->method('Handle')->with($this->equalTo($reservation1))->will($this->returnValue(false)); $this->conflictHandler->expects($this->at(1))->method('Handle')->with($this->equalTo($reservation2))->will($this->returnValue(false)); $this->blackoutRepository->expects($this->never())->method('Update'); $this->blackoutRepository->expects($this->once())->method('LoadByBlackoutId')->with($this->equalTo($blackoutInstanceId))->will($this->returnValue($series)); $result = $this->service->Update($blackoutInstanceId, $date, $resourceIds, $title, $this->conflictHandler, new RepeatNone(), SeriesUpdateScope::FullSeries); $this->assertFalse($result->WasSuccessful()); }
public function testWhenReservationIsNotFound() { $reservation = NullReservationView::Instance(); $referenceNumber = '12323'; $this->reservationViewRepository->expects($this->once())->method('GetReservationForEditing')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservation)); $this->service->GetReservation($referenceNumber); $expectedResponse = RestResponse::NotFound(); $this->assertEquals($expectedResponse, $this->server->_LastResponse); }
public function testWhenViewingOpenInvites() { $startDate = Date::Now(); $endDate = $startDate->AddDays(30); $userId = $this->fakeUser->UserId; $inviteeLevel = ReservationUserLevel::INVITEE; $reservations[] = new ReservationItemView(); $reservations[] = new ReservationItemView(); $reservations[] = new ReservationItemView(); $this->reservationViewRepo->expects($this->once())->method('GetReservationList')->with($this->equalTo($startDate), $this->equalTo($endDate), $this->equalTo($userId), $this->equalTo($inviteeLevel))->will($this->returnValue($reservations)); $this->page->expects($this->once())->method('BindReservations')->with($this->equalTo($reservations)); $this->presenter->PageLoad(); }
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 testNoConflictsButTooHigh() { $accessory1 = new ReservationAccessory(1, 5); $quantityAvailable = 4; $reservation = new TestReservationSeries(); $dr1 = new TestDateRange(); $reservation->WithDuration($dr1); $reservation->WithAccessory($accessory1); $this->accessoryRepository->expects($this->at(0))->method('LoadById')->with($accessory1->AccessoryId)->will($this->returnValue(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable))); $this->reservationRepository->expects($this->once(0))->method('GetAccessoriesWithin')->with($this->anything())->will($this->returnValue(array())); $result = $this->rule->Validate($reservation); $this->assertFalse($result->IsValid()); $this->assertFalse(is_null($result->ErrorMessage())); }
public function testGetsUserReservationsForTheNextYearByResourceId() { $publicId = '1'; $reservationResult = array(new TestReservationItemView(1, Date::Now(), Date::Now())); $userId = 999; $user = new FakeUser($userId); $weekAgo = Date::Now()->AddDays(-7); $nextYear = Date::Now()->AddDays(365); $this->page->expects($this->once())->method('GetUserId')->will($this->returnValue($publicId)); $this->service->expects($this->once())->method('GetUser')->with($this->equalTo($publicId))->will($this->returnValue($user)); $this->repo->expects($this->once())->method('GetReservationList')->with($this->equalTo($weekAgo), $this->equalTo($nextYear), $this->equalTo($userId), $this->isNull(), $this->isNull(), $this->isNull())->will($this->returnValue($reservationResult)); $this->page->expects($this->once())->method('SetReservations')->with($this->arrayHasKey(0)); $this->presenter->PageLoad(); }
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(); }
public function testNoConflictsIfReservationExistsAtSameTimeForDifferentResource() { $resourceId1 = 1; $resourceId2 = 2; $resourceId3 = 3; $currentId = 19; $currentDate = new DateRange(Date::Now()->AddDays(10), Date::Now()->AddDays(15)); $current = new TestReservation('ref', $currentDate); $current->SetReservationId($currentId); $series = new ExistingReservationSeries(); $series->WithPrimaryResource(new FakeBookableResource($resourceId1)); $series->WithResource(new FakeBookableResource($resourceId2)); $series->WithCurrentInstance($current); $reservations = array(new TestReservationItemView($currentId + 1, Date::Now(), Date::Now(), $resourceId3)); $this->strategy->expects($this->once())->method('GetItemsBetween')->with($this->anything(), $this->anything())->will($this->returnValue($reservations)); $rule = new ExistingResourceAvailabilityRule($this->strategy, $this->timezone); $ruleResult = $rule->Validate($series); $this->assertTrue($ruleResult->IsValid()); }
public function testGetsSingleResourceAvailabilityForARequestTime() { $date = Date::Parse('2014-01-01 04:30:00', 'America/Chicago'); $this->server->SetQueryString(WebServiceQueryStringKeys::DATE_TIME, $date->ToIso()); $resourceId1 = 1; $startTime = $date->AddHours(-1); $endTime = $date->AddHours(1); $resource = new FakeBookableResource($resourceId1); $this->repository->expects($this->once())->method('LoadById')->with($this->equalTo($resourceId1))->will($this->returnValue($resource)); $conflicting = new TestReservationItemView(1, $startTime, $endTime, $resourceId1); $upcoming = new TestReservationItemView(2, $endTime, $endTime->AddHours(3), $resourceId1); $upcoming2 = new TestReservationItemView(3, $endTime->AddHours(3), $endTime->AddHours(4), $resourceId1); $upcoming3 = new TestReservationItemView(4, $endTime->AddHours(5), $endTime->AddHours(6), $resourceId1); $reservations = array($conflicting, $upcoming, $upcoming2, $upcoming3); $endDate = $date->AddDays(7); $this->reservationRepository->expects($this->once())->method('GetReservationList')->with($this->equalTo($date->AddDays(-1)->ToUtc()), $this->equalTo($endDate->ToUtc()), $this->isEmpty(), $this->isEmpty(), $this->isEmpty(), $this->equalTo($resourceId1))->will($this->returnValue($reservations)); $this->service->GetAvailability($resourceId1); $resources = array(new ResourceAvailabilityResponse($this->server, $resource, $conflicting, $upcoming, $endTime->AddHours(4), $endDate)); $this->assertEquals(new ResourcesAvailabilityResponse($this->server, $resources), $this->server->_LastResponse); }
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); }
private function SearchReturns($reservations) { $this->reservationViewRepository->expects($this->once())->method('GetReservationList')->with($this->anything(), $this->anything(), $this->anything(), $this->anything())->will($this->returnValue($reservations)); }