Move ban test, work on TicketValidators test
parent
bbdb03d103
commit
176b786279
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: mkoch
|
||||||
|
* Date: 2/2/2017
|
||||||
|
* Time: 9:57 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
|
|
||||||
|
use BusinessLogic\Security\BannedEmail;
|
||||||
|
use BusinessLogic\Security\BannedIp;
|
||||||
|
use BusinessLogic\Security\BanRetriever;
|
||||||
|
use DataAccess\Security\BanGateway;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
|
||||||
|
class BanRetrieverTests extends TestCase {
|
||||||
|
/**
|
||||||
|
* @var $banGateway \PHPUnit_Framework_MockObject_MockObject;
|
||||||
|
*/
|
||||||
|
private $banGateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $banRetriever BanRetriever;
|
||||||
|
*/
|
||||||
|
private $banRetriever;
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
$this->banGateway = $this->createMock(BanGateway::class);
|
||||||
|
$this->banRetriever = new BanRetriever($this->banGateway);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItReturnsTrueWhenTheEmailIsBanned() {
|
||||||
|
//-- Arrange
|
||||||
|
$bannedEmail = new BannedEmail();
|
||||||
|
$bannedEmail->email = 'my@email.address';
|
||||||
|
$this->banGateway->method('getEmailBans')
|
||||||
|
->willReturn([$bannedEmail]);
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->banRetriever->isEmailBanned('my@email.address', null);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
$this->assertThat($result, $this->isTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItReturnsFalseWhenTheEmailIsNotBanned() {
|
||||||
|
//-- Arrange
|
||||||
|
$bannedEmail = new BannedEmail();
|
||||||
|
$bannedEmail->email = 'my@other.address';
|
||||||
|
$this->banGateway->method('getEmailBans')
|
||||||
|
->willReturn([$bannedEmail]);
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->banRetriever->isEmailBanned('my@email.address', null);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
$this->assertThat($result, $this->isFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItReturnsTrueWhenTheIpIsBanned() {
|
||||||
|
//-- Arrange
|
||||||
|
$bannedIp = new BannedIp();
|
||||||
|
$bannedIp->ipFrom = ip2long('1.0.0.0');
|
||||||
|
$bannedIp->ipTo = ip2long('1.0.0.5');
|
||||||
|
$this->banGateway->method('getIpBans')
|
||||||
|
->willReturn([$bannedIp]);
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->banRetriever->isIpAddressBanned(ip2long('1.0.0.3'), null);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
$this->assertThat($result, $this->isTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItReturnsFalseWhenTheIpIsNotBanned() {
|
||||||
|
//-- Arrange
|
||||||
|
$bannedIp = new BannedIp();
|
||||||
|
$bannedIp->ipFrom = ip2long('1.0.0.0');
|
||||||
|
$bannedIp->ipTo = ip2long('1.0.0.5');
|
||||||
|
$this->banGateway->method('getIpBans')
|
||||||
|
->willReturn([$bannedIp]);
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->banRetriever->isIpAddressBanned(ip2long('2.0.0.3'), null);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
$this->assertThat($result, $this->isFalse());
|
||||||
|
}
|
||||||
|
}
|
@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: mkoch
|
|
||||||
* Date: 2/2/2017
|
|
||||||
* Time: 9:57 PM
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Tests;
|
|
||||||
|
|
||||||
|
|
||||||
use BusinessLogic\Security\BannedEmail;
|
|
||||||
use BusinessLogic\Security\BanRetriever;
|
|
||||||
use DataAccess\Security\BanGateway;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
|
|
||||||
class BanRetrieverTests extends TestCase {
|
|
||||||
function testItReturnsTrueWhenTheIpIsBanned() {
|
|
||||||
//-- Arrange
|
|
||||||
$banGateway = $this->createMock(BanGateway::class);
|
|
||||||
$banRetriever = new BanRetriever($banGateway);
|
|
||||||
$bannedEmail = new BannedEmail();
|
|
||||||
$bannedEmail->email = 'my@email.address';
|
|
||||||
$banGateway->method('getEmailBans')
|
|
||||||
->willReturn([$bannedEmail]);
|
|
||||||
|
|
||||||
//-- Act
|
|
||||||
$result = $banRetriever->isEmailBanned('my@email.address', null);
|
|
||||||
|
|
||||||
//-- Assert
|
|
||||||
$this->assertThat($result, $this->isTrue());
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Tickets;
|
||||||
|
|
||||||
|
|
||||||
|
use DataAccess\Tickets\TicketGateway;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class TicketValidatorsTest extends TestCase {
|
||||||
|
/**
|
||||||
|
* @var $ticketGateway \PHPUnit_Framework_MockObject_MockObject
|
||||||
|
*/
|
||||||
|
private $ticketGateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $ticketValidator TicketValidators
|
||||||
|
*/
|
||||||
|
private $ticketValidator;
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
$this->ticketGateway = $this->createMock(TicketGateway::class);
|
||||||
|
$this->ticketValidator = new TicketValidators($this->ticketGateway);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItReturnsTrueWhenTheUserIsMaxedOutOnOpenTickets() {
|
||||||
|
//-- Arrange
|
||||||
|
$tickets = [new Ticket(), new Ticket(), new Ticket()];
|
||||||
|
$this->ticketGateway->method('getTicketsByEmail')
|
||||||
|
->with('my@email.com')
|
||||||
|
->willReturn($tickets);
|
||||||
|
$heskSettings = array(
|
||||||
|
'max_open' => 3
|
||||||
|
);
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->ticketValidator->isCustomerAtMaxTickets('my@email.com', $heskSettings);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
$this->assertThat($result, $this->isTrue(), str_replace('test','',__FUNCTION__));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItReturnsFalseWhenTheUserIsNotMaxedOutOnOpenTickets() {
|
||||||
|
//-- Arrange
|
||||||
|
$tickets = [new Ticket(), new Ticket(), new Ticket()];
|
||||||
|
$this->ticketGateway->method('getTicketsByEmail')
|
||||||
|
->with('my@email.com')
|
||||||
|
->willReturn($tickets);
|
||||||
|
$heskSettings = array(
|
||||||
|
'max_open' => 10
|
||||||
|
);
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->ticketValidator->isCustomerAtMaxTickets('my@email.com', $heskSettings);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
$this->assertThat($result, $this->isFalse(), str_replace('test','',__FUNCTION__));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItReturnsFalseWhenMaxOpenIsZero() {
|
||||||
|
//-- Arrange
|
||||||
|
$tickets = [new Ticket(), new Ticket(), new Ticket()];
|
||||||
|
$this->ticketGateway->method('getTicketsByEmail')
|
||||||
|
->with('my@email.com')
|
||||||
|
->willReturn($tickets);
|
||||||
|
$heskSettings = array(
|
||||||
|
'max_open' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->ticketValidator->isCustomerAtMaxTickets('my@email.com', $heskSettings);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
$this->assertThat($result, $this->isFalse(), str_replace('test','',__FUNCTION__));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue