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());
 }
Beispiel #2
0
 private function GetHourLongReservation($startDate, $endDate, $resourceId1 = null, $resourceId2 = null, $scheduleId = null)
 {
     $userId = 12;
     $resource1 = empty($resourceId1) ? 13 : $resourceId1;
     $resource2 = empty($resourceId2) ? 14 : $resourceId2;
     $schedule = empty($scheduleId) ? 1 : $scheduleId;
     $hourLongReservation = new DateRange($startDate, $endDate, $this->tz);
     $resource = new FakeBookableResource($resource1);
     $resource->SetScheduleId($schedule);
     $series = ReservationSeries::Create($userId, $resource, null, null, $hourLongReservation, new RepeatNone(), new FakeUserSession());
     $series->AddResource(new FakeBookableResource($resource2));
     return $series;
 }
Beispiel #3
0
 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');
 }