Commit d451d754 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Refs #7743. Move error mesages to Constants.php. Unit tests use those...

Refs #7743. Move error mesages to Constants.php. Unit tests use those constants now. 'data-pattern-error' only delivered if a 'pattern' is given. 'required' attribute only delivered is set.
parent 4f52831e
Pipeline #1414 failed with stage
in 2 minutes and 13 seconds
......@@ -1297,16 +1297,27 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeList($formElement, [FE_INPUT_AUTOCOMPLETE, 'autofocus', 'placeholder']);
$formElement[FE_CHECK_PATTERN] = Sanitize::getInputCheckPattern($formElement[FE_CHECK_TYPE], $formElement[FE_CHECK_PATTERN], $formElement[FE_DECIMAL_FORMAT], $sanitizeMessage);
$attribute .= ($formElement[FE_CHECK_PATTERN] === '') ? '' : 'pattern="' . $formElement[FE_CHECK_PATTERN] . '" ';
if (empty($formElement[F_FE_DATA_PATTERN_ERROR])) {
$formElement[F_FE_DATA_PATTERN_ERROR] = empty($sanitizeMessage) ? F_FE_DATA_PATTERN_ERROR_DEFAULT : $sanitizeMessage;
$formElement[FE_CHECK_PATTERN] = Sanitize::getInputCheckPattern($formElement[FE_CHECK_TYPE], $formElement[FE_CHECK_PATTERN]
, $formElement[FE_DECIMAL_FORMAT], $sanitizeMessage);
if ($formElement[FE_CHECK_PATTERN] !== '') {
$attribute .= Support::doAttribute('pattern', $formElement[FE_CHECK_PATTERN], true, ESCAPE_WITH_BACKSLASH);
// Use system specific message only,if no custom one is set.
if ($formElement[F_FE_DATA_PATTERN_ERROR] == $formElement[F_FE_DATA_PATTERN_ERROR_SYSTEM]) {
$formElement[F_FE_DATA_PATTERN_ERROR] = $sanitizeMessage;
}
$attribute .= Support::doAttribute(F_FE_DATA_PATTERN_ERROR, $formElement[F_FE_DATA_PATTERN_ERROR], true, ESCAPE_WITH_BACKSLASH);
}
if ($formElement[FE_MODE] == FE_MODE_REQUIRED) {
$attribute .= Support::doAttribute(F_FE_DATA_REQUIRED_ERROR, $formElement[F_FE_DATA_REQUIRED_ERROR]);
}
if (empty($formElement[F_FE_DATA_MATCH_ERROR])) {
$formElement[F_FE_DATA_REQUIRED_ERROR] = F_FE_DATA_REQUIRED_ERROR_DEFAULT;
}
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR, FE_MIN, FE_MAX, FE_STEP]);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR, FE_MIN, FE_MAX, FE_STEP]);
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('title', $formElement[FE_TOOLTIP]);
......@@ -3358,9 +3369,14 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('title', $formElement[FE_TOOLTIP]);
$pattern = Sanitize::getInputCheckPattern($formElement[FE_CHECK_TYPE], $formElement[FE_CHECK_PATTERN], '', $rcSanitizeMessage);
$pattern = Sanitize::getInputCheckPattern($formElement[FE_CHECK_TYPE], $formElement[FE_CHECK_PATTERN], '', $sanitizeMessage);
$attribute .= ($pattern === '') ? '' : 'pattern="' . $pattern . '" ';
// Use system message only,if no custom one is set.
if ($formElement[F_FE_DATA_PATTERN_ERROR] == $formElement[F_FE_DATA_PATTERN_ERROR_SYSTEM]) {
$formElement[F_FE_DATA_PATTERN_ERROR] = $sanitizeMessage;
}
$attribute .= $this->getAttributeList($formElement, [FE_MIN, FE_MAX]);
$json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
......
......@@ -89,6 +89,12 @@ const SANITIZE_EMPTY_STRING = 'empty string';
const SANITIZE_VIOLATE = '!!';
const SANITIZE_ALLOW_ALNUMX_MESSAGE = 'Allowed characters: 0...9, [latin character], @-_.m;: /()';
const SANITIZE_ALLOW_DIGIT_MESSAGE = 'Allowed characters: 0...9';
const SANITIZE_ALLOW_NUMERICAL_MESSAGE = 'Allowed characters: 0...9 and .+-';
const SANITIZE_ALLOW_EMAIL_MESSAGE = 'Requested format: string@domain.tld';
const SANITIZE_ALLOW_ALLBUT_MESSAGE = 'Forbidden characters: ^[]{}%\#';
const PATTERN_ALNUMX = '^[@\-_\.,;: \/\(\)a-zA-Z0-9ÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜŸäëïöüÿç]*$';
const PATTERN_DIGIT = '^[\d]*$';
......@@ -902,9 +908,9 @@ const F_FE_DATA_MATCH_ERROR = 'data-match-error'; // contains id of the sibling
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
const F_FE_DATA_MATCH_ERROR_DEFAULT = 'fields do not match'; // Attention: the default is also defined in ext_conf_template.txt
const F_FE_DATA_PATTERN_ERROR_DEFAULT = 'Pattern mismatch'; // Attention: the default is also defined in ext_conf_template.txt
const F_FE_DATA_REQUIRED_ERROR_DEFAULT = 'Required'; // Attention: the default is also defined in ext_conf_template.txt
const F_FE_DATA_MATCH_ERROR_DEFAULT = 'Fields do not match'; // Attention: the default is also defined in ext_conf_template.txt
const F_FE_LABEL_ALIGN = SYSTEM_LABEL_ALIGN;
const F_FE_LABEL_ALIGN_DEFAULT = 'default';
......
......@@ -33,16 +33,15 @@ class Sanitize {
];
private static $sanitizeMessage = [
SANITIZE_ALLOW_ALNUMX => 'Allowed characters: 0...9, [latin character], @-_.m;: /()',
SANITIZE_ALLOW_DIGIT => 'Allowed characters: 0...9',
SANITIZE_ALLOW_NUMERICAL => 'Allowed characters: 0...9 and .+-',
SANITIZE_ALLOW_EMAIL => 'Requested format: string@domain.tld',
SANITIZE_ALLOW_ALLBUT => 'Forbidden characters: ^[]{}%\#',
SANITIZE_ALLOW_ALNUMX => SANITIZE_ALLOW_ALNUMX_MESSAGE,
SANITIZE_ALLOW_DIGIT => SANITIZE_ALLOW_DIGIT_MESSAGE,
SANITIZE_ALLOW_NUMERICAL => SANITIZE_ALLOW_NUMERICAL_MESSAGE,
SANITIZE_ALLOW_EMAIL => SANITIZE_ALLOW_EMAIL_MESSAGE,
SANITIZE_ALLOW_ALLBUT => SANITIZE_ALLOW_ALLBUT_MESSAGE,
SANITIZE_ALLOW_ALL => '',
SANITIZE_ALLOW_PATTERN => 'Please match the requested format',
SANITIZE_ALLOW_PATTERN => F_FE_DATA_PATTERN_ERROR_DEFAULT,
];
private function __construct() {
// Class should never be instantiated
}
......
......@@ -95,56 +95,56 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$label['123-r'][API_ELEMENT_ATTRIBUTE] = ['class' => ''];
$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="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-error="Error" 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);
// Min/Max
$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="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" min="1" max="10" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="number" value="" data-error="Error" 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_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="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" min="1" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-error="Error" 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';
$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="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" max="10" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-error="Error" 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="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" min="0" max="10" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-error="Error" 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="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" min="-5" max="0" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-error="Error" 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] = '';
// CheckType
// CheckType: custom pattern, standard data-pattern-error
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_PATTERN;
$formElement[FE_CHECK_PATTERN] = '^[a-z]*$';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^[a-z]*$" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^[a-z]*$" data-pattern-error="' . F_FE_DATA_PATTERN_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^[a-z]*$';
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_DIGIT;
$formElement[FE_CHECK_PATTERN] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^[\d]*$" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^[\d]*$" data-pattern-error="' . SANITIZE_ALLOW_DIGIT_MESSAGE . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^[\d]*$';
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
......@@ -153,7 +153,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement[FE_CHECK_PATTERN] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$';
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" data-pattern-error="pattern error" data-required-error="data required" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" data-pattern-error="' . SANITIZE_ALLOW_EMAIL_MESSAGE . '" data-error="Error" 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_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
......@@ -163,7 +163,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
// Decimal format
$formElement[FE_DECIMAL_FORMAT] = '5,2';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^-?[0-9]{0,3}(\.[0-9]{0,2})?$" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^-?[0-9]{0,3}(\.[0-9]{0,2})?$" data-pattern-error="Requested decimal format (mantis,decimal): 5,2" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^-?[0-9]{0,3}(\.[0-9]{0,2})?$';
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
......@@ -174,14 +174,14 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement['size'] = 40;
$formElement['maxLength'] = 40;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="40" type="input" size="40" value="" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="40" type="input" size="40" value="" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
unset($label['123'][API_ELEMENT_ATTRIBUTE]['pattern']);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
// maxlength bigger than physical spec:
$formElement['maxLength'] = 1000;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" size="40" value="" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" size="40" value="" data-error="Error" 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);
// no size, no maxlength and column not in primary table
......@@ -190,24 +190,24 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement2['size'] = '';
$formElement2['name'] = 'specialname';
$result = $build->buildInput($formElement2, 'specialname:1', '', $json);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" type="input" value="" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" type="input" value="" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// no size, given maxlength and column not in primary table
$formElement2['maxLength'] = '10';
$result = $build->buildInput($formElement2, 'specialname:1', '', $json);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" maxlength="10" type="input" value="" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" maxlength="10" type="input" value="" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// size given, no maxlength and column not in primary table
$formElement2['maxLength'] = '';
$formElement2['size'] = '10';
$result = $build->buildInput($formElement2, 'specialname:1', '', $json);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" type="input" size="10" value="" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" type="input" size="10" value="" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// size given, maxlength given and column not in primary table
$formElement2['maxLength'] = '20';
$formElement2['size'] = '10';
$result = $build->buildInput($formElement2, 'specialname:1', '', $json);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" maxlength="20" type="input" size="10" value="" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" maxlength="20" type="input" size="10" value="" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$formElement2['maxLength'] = '';
$formElement2['size'] = '';
......@@ -215,20 +215,20 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement2['tooltip'] = 'Nice Tooltip';
$formElement2['placeholder'] = 'Please type a name';
$result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" value="Hello World" placeholder="Please type a name" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" title="Nice Tooltip" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" value="Hello World" placeholder="Please type a name" data-error="Error" title="Nice Tooltip" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$label['123'][API_ELEMENT_ATTRIBUTE] = ['value' => 'Hello World', 'required' => false, 'hidden' => false];
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
// textarea
$formElement2['size'] = '40,10';
$result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
$this->assertEquals('<textarea id="123" name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" title="Nice Tooltip" data-hidden="no" data-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<textarea id="123" name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" data-error="Error" title="Nice Tooltip" data-hidden="no" data-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
$formElement2['size'] = ' 40 , 10 ';
$result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
$this->assertEquals('<textarea id="123" name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" title="Nice Tooltip" data-hidden="no" data-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<textarea id="123" name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" data-error="Error" title="Nice Tooltip" data-hidden="no" data-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
}
......@@ -254,32 +254,44 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_ALNUMX . '" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_ALNUMX .
'" data-pattern-error="' . SANITIZE_ALLOW_ALNUMX_MESSAGE .
'" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_DIGIT;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_DIGIT . '" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_DIGIT .
'" data-pattern-error="' . SANITIZE_ALLOW_DIGIT_MESSAGE .
'" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_NUMERICAL;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_NUMERICAL . '" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_NUMERICAL .
'" data-pattern-error="' . SANITIZE_ALLOW_NUMERICAL_MESSAGE .
'" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_EMAIL;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_EMAIL . '" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_EMAIL .
'" data-pattern-error="' . SANITIZE_ALLOW_EMAIL_MESSAGE .
'" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALLBUT;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_ALLBUT . '" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_ALLBUT .
'" data-pattern-error="' . SANITIZE_ALLOW_ALLBUT_MESSAGE .
'" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
$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="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_PATTERN;
$formElement[FE_CHECK_PATTERN] = '^[0-2]$';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . $formElement[FE_CHECK_PATTERN] . '" data-pattern-error="pattern error" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . $formElement[FE_CHECK_PATTERN] .
'" data-pattern-error="' . F_FE_DATA_PATTERN_ERROR_DEFAULT .
'" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
}
/**
......@@ -306,7 +318,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="' . PATTERN_ALNUMX .
'" data-pattern-error="' . $formElement[F_FE_DATA_PATTERN_ERROR] . '" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT .
'" data-pattern-error="' . SANITIZE_ALLOW_ALNUMX_MESSAGE .
'" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// const SANITIZE_ALLOW_ALNUMX = "alnumx";
......@@ -692,7 +704,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
F_FE_DATA_ERROR => F_FE_DATA_ERROR_DEFAULT,
F_FE_DATA_PATTERN_ERROR => F_FE_DATA_PATTERN_ERROR_DEFAULT,
F_FE_DATA_PATTERN_ERROR_SYSTEM => F_FE_DATA_ERROR_DEFAULT,
F_FE_DATA_PATTERN_ERROR_SYSTEM => F_FE_DATA_PATTERN_ERROR_DEFAULT,
'tabindex' => 0,
];
......
......@@ -119,10 +119,10 @@ enterAsSubmit = 1
editFormPage = form
# cat=form-config/config; type=string; label=Form data pattern error message:QFQ default is pattern dependent - leave this empty to use pattern specific messages. Customizable error message used in validator.js. 'pattern' violation.
# cat=form-config/config; type=string; label=Form data pattern error message: default is 'Pattern mismatch' for all custom pattern. Customizable message used in validator.js. 'pattern' violation.
formDataPatternError =
# cat=form-config/config; type=string; label=Form data required error message:Default is 'data required'. Customizable error message used in validator.js. 'required' violation.
# cat=form-config/config; type=string; label=Form data required error message:Default is 'Required'. Customizable error message used in validator.js. 'required' violation.
formDataRequiredError =
# cat=form-config/config; type=string; label=Form data match error message:Default is 'Fields do not match'. Customizable error message used in validator.js. 'match' violation. Typically used to ensure that two given emails or passwords are identically.
......
Supports Markdown
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