Refactored custom field validator, re-enabled test
parent
e22d318b92
commit
e44baa99c2
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: cokoch
|
||||
* Date: 2/9/2017
|
||||
* Time: 12:28 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Tickets\CustomFields;
|
||||
|
||||
|
||||
class CustomFieldValidator {
|
||||
static function isCustomFieldInCategory($customFieldId, $categoryId, $staff, $heskSettings) {
|
||||
$customField = $heskSettings['custom_fields']["custom{$customFieldId}"];
|
||||
|
||||
if (!$customField['use'] ||
|
||||
(!$staff && $customField['use'] === 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($customField['category']) === 0 ||
|
||||
in_array($categoryId, $customField['category']);
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: cokoch
|
||||
* Date: 2/9/2017
|
||||
* Time: 12:29 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Tickets\CustomFields;
|
||||
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CustomFieldValidatorTest extends TestCase {
|
||||
function testItReturnsTrueWhenTheCustomFieldIsInTheCategory() {
|
||||
//-- Arrange
|
||||
$heskSettings = array(
|
||||
'custom_fields' => 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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue