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 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 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));
 }