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 testNoConflictsIfReservationExistsAtSameTimeForDifferentResource()
 {
     $resourceId1 = 1;
     $resourceId2 = 2;
     $resourceId3 = 3;
     $currentId = 19;
     $currentDate = new DateRange(Date::Now()->AddDays(10), Date::Now()->AddDays(15));
     $current = new TestReservation('ref', $currentDate);
     $current->SetReservationId($currentId);
     $series = new ExistingReservationSeries();
     $series->WithPrimaryResource(new FakeBookableResource($resourceId1));
     $series->WithResource(new FakeBookableResource($resourceId2));
     $series->WithCurrentInstance($current);
     $reservations = array(new TestReservationItemView($currentId + 1, Date::Now(), Date::Now(), $resourceId3));
     $this->strategy->expects($this->once())->method('GetItemsBetween')->with($this->anything(), $this->anything())->will($this->returnValue($reservations));
     $rule = new ExistingResourceAvailabilityRule($this->strategy, $this->timezone);
     $ruleResult = $rule->Validate($series);
     $this->assertTrue($ruleResult->IsValid());
 }
 public function testChangesInviteesForAllInstances()
 {
     $instanceId1 = 100;
     $reservation1 = new TestReservation(null, null, $instanceId1);
     $reservation1->WithInvitees(array(1, 2, 3));
     $instanceId2 = 101;
     $reservation2 = new TestReservation(null, null, $instanceId2);
     $reservation2->WithInvitees(array(2, 3));
     $builder = new ExistingReservationSeriesBuilder();
     $builder->WithInstance($reservation1);
     $builder->WithInstance($reservation2);
     $series = $builder->BuildTestVersion();
     $series->ChangeInvitees(array(3, 4));
     $this->repository->Update($series);
     $this->assertTrue($this->db->ContainsCommand($this->GetRemoveUserCommand($instanceId1, 1)));
     $this->assertTrue($this->db->ContainsCommand($this->GetRemoveUserCommand($instanceId1, 2)));
     $this->assertTrue($this->db->ContainsCommand($this->GetAddUserCommand($instanceId1, 4, ReservationUserLevel::INVITEE)));
     $this->assertTrue($this->db->ContainsCommand($this->GetRemoveUserCommand($instanceId2, 2)));
     $this->assertTrue($this->db->ContainsCommand($this->GetAddUserCommand($instanceId2, 4, ReservationUserLevel::INVITEE)));
 }
 public function testWhenUserJoinsAllAndThereIsNotSpace()
 {
     $invitationAction = InvitationAction::JoinAll;
     $currentUserId = 1029;
     $referenceNumber = 'abc123';
     $builder = new ExistingReservationSeriesBuilder();
     $instance = new TestReservation();
     $instance->WithParticipants(array(1));
     $instance->WithInvitee($currentUserId);
     $resource = new FakeBookableResource(1);
     $resource->SetMaxParticipants(1);
     $builder->WithCurrentInstance($instance)->WithPrimaryResource($resource);
     $series = $builder->Build();
     $this->page->expects($this->once())->method('GetResponseType')->will($this->returnValue('json'));
     $this->page->expects($this->once())->method('GetInvitationAction')->will($this->returnValue($invitationAction));
     $this->page->expects($this->once())->method('GetInvitationReferenceNumber')->will($this->returnValue($referenceNumber));
     $this->page->expects($this->once())->method('GetUserId')->will($this->returnValue($currentUserId));
     $this->reservationRepo->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($series));
     $this->page->expects($this->once())->method('DisplayResult')->with($this->stringContains('ParticipationNotAllowed'));
     $this->presenter->PageLoad();
 }
 public function testDeletesWholeSeriesWhenAdminRegardlessOfDate()
 {
     $r1 = new TestReservation();
     $r1->SetReservationDate(TestDateRange::CreateWithDays(-1));
     $r2 = new TestReservation();
     $r2->SetReservationDate(TestDateRange::CreateWithDays(-2));
     $builder = new ExistingReservationSeriesBuilder();
     $builder->WithCurrentInstance($r1);
     $builder->WithInstance($r2);
     $series = $builder->Build();
     $series->ApplyChangesTo(SeriesUpdateScope::FullSeries);
     $series->Delete($this->admin);
     $events = $series->GetEvents();
     $this->assertEquals(1, count($events));
     $this->assertTrue(in_array(new SeriesDeletedEvent($series), $events));
 }
 public function testRemovesParticipationFromAllInstances()
 {
     $userId = 1;
     $r1 = new TestReservation();
     $r1->WithParticipant($userId);
     $r1->SetReservationId(100);
     $r2 = new TestReservation();
     $r2->WithParticipant($userId);
     $r2->SetReservationId(101);
     $r3 = new TestReservation();
     $r3->WithParticipant(89);
     $r3->SetReservationId(102);
     $builder = new ExistingReservationSeriesBuilder();
     $builder->WithInstance($r1);
     $builder->WithInstance($r2);
     $builder->WithInstance($r3);
     $series = $builder->Build();
     $series->CancelAllParticipation($userId);
     $events = $series->GetEvents();
     $this->assertContains($userId, $r1->RemovedParticipants());
     $this->assertContains($userId, $r2->RemovedParticipants());
     $this->assertEmpty($r3->RemovedInvitees());
     $this->assertTrue(in_array(new InstanceUpdatedEvent($r1, $series), $events));
     $this->assertTrue(in_array(new InstanceUpdatedEvent($r2, $series), $events));
     $this->assertFalse(in_array(new InstanceUpdatedEvent($r3, $series), $events));
 }