diff --git a/api/businesslogic/Helpers.php b/api/BusinessLogic/Helpers.php similarity index 100% rename from api/businesslogic/Helpers.php rename to api/BusinessLogic/Helpers.php diff --git a/api/BusinessLogic/Tickets/CustomFields/CustomFieldValidator.php b/api/BusinessLogic/Tickets/CustomFields/CustomFieldValidator.php new file mode 100644 index 00000000..037d828e --- /dev/null +++ b/api/BusinessLogic/Tickets/CustomFields/CustomFieldValidator.php @@ -0,0 +1,24 @@ +priority) === $TICKET_PRIORITY_CRITICAL) { $validationModel->errorKeys[] = 'CRITICAL_PRIORITY_FORBIDDEN'; } @@ -89,7 +89,7 @@ class TicketCreator { foreach ($heskSettings['custom_fields'] as $key => $value) { $customFieldNumber = intval(str_replace('custom', '', $key)); - if ($value['use'] == 1 && hesk_is_custom_field_in_category($customFieldNumber, intval($ticketRequest->category))) { + if ($value['use'] == 1 && CustomFieldValidator::isCustomFieldInCategory($customFieldNumber, intval($ticketRequest->category), false, $heskSettings)) { $custom_field_value = $ticketRequest->customFields[$customFieldNumber]; if (empty($custom_field_value)) { $validationModel->errorKeys[] = "CUSTOM_FIELD_{$customFieldNumber}_INVALID::NO_VALUE"; diff --git a/api/businesslogic/ValidationModel.php b/api/BusinessLogic/ValidationModel.php similarity index 100% rename from api/businesslogic/ValidationModel.php rename to api/BusinessLogic/ValidationModel.php diff --git a/api/businesslogic/security/BanRetriever.php b/api/BusinessLogic/security/BanRetriever.php similarity index 100% rename from api/businesslogic/security/BanRetriever.php rename to api/BusinessLogic/security/BanRetriever.php diff --git a/api/businesslogic/security/BannedEmail.php b/api/BusinessLogic/security/BannedEmail.php similarity index 100% rename from api/businesslogic/security/BannedEmail.php rename to api/BusinessLogic/security/BannedEmail.php diff --git a/api/businesslogic/security/BannedIp.php b/api/BusinessLogic/security/BannedIp.php similarity index 100% rename from api/businesslogic/security/BannedIp.php rename to api/BusinessLogic/security/BannedIp.php diff --git a/api/businesslogic/security/UserContext.php b/api/BusinessLogic/security/UserContext.php similarity index 100% rename from api/businesslogic/security/UserContext.php rename to api/BusinessLogic/security/UserContext.php diff --git a/api/businesslogic/security/UserContextBuilder.php b/api/BusinessLogic/security/UserContextBuilder.php similarity index 100% rename from api/businesslogic/security/UserContextBuilder.php rename to api/BusinessLogic/security/UserContextBuilder.php diff --git a/api/businesslogic/security/UserContextNotifications.php b/api/BusinessLogic/security/UserContextNotifications.php similarity index 100% rename from api/businesslogic/security/UserContextNotifications.php rename to api/BusinessLogic/security/UserContextNotifications.php diff --git a/api/businesslogic/security/UserContextPreferences.php b/api/BusinessLogic/security/UserContextPreferences.php similarity index 100% rename from api/businesslogic/security/UserContextPreferences.php rename to api/BusinessLogic/security/UserContextPreferences.php diff --git a/api/core/database.inc.php b/api/Core/database.inc.php similarity index 100% rename from api/core/database.inc.php rename to api/Core/database.inc.php diff --git a/api/core/database_mysqli.inc.php b/api/Core/database_mysqli.inc.php similarity index 100% rename from api/core/database_mysqli.inc.php rename to api/Core/database_mysqli.inc.php diff --git a/api/core/json_error.php b/api/Core/json_error.php similarity index 100% rename from api/core/json_error.php rename to api/Core/json_error.php diff --git a/api/core/output.php b/api/Core/output.php similarity index 100% rename from api/core/output.php rename to api/Core/output.php diff --git a/api/Tests/BusinessLogic/Tickets/CustomFields/CustomFieldValidatorTest.php b/api/Tests/BusinessLogic/Tickets/CustomFields/CustomFieldValidatorTest.php new file mode 100644 index 00000000..b9958be1 --- /dev/null +++ b/api/Tests/BusinessLogic/Tickets/CustomFields/CustomFieldValidatorTest.php @@ -0,0 +1,86 @@ + array( + 'custom1' => array( + 'use' => 1, + 'category' => array(1, 2) + ) + ) + ); + + //-- Act + $result = CustomFieldValidator::isCustomFieldInCategory(1, 1, false, $heskSettings); + + //-- Assert + $this->assertThat($result, $this->isTrue()); + } + + function testItReturnsTrueWhenTheCustomFieldIsForAllCategories() { + //-- Arrange + $heskSettings = array( + 'custom_fields' => array( + 'custom1' => array( + 'use' => 1, + 'category' => [] + ) + ) + ); + + //-- Act + $result = CustomFieldValidator::isCustomFieldInCategory(1, 1, false, $heskSettings); + + //-- Assert + $this->assertThat($result, $this->isTrue()); + } + + function testItReturnsFalseWhenTheCustomFieldIsNotInTheCategory() { + //-- Arrange + $heskSettings = array( + 'custom_fields' => array( + 'custom1' => array( + 'use' => 1, + 'category' => array(1, 2) + ) + ) + ); + + //-- Act + $result = CustomFieldValidator::isCustomFieldInCategory(1, 50, false, $heskSettings); + + //-- Assert + $this->assertThat($result, $this->isFalse()); + } + + function testItReturnsFalseWhenTheCustomFieldIsForStaffOnly() { + //-- Arrange + $heskSettings = array( + 'custom_fields' => array( + 'custom1' => array( + 'use' => 2, + 'category' => array(1, 2) + ) + ) + ); + + //-- Act + $result = CustomFieldValidator::isCustomFieldInCategory(1, 1, false, $heskSettings); + + //-- Assert + $this->assertThat($result, $this->isFalse()); + } +} diff --git a/api/Tests/BusinessLogic/Tickets/TicketCreatorTest.php b/api/Tests/BusinessLogic/Tickets/TicketCreatorTest.php index c4b9e2b8..6ce6d5c1 100644 --- a/api/Tests/BusinessLogic/Tickets/TicketCreatorTest.php +++ b/api/Tests/BusinessLogic/Tickets/TicketCreatorTest.php @@ -377,10 +377,6 @@ class TicketCreatorTest extends TestCase { } function testItAddsTheProperValidationErrorWhenTheCustomerSubmitsTicketWithNullRequiredCustomField() { - $this->markTestIncomplete( - 'Not complete; need to refactor custom field in category' - ); - //-- Arrange $customField = array(); $customField['req'] = 1;