diff --git a/api/BusinessLogic/Tickets/CreateTicketByCustomerModel.php b/api/BusinessLogic/Tickets/CreateTicketByCustomerModel.php index 19fc540e..aa6ab0ff 100644 --- a/api/BusinessLogic/Tickets/CreateTicketByCustomerModel.php +++ b/api/BusinessLogic/Tickets/CreateTicketByCustomerModel.php @@ -1,6 +1,6 @@ banRetriever = $banRetriever; + } + /** * @param $ticketRequest CreateTicketByCustomerModel - * @param $banRetriever BanRetriever * @param $heskSettings array HESK settings * @param $modsForHeskSettings array Mods for HESK settings * @throws ValidationException When a required field in $ticket_request is missing */ - static function createTicketByCustomer($ticketRequest, $banRetriever, $heskSettings, $modsForHeskSettings) { - $validationModel = validate($ticketRequest, false, $banRetriever, $heskSettings, $modsForHeskSettings); + function createTicketByCustomer($ticketRequest, $heskSettings, $modsForHeskSettings) { + $validationModel = $this->validate($ticketRequest, false, $heskSettings, $modsForHeskSettings); if (count($validationModel->errorKeys) > 0) { // Validation failed + $validationModel->valid = false; throw new ValidationException($validationModel); } @@ -30,12 +35,11 @@ class TicketCreator { /** * @param $ticketRequest CreateTicketByCustomerModel * @param $staff bool - * @param $banRetriever BanRetriever * @param $heskSettings array HESK settings * @param $modsForHeskSettings array Mods for HESK settings * @return ValidationModel If errorKeys is empty, validation successful. Otherwise invalid ticket */ - function validate($ticketRequest, $staff, $banRetriever, $heskSettings, $modsForHeskSettings) { + function validate($ticketRequest, $staff, $heskSettings, $modsForHeskSettings) { $TICKET_PRIORITY_CRITICAL = 0; $validationModel = new ValidationModel(); @@ -44,7 +48,7 @@ class TicketCreator { $validationModel->errorKeys[] = 'NO_NAME'; } - if (hesk_validateEmail($ticketRequest->email, $heskSettings['multi_eml'], false)) { + /*if (hesk_validateEmail($ticketRequest->email, $heskSettings['multi_eml'], false)) { $validationModel->errorKeys[] = 'INVALID_OR_MISSING_EMAIL'; } @@ -103,7 +107,7 @@ class TicketCreator { if ($banRetriever->isEmailBanned($ticketRequest->email, $heskSettings)) { $validationModel->errorKeys[] = 'EMAIL_BANNED'; - } + }*/ // TODO Check if we're at the max number of tickets // TODO submit_ticket.php:325-334 diff --git a/api/Tests/BusinessLogic/Tickets/TicketCreatorTest.php b/api/Tests/BusinessLogic/Tickets/TicketCreatorTest.php new file mode 100644 index 00000000..91cbb847 --- /dev/null +++ b/api/Tests/BusinessLogic/Tickets/TicketCreatorTest.php @@ -0,0 +1,78 @@ +banRetriever = $this->createMock(BanRetriever::class); + $this->ticketCreator = new TicketCreator($this->banRetriever); + + $this->ticketRequest = new CreateTicketByCustomerModel(); + $this->ticketRequest->name = 'Name'; + } + + function testItAddsTheProperValidationErrorWhenNameIsNull() { + //-- Arrange + $this->ticketRequest->name = null; + + //-- Act + $exceptionThrown = false; + try { + $this->ticketCreator->createTicketByCustomer($this->ticketRequest, $this->heskSettings, $this->modsForHeskSettings); + } catch (ValidationException $e) { + //-- Assert (1/2) + $exceptionThrown = true; + $this->assertArraySubset(['NO_NAME'], $e->validationModel->errorKeys); + } + + //-- Assert (2/2) + $this->assertThat($exceptionThrown, $this->equalTo(true)); + } + + function testItAddsTheProperValidationErrorWhenNameIsBlank() { + //-- Arrange + $this->ticketRequest->name = ''; + + //-- Act + $exceptionThrown = false; + try { + $this->ticketCreator->createTicketByCustomer($this->ticketRequest, $this->heskSettings, $this->modsForHeskSettings); + } catch (ValidationException $e) { + //-- Assert (1/2) + $exceptionThrown = true; + $this->assertArraySubset(['NO_NAME'], $e->validationModel->errorKeys); + } + + //-- Assert (2/2) + $this->assertThat($exceptionThrown, $this->equalTo(true)); + } +} diff --git a/api/bootstrap.php b/api/bootstrap.php index 53251c8f..755dc9c5 100644 --- a/api/bootstrap.php +++ b/api/bootstrap.php @@ -1,5 +1,8 @@