示例#1
0
 public function testChecksWhenAtLeastOneGroupApplies()
 {
     $g1 = new UserGroup(1, null);
     $g2 = new UserGroup(2, null);
     $g4 = new UserGroup(4, null);
     $this->user->SetGroups(array($g1, $g2, $g4));
     $groupId = 4;
     $startDate = Date::Parse('2011-07-31 21:30', $this->tz);
     $endDate = Date::Parse('2011-08-01 2:30', $this->tz);
     $quota = new Quota(1, new QuotaDurationDay(), new QuotaLimitCount(0), null, $groupId, null);
     $series = $this->GetHourLongReservation($startDate, $endDate, 101, 102);
     $this->SearchReturns(array());
     $exceeds = $quota->ExceedsQuota($series, $this->user, $this->schedule, $this->reservationViewRepository);
     $this->assertTrue($exceeds);
 }
示例#2
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');
 }