public function testSendsReservationUpdatedRequiresApprovalEmailIfAdminWantsIt() { $ownerId = 100; $resourceId = 200; $resource = new FakeBookableResource($resourceId, 'name'); $reservation = new ExistingReservationSeries(); $reservation->WithOwner($ownerId); $reservation->WithPrimaryResource($resource); $reservation->SetStatusId(ReservationStatus::Pending); $owner = new FakeUser($ownerId); $admin1 = new UserDto(1, 'f', 'l', 'e'); $admin2 = new UserDto(2, 'f', 'l', 'e'); $admin3 = new UserDto(3, 'f', 'l', 'e'); $admin4 = new UserDto(4, 'f', 'l', 'e'); $admin5 = new UserDto(5, 'f', 'l', 'e'); $admin6 = new UserDto(6, 'f', 'l', 'e'); $resourceAdmins = array($admin1, $admin2, $admin3); $appAdmins = array($admin3, $admin4, $admin1); $groupAdmins = array($admin5, $admin6, $admin2); $attributeRepo = $this->getMock('IAttributeRepository'); $userRepo = $this->getMock('IUserRepository'); $userRepo->expects($this->once())->method('LoadById')->with($this->equalTo($ownerId))->will($this->returnValue($owner)); $userRepo->expects($this->once())->method('GetResourceAdmins')->with($this->equalTo($resourceId))->will($this->returnValue($resourceAdmins)); $userRepo->expects($this->once())->method('GetApplicationAdmins')->will($this->returnValue($appAdmins)); $userRepo->expects($this->once())->method('GetGroupAdmins')->with($this->equalTo($ownerId))->will($this->returnValue($groupAdmins)); $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); $expectedMessage1 = new ReservationRequiresApprovalEmailAdmin($admin1, $owner, $reservation, $resource, $attributeRepo); $expectedMessage2 = new ReservationRequiresApprovalEmailAdmin($admin2, $owner, $reservation, $resource, $attributeRepo); $this->assertEquals(6, count($this->fakeEmailService->_Messages), "send one per person, no duplicates"); $this->isInstanceOf('ReservationRequiresApprovalEmailAdmin', $this->fakeEmailService->_Messages[0]); $this->isInstanceOf('ReservationRequiresApprovalEmailAdmin', $this->fakeEmailService->_Messages[1]); }