First steps in supporting email validation
parent
08d7347f00
commit
c1638aeb98
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: cokoch
|
||||
* Date: 2/20/2017
|
||||
* Time: 12:40 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Tickets;
|
||||
|
||||
|
||||
use DataAccess\Tickets\VerifiedEmailGateway;
|
||||
|
||||
class VerifiedEmailChecker {
|
||||
/**
|
||||
* @var $verifiedEmailGateway VerifiedEmailGateway
|
||||
*/
|
||||
private $verifiedEmailGateway;
|
||||
|
||||
function __construct($verifiedEmailGateway) {
|
||||
$this->verifiedEmailGateway = $verifiedEmailGateway;
|
||||
}
|
||||
|
||||
function isEmailVerified($emailAddress, $heskSettings) {
|
||||
return $this->verifiedEmailGateway->isEmailVerified($emailAddress, $heskSettings);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace DataAccess\Tickets;
|
||||
|
||||
|
||||
use DataAccess\CommonDao;
|
||||
|
||||
class VerifiedEmailGateway extends CommonDao {
|
||||
function isEmailVerified($emailAddress, $heskSettings) {
|
||||
$this->init();
|
||||
|
||||
$rs = hesk_dbQuery("SELECT 1 FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "verified_emails` WHERE `Email` = '" . hesk_dbEscape($emailAddress) . "'");
|
||||
|
||||
return hesk_dbNumRows($rs) > 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace BusinessLogic\Tickets;
|
||||
|
||||
|
||||
use DataAccess\Tickets\VerifiedEmailGateway;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class VerifiedEmailCheckerTest extends TestCase {
|
||||
/**
|
||||
* @var $verifiedEmailGateway \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $verifiedEmailGateway;
|
||||
|
||||
/**
|
||||
* @var $verifiedEmailChecker VerifiedEmailChecker
|
||||
*/
|
||||
private $verifiedEmailChecker;
|
||||
|
||||
/**
|
||||
* @var $heskSettings array
|
||||
*/
|
||||
private $heskSettings;
|
||||
|
||||
protected function setUp() {
|
||||
$this->verifiedEmailGateway = $this->createMock(VerifiedEmailGateway::class);
|
||||
$this->heskSettings = array();
|
||||
$this->verifiedEmailChecker = new VerifiedEmailChecker($this->verifiedEmailGateway);
|
||||
}
|
||||
|
||||
function testItGetsTheValidationStateFromTheGatewayWhenItItTrue() {
|
||||
//-- Arrange
|
||||
$this->verifiedEmailGateway->method('isEmailVerified')
|
||||
->with('some email', $this->heskSettings)
|
||||
->willReturn(true);
|
||||
|
||||
//-- Act
|
||||
$actual = $this->verifiedEmailChecker->isEmailVerified('some email', $this->heskSettings);
|
||||
|
||||
//-- Assert
|
||||
self::assertThat($actual, self::isTrue());
|
||||
}
|
||||
|
||||
function testItGetsTheValidationStateFromTheGatewayWhenItItFalse() {
|
||||
//-- Arrange
|
||||
$this->verifiedEmailGateway->method('isEmailVerified')
|
||||
->with('some email', $this->heskSettings)
|
||||
->willReturn(false);
|
||||
|
||||
//-- Act
|
||||
$actual = $this->verifiedEmailChecker->isEmailVerified('some email', $this->heskSettings);
|
||||
|
||||
//-- Assert
|
||||
self::assertThat($actual, self::isFalse());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue