Commit 874aa79e authored by Carsten  Rose's avatar Carsten Rose
Browse files

Refs #7743. Add more unit tests

parent d451d754
Pipeline #1415 failed with stage
in 2 minutes and 1 second
......@@ -299,7 +299,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
* @throws UserFormException
* @throws UserReportException
*/
public function testBuildInputPatternErrorText() {
public function testBuildInputSpecificErrorTextDefault() {
$form = array();
$formElement = array();
$json = array();
......@@ -321,69 +321,73 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
'" 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";
// const SANITIZE_ALLOW_DIGIT = "digit";
// const SANITIZE_ALLOW_NUMERICAL = "numerical";
// const SANITIZE_ALLOW_EMAIL = "email";
// const SANITIZE_ALLOW_PATTERN = "pattern";
// const SANITIZE_ALLOW_ALLBUT = "allbut";
// const SANITIZE_ALLOW_ALL = "all";
//
// // Defaults data-pattern-error: DIGIT
// $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_ALNUMX .
// '" data-pattern-error="' . $formElement[F_FE_DATA_PATTERN_ERROR] . '" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT .
// '" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
//
// // Defaults data-pattern-error: ALUNUMX
// $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
// $formElement[F_FE_DATA_PATTERN_ERROR] = 'custom pattern text';
// $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="' . $formElement[F_FE_DATA_PATTERN_ERROR] . '" data-required-error="' . F_FE_DATA_REQUIRED_ERROR_DEFAULT .
// '" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
//
// // Defaults data-pattern-error: ALUNUMX
// $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
// $formElement[F_FE_DATA_PATTERN_ERROR] = 'custom pattern text';
// $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-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
//
// // Defaults data-pattern-error: ALUNUMX
// $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
// $formElement[F_FE_DATA_PATTERN_ERROR] = 'custom pattern text';
// $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-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
//
// // Defaults data-pattern-error: ALUNUMX
// $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
// $formElement[F_FE_DATA_PATTERN_ERROR] = 'custom pattern text';
// $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-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
//
//
//
//
//
//
//
//
// // Defaults data-error: ALNUMX
// $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
// $formElement[F_FE_DATA_ERROR] = 'custom data text';
// $formElement[F_FE_DATA_PATTERN_ERROR] = 'custom pattern text';
// $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-error="' . $formElement[F_FE_DATA_ERROR] . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// Defaults data-pattern-error: DIGIT
$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="' . SANITIZE_ALLOW_DIGIT_MESSAGE .
'" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// Defaults data-pattern-error: NUMERICAL
$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="' . SANITIZE_ALLOW_NUMERICAL_MESSAGE .
'" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// Defaults data-pattern-error: EMAIL
$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="' . SANITIZE_ALLOW_EMAIL_MESSAGE .
'" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// Defaults data-pattern-error: ALLBUT
$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="' . SANITIZE_ALLOW_ALLBUT_MESSAGE .
'" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testBuildInputCustomErrorText() {
$form = array();
$formElement = array();
$json = array();
$this->templateFormNFormElement($form, $formElement);
$build = new BuildFormPlain($form, array(), [$formElement], $this->dbArray);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
$formElement[FE_DECIMAL_FORMAT] = '';
$label['123-l'][API_ELEMENT_CONTENT] = '<label for="name:1" class="control-label" >Name</label>';
$label['123'][API_ELEMENT_ATTRIBUTE] = ['value' => '', 'required' => false, 'hidden' => false];
$label['123-r'][API_ELEMENT_ATTRIBUTE] = ['class' => ''];
// Defaults data-error: ALNUMX
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
$formElement[F_FE_DATA_ERROR] = 'custom data text';
$formElement[F_FE_DATA_PATTERN_ERROR] = 'custom pattern text';
$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-error="' . $formElement[F_FE_DATA_ERROR] . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// Defaults data-error: ALNUMX
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_PATTERN;
$formElement[FE_CHECK_PATTERN] = '[0-4]';
$formElement[F_FE_DATA_ERROR] = 'custom data text';
$formElement[F_FE_DATA_PATTERN_ERROR] = 'custom pattern text';
$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-4]' .
'" data-pattern-error="' . $formElement[F_FE_DATA_PATTERN_ERROR] .
'" data-error="' . $formElement[F_FE_DATA_ERROR] . '" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
}
/**
......
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