More tests for TicketCreator. Need to refactor some custom field logic
This commit is contained in:
parent
b76e2afac1
commit
e22d318b92
@ -73,7 +73,7 @@ class TicketCreator {
|
||||
}
|
||||
|
||||
// Don't allow critical priority tickets
|
||||
/*if ($heskSettings['cust_urgency'] && intval($ticketRequest->priority) === $TICKET_PRIORITY_CRITICAL) {
|
||||
if ($heskSettings['cust_urgency'] && intval($ticketRequest->priority) === $TICKET_PRIORITY_CRITICAL) {
|
||||
$validationModel->errorKeys[] = 'CRITICAL_PRIORITY_FORBIDDEN';
|
||||
}
|
||||
|
||||
@ -88,13 +88,14 @@ class TicketCreator {
|
||||
}
|
||||
|
||||
foreach ($heskSettings['custom_fields'] as $key => $value) {
|
||||
if ($value['use'] == 1 && hesk_is_custom_field_in_category($key, intval($ticketRequest->category))) {
|
||||
$custom_field_value = $ticketRequest->customFields[$key];
|
||||
$customFieldNumber = intval(str_replace('custom', '', $key));
|
||||
if ($value['use'] == 1 && hesk_is_custom_field_in_category($customFieldNumber, intval($ticketRequest->category))) {
|
||||
$custom_field_value = $ticketRequest->customFields[$customFieldNumber];
|
||||
if (empty($custom_field_value)) {
|
||||
$validationModel->errorKeys[] = 'CUSTOM_FIELD_' . $key . '_INVALID::NO_VALUE';
|
||||
$validationModel->errorKeys[] = "CUSTOM_FIELD_{$customFieldNumber}_INVALID::NO_VALUE";
|
||||
continue;
|
||||
}
|
||||
switch($value['type']) {
|
||||
/*switch($value['type']) {
|
||||
case 'date':
|
||||
if (!preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $custom_field_value)) {
|
||||
$validationModel->errorKeys[] = 'CUSTOM_FIELD_' . $key . '_INVALID::INVALID_DATE';
|
||||
@ -116,11 +117,11 @@ class TicketCreator {
|
||||
$validationModel->errorKeys[] = 'CUSTOM_FIELD_' . $key . '_INVALID::INVALID_OR_MISSING_EMAIL';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
if ($banRetriever->isEmailBanned($ticketRequest->email, $heskSettings)) {
|
||||
/*if ($banRetriever->isEmailBanned($ticketRequest->email, $heskSettings)) {
|
||||
$validationModel->errorKeys[] = 'EMAIL_BANNED';
|
||||
}*/
|
||||
|
||||
|
11
api/Core/Constants/Priority.php
Normal file
11
api/Core/Constants/Priority.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Core\Constants;
|
||||
|
||||
|
||||
class Priority {
|
||||
const CRITICAL = 0;
|
||||
const HIGH = 1;
|
||||
const MEDIUM = 2;
|
||||
const LOW = 3;
|
||||
}
|
@ -14,6 +14,7 @@ use BusinessLogic\Categories\CategoryRetriever;
|
||||
use BusinessLogic\Exceptions\ValidationException;
|
||||
use BusinessLogic\Security\BanRetriever;
|
||||
use BusinessLogic\Security\UserContext;
|
||||
use Core\Constants\Priority;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TicketCreatorTest extends TestCase {
|
||||
@ -55,8 +56,16 @@ class TicketCreatorTest extends TestCase {
|
||||
$this->ticketRequest->name = 'Name';
|
||||
$this->ticketRequest->email = 'some@e.mail';
|
||||
$this->ticketRequest->category = 1;
|
||||
$this->ticketRequest->priority = Priority::HIGH;
|
||||
$this->ticketRequest->subject = 'Subject';
|
||||
$this->ticketRequest->message = 'Message';
|
||||
$this->ticketRequest->customFields = array();
|
||||
$this->heskSettings = array(
|
||||
'multi_eml' => false
|
||||
'multi_eml' => false,
|
||||
'cust_urgency' => false,
|
||||
'require_subject' => 1,
|
||||
'require_message' => 1,
|
||||
'custom_fields' => array(),
|
||||
);
|
||||
|
||||
$category = new Category();
|
||||
@ -256,4 +265,145 @@ class TicketCreatorTest extends TestCase {
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
|
||||
function testItAddsTheProperValidationErrorWhenTheCustomerSubmitsTicketWithPriorityCritical() {
|
||||
//-- Arrange
|
||||
$this->ticketRequest->priority = Priority::CRITICAL;
|
||||
$this->heskSettings['cust_urgency'] = 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(['CRITICAL_PRIORITY_FORBIDDEN'], $e->validationModel->errorKeys);
|
||||
}
|
||||
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
|
||||
function testItAddsTheProperValidationErrorWhenTheCustomerSubmitsTicketWithNullSubjectAndItIsRequired() {
|
||||
//-- Arrange
|
||||
$this->ticketRequest->subject = null;
|
||||
$this->heskSettings['require_subject'] = 1;
|
||||
|
||||
//-- 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(['SUBJECT_REQUIRED'], $e->validationModel->errorKeys);
|
||||
}
|
||||
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
|
||||
function testItAddsTheProperValidationErrorWhenTheCustomerSubmitsTicketWithBlankSubjectAndItIsRequired() {
|
||||
//-- Arrange
|
||||
$this->ticketRequest->subject = '';
|
||||
$this->heskSettings['require_subject'] = 1;
|
||||
|
||||
//-- 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(['SUBJECT_REQUIRED'], $e->validationModel->errorKeys);
|
||||
}
|
||||
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
|
||||
function testItAddsTheProperValidationErrorWhenTheCustomerSubmitsTicketWithNullMessageAndItIsRequired() {
|
||||
//-- Arrange
|
||||
$this->ticketRequest->message = null;
|
||||
$this->heskSettings['require_message'] = 1;
|
||||
|
||||
//-- 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(['MESSAGE_REQUIRED'], $e->validationModel->errorKeys);
|
||||
}
|
||||
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
|
||||
function testItAddsTheProperValidationErrorWhenTheCustomerSubmitsTicketWithBlankMessageAndItIsRequired() {
|
||||
//-- Arrange
|
||||
$this->ticketRequest->message = '';
|
||||
$this->heskSettings['require_message'] = 1;
|
||||
|
||||
//-- 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(['MESSAGE_REQUIRED'], $e->validationModel->errorKeys);
|
||||
}
|
||||
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
|
||||
function testItAddsTheProperValidationErrorWhenTheCustomerSubmitsTicketWithNullRequiredCustomField() {
|
||||
$this->markTestIncomplete(
|
||||
'Not complete; need to refactor custom field in category'
|
||||
);
|
||||
|
||||
//-- Arrange
|
||||
$customField = array();
|
||||
$customField['req'] = 1;
|
||||
$customField['type'] = 'text';
|
||||
$customField['use'] = 1;
|
||||
$customField['category'] = array();
|
||||
$this->heskSettings['custom_fields']['custom1'] = $customField;
|
||||
$this->ticketRequest->customFields[1] = null;
|
||||
|
||||
//-- 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::NO_VALUE'], $e->validationModel->errorKeys);
|
||||
}
|
||||
|
||||
//-- Assert (2/2)
|
||||
$this->assertThat($exceptionThrown, $this->equalTo(true));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user