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 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 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 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 testOkIfLatestInstanceIsBeforeTheMaximumNoticeTime() { $resource = new FakeBookableResource(1, "2"); $resource->SetMaxNotice("1h00m"); $reservation = new TestReservationSeries(); $reservation->WithResource($resource); $duration = new DateRange(Date::Now(), Date::Now()); $reservation->WithDuration($duration); $rule = new ResourceMaximumNoticeRule(); $result = $rule->Validate($reservation); $this->assertTrue($result->IsValid()); }
public function testOkIfReservationIsShorterThanTheMaximumDuration() { $resource = new FakeBookableResource(1, "2"); $resource->SetMaxLength("25h00m"); $reservation = new TestReservationSeries(); $reservation->WithResource($resource); $duration = new DateRange(Date::Now(), Date::Now()->AddDays(1)); $reservation->WithDuration($duration); $rule = new ResourceMaximumDurationRule(); $result = $rule->Validate($reservation); $this->assertTrue($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 testSendsReservationCreatedEmailIfUserWantsIt() { $event = new ReservationCreatedEvent(); $ownerId = 100; $resourceId = 200; $resource = new FakeBookableResource($resourceId, 'name'); $reservation = new TestReservationSeries(); $reservation->WithOwnerId($ownerId); $reservation->WithResource($resource); $userRepo = $this->getMock('IUserRepository'); $attributeRepo = $this->getMock('IAttributeRepository'); $user = $this->LoadsUser($userRepo, $ownerId); $this->AsksUser($user, $event); $notification = new OwnerEmailCreatedNotification($userRepo, $attributeRepo); $notification->Notify($reservation); $expectedMessage = new ReservationCreatedEmail($user, $reservation, null, $attributeRepo); $lastMessage = $this->fakeEmailService->_LastMessage; $this->assertInstanceOf('ReservationCreatedEmail', $lastMessage); // $this->assertEquals($expectedMessage, $lastMessage); }
public function testGetsConflictingReservationTimesForSingleDateSingleResourceWithBufferTimes() { $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); $conflict1 = new TestReservationItemView(2, Date::Parse('2010-04-04 04:00', 'UTC'), Date::Parse('2010-04-04 05:30', 'UTC'), $resource1->GetId()); $conflict1->WithBufferTime($bufferTime); $conflict2 = new TestReservationItemView(3, Date::Parse('2010-04-04 07:30', 'UTC'), Date::Parse('2010-04-04 08:00', 'UTC'), $resource1->GetId()); $conflict2->WithBufferTime($bufferTime); $nonConflict1 = new TestReservationItemView(4, Date::Parse('2010-04-04 06:00', 'UTC'), Date::Parse('2010-04-04 07:30', 'UTC'), 2); $nonConflict1->WithBufferTime($bufferTime); $nonConflict2 = new TestReservationItemView(5, Date::Parse('2010-04-04 02:30', 'UTC'), Date::Parse('2010-04-04 05:00', 'UTC'), $resource1->GetId()); $nonConflict2->WithBufferTime($bufferTime); $nonConflict3 = new TestReservationItemView(6, Date::Parse('2010-04-04 08:00', 'UTC'), Date::Parse('2010-04-04 09:00', 'UTC'), $resource1->GetId()); $nonConflict3->WithBufferTime($bufferTime); $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($conflict1, $conflict2, $nonConflict1, $nonConflict2, $nonConflict3))); $rule = new ExistingResourceAvailabilityRule($strategy, 'UTC'); $result = $rule->Validate($reservation); $this->assertFalse($result->IsValid()); }
public function testValidatesEachDateThatAReservationRepeatsOn() { $start = Date::Parse('2010-01-01'); $end = Date::Parse('2010-01-02'); $reservationDates = new DateRange($start, $end); $twoRepetitions = new RepeatWeekly(1, $start->AddDays(14), array($start->Weekday())); $repeatDates = $twoRepetitions->GetDates($reservationDates); $reservation = new TestReservationSeries(); $reservation->WithResource(new FakeBookableResource(1)); $reservation->WithDuration($reservationDates); $reservation->WithRepeatOptions($twoRepetitions); $strategy = $this->getMock('IResourceAvailabilityStrategy'); $strategy->expects($this->exactly(1 + count($repeatDates)))->method('GetItemsBetween')->with($this->anything(), $this->anything())->will($this->returnValue(array())); $rule = new ResourceAvailabilityRule($strategy, 'UTC'); $result = $rule->Validate($reservation); }
public function testDoesNotSendReservationCreatedRequiresApprovalEmailIfAdminWantsItButNotRequiresApproval() { $ownerId = 100; $resourceId = 200; $resource = new FakeBookableResource($resourceId, 'name'); $reservation = new TestReservationSeries(); $reservation->WithOwnerId($ownerId); $reservation->WithResource($resource); $reservation->SetStatusId(ReservationStatus::Created); $attributeRepo = $this->getMock('IAttributeRepository'); $userRepo = $this->getMock('IUserRepository'); $this->EnableNotifyFor(ConfigKeys::NOTIFY_APPROVAL_RESOURCE_ADMINS); $this->EnableNotifyFor(ConfigKeys::NOTIFY_APPROVAL_APPLICATION_ADMINS); $this->EnableNotifyFor(ConfigKeys::NOTIFY_APPROVAL_GROUP_ADMINS); $notification = new AdminEmailApprovalNotification($userRepo, $userRepo, $attributeRepo); $notification->Notify($reservation); $this->assertEquals(0, count($this->fakeEmailService->_Messages)); }
public function testAddsReservationReminders() { $seriesId = 999; $reservation = new TestReservationSeries(); $reservation->WithResource(new FakeBookableResource(837)); $reservation->AddStartReminder(new ReservationReminder(15, ReservationReminderInterval::Hours)); $reservation->AddEndReminder(new ReservationReminder(400, ReservationReminderInterval::Minutes)); $minutesPriorStart = 60 * 15; $minutesPriorEnd = 400; $this->db->_ExpectedInsertId = $seriesId; $this->repository->Add($reservation); $insertStartReminder = new AddReservationReminderCommand($seriesId, $minutesPriorStart, ReservationReminderType::Start); $insertEndReminder = new AddReservationReminderCommand($seriesId, $minutesPriorEnd, ReservationReminderType::End); $this->assertTrue($this->db->ContainsCommand($insertStartReminder)); $this->assertTrue($this->db->ContainsCommand($insertEndReminder)); }