mailer = $this->createMock(IMailer::class); $this->userManager = $this->createMock(IUserManager::class); $this->l10nFactory = $this->createMock(IFactory::class); $this->l10n = $this->createMock(IL10N::class); $this->logger = $this->createMock(LoggerInterface::class); $this->l10nFactory->method('get')->with('core')->willReturn($this->l10n); $this->l10n->method('t')->willReturnArgument(0); $this->listener = new RemoteWipeEmailListener( $this->mailer, $this->userManager, $this->l10nFactory, $this->logger ); } public function testHandleUnrelated(): void { $event = new Event(); $this->mailer->expects($this->never())->method('send'); $this->listener->handle($event); } public function testHandleRemoteWipeStartedInvalidUser(): void { /** @var IToken|MockObject $token */ $token = $this->createMock(IToken::class); $event = new RemoteWipeStarted($token); $token->method('getUID')->willReturn('nope'); $this->userManager->expects($this->once()) ->method('get') ->with('nope') ->willReturn(null); $this->mailer->expects($this->never())->method('send'); $this->listener->handle($event); } public function testHandleRemoteWipeStartedNoEmailSet(): void { /** @var IToken|MockObject $token */ $token = $this->createMock(IToken::class); $event = new RemoteWipeStarted($token); $token->method('getUID')->willReturn('nope'); $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') ->with('nope') ->willReturn($user); $user->method('getEMailAddress')->willReturn(null); $this->mailer->expects($this->never())->method('send'); $this->listener->handle($event); } public function testHandleRemoteWipeStartedTransmissionError(): void { /** @var IToken|MockObject $token */ $token = $this->createMock(IToken::class); $event = new RemoteWipeStarted($token); $token->method('getUID')->willReturn('nope'); $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') ->with('nope') ->willReturn($user); $user->method('getEMailAddress')->willReturn('user@domain.org'); $this->mailer->expects($this->once()) ->method('send') ->willThrowException(new Exception()); $this->logger->expects($this->once()) ->method('error'); $this->listener->handle($event); } public function testHandleRemoteWipeStarted(): void { /** @var IToken|MockObject $token */ $token = $this->createMock(IToken::class); $event = new RemoteWipeStarted($token); $token->method('getUID')->willReturn('nope'); $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') ->with('nope') ->willReturn($user); $user->method('getEMailAddress')->willReturn('user@domain.org'); $message = $this->createMock(IMessage::class); $this->mailer->expects($this->once()) ->method('createMessage') ->willReturn($message); $message->expects($this->once()) ->method('setTo') ->with($this->equalTo(['user@domain.org'])); $this->mailer->expects($this->once()) ->method('send') ->with($message); $this->listener->handle($event); } public function testHandleRemoteWipeFinishedInvalidUser(): void { /** @var IToken|MockObject $token */ $token = $this->createMock(IToken::class); $event = new RemoteWipeFinished($token); $token->method('getUID')->willReturn('nope'); $this->userManager->expects($this->once()) ->method('get') ->with('nope') ->willReturn(null); $this->mailer->expects($this->never())->method('send'); $this->listener->handle($event); } public function testHandleRemoteWipeFinishedNoEmailSet(): void { /** @var IToken|MockObject $token */ $token = $this->createMock(IToken::class); $event = new RemoteWipeFinished($token); $token->method('getUID')->willReturn('nope'); $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') ->with('nope') ->willReturn($user); $user->method('getEMailAddress')->willReturn(null); $this->mailer->expects($this->never())->method('send'); $this->listener->handle($event); } public function testHandleRemoteWipeFinishedTransmissionError(): void { /** @var IToken|MockObject $token */ $token = $this->createMock(IToken::class); $event = new RemoteWipeFinished($token); $token->method('getUID')->willReturn('nope'); $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') ->with('nope') ->willReturn($user); $user->method('getEMailAddress')->willReturn('user@domain.org'); $this->mailer->expects($this->once()) ->method('send') ->willThrowException(new Exception()); $this->logger->expects($this->once()) ->method('error'); $this->listener->handle($event); } public function testHandleRemoteWipeFinished(): void { /** @var IToken|MockObject $token */ $token = $this->createMock(IToken::class); $event = new RemoteWipeFinished($token); $token->method('getUID')->willReturn('nope'); $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') ->with('nope') ->willReturn($user); $user->method('getEMailAddress')->willReturn('user@domain.org'); $message = $this->createMock(IMessage::class); $this->mailer->expects($this->once()) ->method('createMessage') ->willReturn($message); $message->expects($this->once()) ->method('setTo') ->with($this->equalTo(['user@domain.org'])); $this->mailer->expects($this->once()) ->method('send') ->with($message); $this->listener->handle($event); } }