public function testChecksIfUserHasPermission()
 {
     $userId = 98;
     $user = new FakeUserSession();
     $user->UserId = $userId;
     $resourceId = 100;
     $resourceId1 = 1;
     $resourceId2 = 2;
     $rr1 = new ReservationResource($resourceId);
     $rr2 = new ReservationResource($resourceId1);
     $resource = new FakeBookableResource($resourceId, null);
     $resource1 = new FakeBookableResource($resourceId1, null);
     $resource2 = new FakeBookableResource($resourceId2, null);
     $reservation = new TestReservationSeries();
     $reservation->WithOwnerId($userId);
     $reservation->WithResource($resource);
     $reservation->AddResource($resource1);
     $reservation->AddResource($resource2);
     $reservation->WithBookedBy($user);
     $service = new FakePermissionService(array(true, false));
     $factory = $this->getMock('IPermissionServiceFactory');
     $factory->expects($this->once())->method('GetPermissionService')->will($this->returnValue($service));
     $rule = new PermissionValidationRule($factory);
     $result = $rule->Validate($reservation);
     $this->assertEquals(false, $result->IsValid());
     $this->assertEquals($rr1, $service->Resources[0]);
     $this->assertEquals($rr2, $service->Resources[1]);
     $this->assertEquals($rr2, $service->Resources[1]);
     $this->assertEquals($user, $service->User);
 }
Exemplo n.º 2
0
 public function setup()
 {
     parent::setup();
     $this->userRepository = $this->getMock('IUserRepository');
     $this->baseRule = $this->getMock('IReservationValidationRule');
     $this->user = $this->getMock('User');
     $this->rule = new AdminExcludedRule($this->baseRule, $this->fakeUser, $this->userRepository);
     $this->reservationSeries = new TestReservationSeries();
     $this->resource1 = new FakeBookableResource(1);
     $this->resource2 = new FakeBookableResource(2);
     $this->reservationSeries->WithResource($this->resource1);
     $this->reservationSeries->AddResource($this->resource2);
 }
 public function testWhenBothResourcesAreOverLimit()
 {
     $series = new TestReservationSeries();
     $series->WithCurrentInstance(new TestReservation());
     $series->WithResource($this->resourceLimit10);
     $series->AddResource($this->resourceLimit20);
     $series->ChangeParticipants(range(1, 22));
     $result = $this->rule->Validate($series);
     $this->assertFalse($result->IsValid());
 }
 public function testNotValidIfTheReservationIsShorterThanTheMinDurationForAnyResource()
 {
     $resource1 = new FakeBookableResource(1, "1");
     $resource1->SetMinLength(null);
     $resource2 = new FakeBookableResource(2, "2");
     $resource2->SetMinLength("25h00m");
     $reservation = new TestReservationSeries();
     $duration = new DateRange(Date::Now(), Date::Now()->AddDays(1));
     $reservation->WithDuration($duration);
     $reservation->WithResource($resource1);
     $reservation->AddResource($resource2);
     $rule = new ResourceMinimumDurationRule();
     $result = $rule->Validate($reservation);
     $this->assertFalse($result->IsValid());
 }
 public function testMaxNoticeIsCheckedAgainstEachReservationInstanceForEachResource()
 {
     $resource1 = new FakeBookableResource(1, "1");
     $resource1->SetMaxNotice(null);
     $resource2 = new FakeBookableResource(2, "2");
     $resource2->SetMaxNotice("23h00m");
     $reservation = new TestReservationSeries();
     $duration = new DateRange(Date::Now(), Date::Now());
     $tooFarInFuture = Date::Now()->AddDays(1);
     $reservation->WithDuration($duration);
     $reservation->WithRepeatOptions(new RepeatDaily(1, $tooFarInFuture));
     $reservation->WithResource($resource1);
     $reservation->AddResource($resource2);
     $rule = new ResourceMaximumNoticeRule();
     $result = $rule->Validate($reservation);
     $this->assertFalse($result->IsValid());
 }
 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 testRuleIsValidIfNoConflictsForTheReservationResourcesWithBufferTimes()
 {
     $startDate = Date::Parse('2010-04-04 06:00', 'UTC');
     $endDate = Date::Parse('2010-04-04 07:00', 'UTC');
     $r1Buffer = 60 * 60;
     $r2Buffer = 30 * 60;
     $reservation = new TestReservationSeries();
     $resource1 = new FakeBookableResource(100, null);
     $resource1->SetBufferTime($r1Buffer);
     $resource2 = new FakeBookableResource(101, null);
     $resource2->SetBufferTime($r2Buffer);
     $reservation->WithDuration(new DateRange($startDate, $endDate));
     $reservation->WithResource($resource1);
     $reservation->AddResource($resource2);
     $reservation->AddResource(new FakeBookableResource(102, null));
     $scheduleReservation1 = new TestReservationItemView(2, Date::Parse('2010-04-04 04:00', 'UTC'), Date::Parse('2010-04-04 05:00', 'UTC'), $resource1->GetId());
     $scheduleReservation1->WithBufferTime($r1Buffer);
     $scheduleReservation2 = new TestReservationItemView(3, Date::Parse('2010-04-04 08:00', 'UTC'), Date::Parse('2010-04-04 09:00', 'UTC'), $resource1->GetId());
     $scheduleReservation2->WithBufferTime($r1Buffer);
     $scheduleReservation3 = new TestReservationItemView(4, Date::Parse('2010-04-04 05:00', 'UTC'), Date::Parse('2010-04-04 05:30', 'UTC'), $resource2->GetId());
     $scheduleReservation3->WithBufferTime($r2Buffer);
     $scheduleReservation4 = new TestReservationItemView(5, Date::Parse('2010-04-04 07:30', 'UTC'), Date::Parse('2010-04-04 08:00', 'UTC'), $resource2->GetId());
     $scheduleReservation4->WithBufferTime($r2Buffer);
     $scheduleReservation5 = new TestReservationItemView(6, $startDate, $endDate, 999);
     $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($scheduleReservation1, $scheduleReservation2, $scheduleReservation3, $scheduleReservation4, $scheduleReservation5)));
     $rule = new ExistingResourceAvailabilityRule($strategy, 'UTC');
     $result = $rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }
 public function testCanAddAdditionalResources()
 {
     $seriesId = 999;
     $id1 = 1;
     $id2 = 2;
     $reservation = new TestReservationSeries();
     $reservation->WithResource(new FakeBookableResource(837));
     $reservation->AddResource(new FakeBookableResource($id1));
     $reservation->AddResource(new FakeBookableResource($id2));
     $this->db->_ExpectedInsertId = $seriesId;
     $this->repository->Add($reservation);
     $insertResource1 = new AddReservationResourceCommand($seriesId, $id1, ResourceLevel::Additional);
     $insertResource2 = new AddReservationResourceCommand($seriesId, $id2, ResourceLevel::Additional);
     $this->assertTrue(in_array($insertResource1, $this->db->_Commands));
     $this->assertTrue(in_array($insertResource2, $this->db->_Commands));
 }