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);
 }
 public function testDoesNotMarkAsRequiringApprovalIfUserCanApproveForResource()
 {
     $series = new TestReservationSeries();
     $resource = new FakeBookableResource(1);
     $resource->RequiresApproval(true);
     $series->WithResource($resource);
     $series->WithBookedBy($this->fakeUser);
     $this->authorizationService->expects($this->once())->method('CanApproveForResource')->with($this->equalTo($this->fakeUser), $this->equalTo($resource))->will($this->returnValue(true));
     $this->rule->Validate($series);
     $this->assertFalse($series->RequiresApproval());
 }
 public function testApplicationAdminsAreExcludedFromBufferConstraints()
 {
     $startDate = Date::Parse('2010-04-04 06:00', 'UTC');
     $endDate = Date::Parse('2010-04-04 07:00', 'UTC');
     $bufferTime = 60 * 60;
     $reservation = new TestReservationSeries();
     $resource1 = new FakeBookableResource(100, null);
     $resource1->SetBufferTime($bufferTime);
     $reservation->WithDuration(new DateRange($startDate, $endDate));
     $reservation->WithResource($resource1);
     $reservation->WithBookedBy(new FakeUserSession(true));
     $conflict1 = new TestReservationItemView(2, Date::Parse('2010-04-04 04:00', 'UTC'), Date::Parse('2010-04-04 06:00', 'UTC'), $resource1->GetId());
     $conflict1->WithBufferTime($bufferTime);
     $strategy = $this->getMock('IResourceAvailabilityStrategy');
     $strategy->expects($this->once())->method('GetItemsBetween')->with($this->equalTo($startDate), $this->equalTo($endDate))->will($this->returnValue(array($conflict1)));
     $rule = new ResourceAvailabilityRule($strategy, 'UTC');
     $result = $rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }