public function testSendsReservationDeletedEmails() { $ownerId = 828; $owner = new User(); $participantId1 = 50; $participant1 = new User(); $participantId2 = 60; $participant2 = new User(); $instance1 = new TestReservation(); $instance1->WithAddedParticipants(array(1000, 2000)); $instance1->WithExistingParticipants(array($participantId1, $participantId2)); $series = new TestReservationSeries(); $series->WithOwnerId($ownerId); $series->WithCurrentInstance($instance1); $userRepo = $this->getMock('IUserRepository'); $attributeRepo = $this->getMock('IAttributeRepository'); $userRepo->expects($this->at(0))->method('LoadById')->with($this->equalTo($ownerId))->will($this->returnValue($owner)); $userRepo->expects($this->at(1))->method('LoadById')->with($this->equalTo($participantId1))->will($this->returnValue($participant1)); $userRepo->expects($this->at(2))->method('LoadById')->with($this->equalTo($participantId2))->will($this->returnValue($participant2)); $notification = new ParticipantDeletedEmailNotification($userRepo, $attributeRepo); $notification->Notify($series); $this->assertEquals(2, count($this->fakeEmailService->_Messages)); $lastExpectedMessage = new ParticipantAddedEmail($owner, $participant2, $series, $attributeRepo); $this->assertInstanceOf('ParticipantDeletedEmail', $this->fakeEmailService->_LastMessage); // $this->assertEquals($lastExpectedMessage, $this->fakeEmailService->_LastMessage); }
public function testWhenEnabledAnInvalidInterval() { $series = new TestReservationSeries(); $series->AddEndReminder(new ReservationReminder('abc', ReservationReminderInterval::Days)); $rule = new ReminderValidationRule(); $result = $rule->Validate($series); $this->assertFalse($result->IsValid()); }
public function testRuleIsInvalidIfExtensionIsNotInList() { $this->fakeConfig->SetSectionKey(ConfigSection::UPLOADS, ConfigKeys::UPLOAD_RESERVATION_EXTENSIONS, '.pdf'); $attachment = new FakeReservationAttachment(); $attachment->SetExtension('doc'); $this->series->AddAttachment($attachment); $result = $this->validator->Validate($this->series); $this->assertFalse($result->IsValid()); }
public function testEnsuresThatStartMustBeBeforeEnd() { $start = Date::Parse('2010-01-01'); $reservationDate = new DateRange($start, $start->AddDays(-1)); $reservationSeries = new TestReservationSeries(); $reservationSeries->WithDuration($reservationDate); $rule = new ReservationDateTimeRule(); $result = $rule->Validate($reservationSeries); $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 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 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 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 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 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 testIfUserIsAdminForReservationUserReturnTrue() { $this->fakeUser->IsAdmin = false; $this->fakeUser->IsGroupAdmin = true; $adminUser = $this->getMock('User'); $reservationUser = $this->getMock('User'); $this->userRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($this->fakeUser->UserId))->will($this->returnValue($adminUser)); $this->userRepository->expects($this->at(1))->method('LoadById')->with($this->equalTo($this->reservationSeries->UserId()))->will($this->returnValue($reservationUser)); $adminUser->expects($this->once())->method('IsAdminFor')->with($this->equalTo($reservationUser))->will($this->returnValue(true)); $result = $this->rule->Validate($this->reservationSeries); $this->assertTrue($result->IsValid()); }
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 testWhenAllAttributesAreValid() { $reservation = new TestReservationSeries(); $reservation->WithAttributeValue(new AttributeValue(1, null)); $reservation->WithAttributeValue(new AttributeValue(2, null)); $reservation->WithAttributeValue(new AttributeValue(3, null)); $attributeService = $this->getMock('IAttributeService'); $validationResult = new AttributeServiceValidationResult(true, array()); $attributeService->expects($this->once())->method('Validate')->with($this->equalTo(CustomAttributeCategory::RESERVATION), $this->equalTo($reservation->AttributeValues()))->will($this->returnValue($validationResult)); $rule = new CustomAttributeValidationRule($attributeService); $result = $rule->Validate($reservation); $this->assertEquals(true, $result->IsValid()); }
public function testHandlingReservationCreationDelegatesToHandler() { $series = new TestReservationSeries(); $instance = new Reservation($series, NullDateRange::Instance()); $series->WithCurrentInstance($instance); $this->handler->expects($this->once())->method('Handle')->with($this->equalTo($series), $this->isInstanceOf('FakeReservationSavePage'))->will($this->returnValue(true)); $this->presenter->HandleReservation($series); $this->assertEquals($instance->ReferenceNumber(), $this->page->referenceNumber); $this->assertEquals($series->RequiresApproval(), $this->page->requiresApproval); }
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 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)); }
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 testWhenNotConstrainedByTime() { $this->fakeConfig->SetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_START_TIME_CONSTRAINT, ReservationStartTimeConstraint::NONE); $now = Date::Parse('2011-04-04 12:13:15', 'UTC'); Date::_SetNow($now); $start = Date::Parse('2011-04-04 12:13:14', 'UTC'); $end = $start->AddDays(5); $reservation = new TestReservationSeries(); $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end))); $rule = new ReservationStartTimeRule($this->scheduleRepository); $result = $rule->Validate($reservation); $this->assertTrue($result->IsValid()); }
public function testUnlimitedQuantity() { $accessory1 = new ReservationAccessory(1, 5); $quantityAvailable = null; $startDate = Date::Parse('2010-04-04', 'UTC'); $endDate = Date::Parse('2010-04-05', 'UTC'); $reservation = new TestReservationSeries(); $reservation->WithAccessory($accessory1); $dr1 = new DateRange($startDate, $endDate); $reservation->WithDuration($dr1); $this->accessoryRepository->expects($this->at(0))->method('LoadById')->with($accessory1->AccessoryId)->will($this->returnValue(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable))); $result = $this->rule->Validate($reservation); $this->assertTrue($result->IsValid()); }