Finished validation tests for create ticket
This commit is contained in:
parent
bc9bb698c5
commit
d476f86c8c
@ -20,10 +20,15 @@ class TicketCreator {
|
||||
* @var $banRetriever BanRetriever
|
||||
*/
|
||||
private $banRetriever;
|
||||
/**
|
||||
* @var $ticketValidators TicketValidators
|
||||
*/
|
||||
private $ticketValidators;
|
||||
|
||||
function __construct($categoryRetriever, $banRetriever) {
|
||||
function __construct($categoryRetriever, $banRetriever, $ticketValidators) {
|
||||
$this->categoryRetriever = $categoryRetriever;
|
||||
$this->banRetriever = $banRetriever;
|
||||
$this->ticketValidators = $ticketValidators;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,18 +118,22 @@ class TicketCreator {
|
||||
}
|
||||
}
|
||||
break;
|
||||
/*case 'email':
|
||||
if (!hesk_validateEmail($custom_field_value, $value['value']['multiple'], false)) {
|
||||
$validationModel->errorKeys[] = 'CUSTOM_FIELD_' . $key . '_INVALID::INVALID_OR_MISSING_EMAIL';
|
||||
case CustomField::EMAIL:
|
||||
if (!Validators::validateEmail($custom_field_value, $value['value']['multiple'], false)) {
|
||||
$validationModel->errorKeys[] = "CUSTOM_FIELD_{$customFieldNumber}_INVALID::INVALID_EMAIL";
|
||||
}
|
||||
break;*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*if ($banRetriever->isEmailBanned($ticketRequest->email, $heskSettings)) {
|
||||
if ($this->banRetriever->isEmailBanned($ticketRequest->email, $heskSettings)) {
|
||||
$validationModel->errorKeys[] = 'EMAIL_BANNED';
|
||||
}*/
|
||||
}
|
||||
|
||||
if ($this->ticketValidators->isCustomerAtMaxTickets($ticketRequest->email, $heskSettings)) {
|
||||
$validationModel->errorKeys[] = 'EMAIL_AT_MAX_OPEN_TICKETS';
|
||||
}
|
||||
|
||||
// TODO Check if we're at the max number of tickets
|
||||
// TODO submit_ticket.php:325-334
|
||||
|
@ -34,6 +34,11 @@ class TicketCreatorTest extends TestCase {
|
||||
*/
|
||||
private $categoryRetriever;
|
||||
|
||||
/**
|
||||
* @var $ticketValidators \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $ticketValidators;
|
||||
|
||||
/**
|
||||
* @var $ticketRequest CreateTicketByCustomerModel
|
||||
*/
|
||||
@ -50,7 +55,8 @@ class TicketCreatorTest extends TestCase {
|
||||
function setUp() {
|
||||
$this->banRetriever = $this->createMock(BanRetriever::class);
|
||||
$this->categoryRetriever = $this->createMock(CategoryRetriever::class);
|
||||
$this->ticketCreator = new TicketCreator($this->categoryRetriever, $this->banRetriever);
|
||||
$this->ticketValidators = $this->createMock(TicketValidators::class);
|
||||
$this->ticketCreator = new TicketCreator($this->categoryRetriever, $this->banRetriever, $this->ticketValidators);
|
||||
$this->userContext = new UserContext();
|
||||
|
||||
$this->ticketRequest = new CreateTicketByCustomerModel();
|
||||
@ -519,4 +525,82 @@ class TicketCreatorTest extends TestCase {
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
|
||||
function testItAddsTheProperValidationErrorWhenTheCustomerSubmitsTicketWithEmailThatIsInvalid() {
|
||||
//-- Arrange
|
||||
$customField = array();
|
||||
$customField['req'] = 1;
|
||||
$customField['type'] = CustomField::EMAIL;
|
||||
$customField['use'] = 1;
|
||||
$customField['category'] = array();
|
||||
$customField['value'] = array(
|
||||
'multiple' => 0
|
||||
);
|
||||
$this->heskSettings['custom_fields']['custom1'] = $customField;
|
||||
$this->ticketRequest->customFields[1] = 'invalid@';
|
||||
|
||||
//-- Act
|
||||
$exceptionThrown = false;
|
||||
try {
|
||||
$this->ticketCreator->createTicketByCustomer($this->ticketRequest,
|
||||
$this->heskSettings,
|
||||
$this->modsForHeskSettings,
|
||||
$this->userContext);
|
||||
} catch (ValidationException $e) {
|
||||
//-- Assert (1/2)
|
||||
$exceptionThrown = true;
|
||||
$this->assertArraySubset(['CUSTOM_FIELD_1_INVALID::INVALID_EMAIL'], $e->validationModel->errorKeys);
|
||||
}
|
||||
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
|
||||
function testItAddsTheProperValidationErrorWhenTheCustomerSubmitsTicketWithABannedEmail() {
|
||||
//-- Arrange
|
||||
$this->ticketRequest->email = 'some@banned.email';
|
||||
$this->banRetriever->method('isEmailBanned')
|
||||
->with($this->ticketRequest->email, $this->heskSettings)
|
||||
->willReturn(true);
|
||||
|
||||
//-- Act
|
||||
$exceptionThrown = false;
|
||||
try {
|
||||
$this->ticketCreator->createTicketByCustomer($this->ticketRequest,
|
||||
$this->heskSettings,
|
||||
$this->modsForHeskSettings,
|
||||
$this->userContext);
|
||||
} catch (ValidationException $e) {
|
||||
//-- Assert (1/2)
|
||||
$exceptionThrown = true;
|
||||
$this->assertArraySubset(['EMAIL_BANNED'], $e->validationModel->errorKeys);
|
||||
}
|
||||
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
|
||||
function testItAddsTheProperValidationErrorWhenTheCustomerSubmitsTicketWhenTheyAreMaxedOut() {
|
||||
//-- Arrange
|
||||
$this->ticketRequest->email = 'some@maxedout.email';
|
||||
$this->ticketValidators->method('isCustomerAtMaxTickets')
|
||||
->with($this->ticketRequest->email, $this->heskSettings)
|
||||
->willReturn(true);
|
||||
|
||||
//-- Act
|
||||
$exceptionThrown = false;
|
||||
try {
|
||||
$this->ticketCreator->createTicketByCustomer($this->ticketRequest,
|
||||
$this->heskSettings,
|
||||
$this->modsForHeskSettings,
|
||||
$this->userContext);
|
||||
} catch (ValidationException $e) {
|
||||
//-- Assert (1/2)
|
||||
$exceptionThrown = true;
|
||||
$this->assertArraySubset(['EMAIL_AT_MAX_OPEN_TICKETS'], $e->validationModel->errorKeys);
|
||||
}
|
||||
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user