service = new Service(); } public function testGetDi(): void { $di = $this->getDi(); $this->service->setDi($di); $getDi = $this->service->getDi(); $this->assertEquals($di, $getDi); } public function testOnBeforeClientSignUp(): void { $spamCheckerService = $this->createMock(Service::class); $spamCheckerService->expects($this->atLeastOnce()) ->method('isBlockedIp'); $spamCheckerService->expects($this->atLeastOnce()) ->method('isSpam'); $di = $this->getDi(); $di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $spamCheckerService); $boxEventMock = $this->getMockBuilder('\Box_Event')->disableOriginalConstructor() ->getMock(); $boxEventMock->expects($this->atLeastOnce()) ->method('getDi') ->willReturn($di); $this->service->onBeforeClientSignUp($boxEventMock); } public function testOnBeforeGuestPublicTicketOpen(): void { $spamCheckerService = $this->createMock(Service::class); $spamCheckerService->expects($this->atLeastOnce()) ->method('isBlockedIp'); $spamCheckerService->expects($this->atLeastOnce()) ->method('isSpam'); $di = $this->getDi(); $di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $spamCheckerService); $boxEventMock = $this->getMockBuilder('\Box_Event')->disableOriginalConstructor() ->getMock(); $boxEventMock->expects($this->atLeastOnce()) ->method('getDi') ->willReturn($di); $this->service->onBeforeGuestPublicTicketOpen($boxEventMock); } public function testIsBlockedIpIpNotBlocked(): void { $clientIp = '214.1.4.99'; $modConfig = [ 'block_ips' => true, 'blocked_ips' => '1.1.1.1' . PHP_EOL . '2.2.2.2', ]; $di = $this->getDi(); $di['request'] = Request::createFromGlobals(); $di['mod_config'] = $di->protect(function ($modName) use ($modConfig) { if ($modName == 'Spamchecker') { return $modConfig; } }); $boxEventMock = $this->getMockBuilder('\Box_Event')->disableOriginalConstructor() ->getMock(); $boxEventMock->expects($this->atLeastOnce()) ->method('getDi') ->willReturn($di); $this->service->isBlockedIp($boxEventMock); } public function testIsBlockedIpBlockIpsNotEnabled(): void { $modConfig = [ 'block_ips' => false, ]; $di = $this->getDi(); $di['mod_config'] = $di->protect(function ($modName) use ($modConfig) { if ($modName == 'Spamchecker') { return $modConfig; } }); $boxEventMock = $this->getMockBuilder('\Box_Event')->disableOriginalConstructor() ->getMock(); $boxEventMock->expects($this->atLeastOnce()) ->method('getDi') ->willReturn($di); $this->service->isBlockedIp($boxEventMock); } public function dataProviderSpamResponses(): array { return [ [ '{"success" : "true", "username" : {"appears" : "true" }}', 'Your username is blacklisted in the Stop Forum Spam database', ], [ '{"success" : "true", "email" : {"appears" : "true" }}', 'Your e-mail is blacklisted in the Stop Forum Spam database', ], [ '{"success" : "true", "ip" : {"appears" : "true" }}', 'Your IP address is blacklisted in the Stop Forum Spam database', ], ]; } }