Commit 8c117f3c authored by Carsten  Rose's avatar Carsten Rose
Browse files

Refs #7743. Add unit tests. Make default error text more specific (only if...

Refs #7743. Add unit tests. Make default error text more specific (only if default error text is not explicit set in config, form or form-element)
parent fe00ae9b
Pipeline #1412 failed with stage
in 2 minutes and 3 seconds
......@@ -889,6 +889,7 @@ const F_FE_DATA_PATTERN_ERROR = 'data-pattern-error';
const F_FE_DATA_REQUIRED_ERROR = 'data-required-error';
const F_FE_DATA_MATCH_ERROR = 'data-match-error'; // contains id of the sibling input to check that i
const F_FE_DATA_ERROR = 'data-error';
const F_FE_DATA_ERROR_DEFAULT = 'Error';
const F_FE_DATA_PATTERN_ERROR_DEFAULT = 'pattern error'; // Attention: the default is also defined in ext_conf_template.txt
const F_FE_DATA_REQUIRED_ERROR_DEFAULT = 'data required'; // Attention: the default is also defined in ext_conf_template.txt
......
......@@ -960,22 +960,23 @@ class Support {
}
// Set parameters if not set by user
if ($formElement[FE_CHECK_TYPE] === SANITIZE_ALLOW_AUTO) {
$formElement[FE_CHECK_TYPE] = $checkType;
}
// If nothing given, set default
if ( ($formElement[FE_MIN]??'')=='' ){
if ( $formElement[FE_MIN]=='' ){
$formElement[FE_MIN] = $min;
}
// If nothing given, set default
if ( ($formElement[FE_MAX]??'')==''){
if ( $formElement[FE_MAX]==''){
$formElement[FE_MAX] = $max;
}
if (empty($formElement[FE_INPUT_TYPE])) $formElement[FE_INPUT_TYPE] = $inputType;
if (empty($formElement[FE_INPUT_TYPE])) {
$formElement[FE_INPUT_TYPE] = $inputType;
}
// If a $formElement[FE_STEP] is given, the optional boundaries (FE_MIN / FE_MAX) have to be aligned to a multiple of $formElement[FE_STEP].
if (!empty($formElement[FE_STEP])) {
......@@ -986,6 +987,11 @@ class Support {
$formElement[FE_MAX] = floor($formElement[FE_MAX] / $formElement[FE_STEP]) * $formElement[FE_STEP];
}
}
// If min or max is set and if there is the standard error text given, define a more detailed error text if the value is outside.
if( ($formElement[FE_MIN]!='' ||$formElement[FE_MAX]!='') && $formElement[F_FE_DATA_ERROR]==F_FE_DATA_ERROR_DEFAULT ){
$formElement[F_FE_DATA_ERROR]=F_FE_DATA_ERROR_DEFAULT . ' - value to low / high';
}
}
/**
......@@ -997,6 +1003,7 @@ class Support {
* @throws UserFormException
*/
private static function adjustDecimalFormat(array &$formElement, $typeSpec) {
if (isset($formElement[FE_DECIMAL_FORMAT])) {
if ($formElement[FE_DECIMAL_FORMAT] === '') {
// Get decimal format from column definition
......
......@@ -355,7 +355,7 @@ class Config {
F_FE_DATA_REQUIRED_ERROR => F_FE_DATA_REQUIRED_ERROR_DEFAULT,
F_FE_DATA_MATCH_ERROR => F_FE_DATA_MATCH_ERROR_DEFAULT,
F_FE_DATA_ERROR => 'error',
F_FE_DATA_ERROR => F_FE_DATA_ERROR_DEFAULT,
SYSTEM_FLAG_PRODUCTION => 'yes',
SYSTEM_THROW_GENERAL_ERROR => 'auto',
......
......@@ -99,23 +99,36 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
// Min/Max
$formElement[FE_MIN] = 1;
$formElement[FE_MAX] = 10;
$formElement[FE_MIN] = '1';
$formElement[FE_MAX] = '10';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="number" value="" data-pattern-error="pattern error" data-required-error="data required" min="1" max="10" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_MIN] = 1;
$formElement[FE_MIN] = '1';
$formElement[FE_MAX] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-pattern-error="pattern error" data-required-error="data required" min="1" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_MIN] = '';
$formElement[FE_MAX] = 10;
$formElement[FE_MAX] = '10';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-pattern-error="pattern error" data-required-error="data required" max="10" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_MIN] = '0';
$formElement[FE_MAX] = '10';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-pattern-error="pattern error" data-required-error="data required" min="0" max="10" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_MIN] = '-5';
$formElement[FE_MAX] = '0';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-pattern-error="pattern error" data-required-error="data required" min="-5" max="0" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
// reset so they don't interfere with next tests
$formElement[FE_MIN] = '';
$formElement[FE_MAX] = '';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment