Commit ed09b09c authored by Elias Villiger's avatar Elias Villiger
Browse files

Remove unneeded functions & unit tests #5309

parent 2190b11c
......@@ -1404,16 +1404,6 @@ abstract class AbstractBuildForm {
}
switch ($type) {
case SANITIZE_ALLOW_MIN_MAX:
case SANITIZE_ALLOW_MIN_MAX_DATE:
$arrData = explode("|", $data);
if (count($arrData) != 2 || $arrData[0] == '' || $arrData[1] == '')
throw new UserFormException("Missing MIN|MAX values", ERROR_MISSING_MIN_MAX);
$attribute = 'min="' . $arrData[0] . '" ';
$attribute .= 'max="' . $arrData[1] . '" ';
break;
case SANITIZE_ALLOW_PATTERN:
$attribute = 'pattern="' . $data . '" ';
break;
......@@ -3108,12 +3098,6 @@ abstract class AbstractBuildForm {
case SANITIZE_ALLOW_PATTERN:
$formElement[FE_CHECK_PATTERN] = $tmpPattern;
break;
case SANITIZE_ALLOW_MIN_MAX_DATE:
$arrMinMax = explode('|', $formElement[FE_CHECK_PATTERN], 2);
if (count($arrMinMax) != 2) {
throw new UserFormException('Missing min|max definition', ERROR_MISSING_MIN_MAX);
}
break;
case SANITIZE_ALLOW_ALL:
case SANITIZE_ALLOW_ALNUMX:
case SANITIZE_ALLOW_ALLBUT:
......
......@@ -966,7 +966,6 @@ const FE_FLAG_ROW_CLOSE_TAG = '_flagRowCloseTag'; // will be automatically compu
const FE_MIN = 'min';
const FE_MAX = 'max';
const FE_MIN_MAX_COMPARE_MODE = 'minMaxCompareMode';
const RETYPE_FE_NAME_EXTENSION = 'RETYPE';
......
......@@ -124,8 +124,6 @@ class Sanitize {
SANITIZE_ALLOW_DIGIT => '^[\d]*$',
SANITIZE_ALLOW_NUMERICAL => '^[\d.+-]*$',
SANITIZE_ALLOW_EMAIL => '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
SANITIZE_ALLOW_MIN_MAX => '',
SANITIZE_ALLOW_MIN_MAX_DATE => '',
SANITIZE_ALLOW_PATTERN => '',
SANITIZE_ALLOW_ALLBUT => '^[^\[\]{}%&\\\\#]*$',
SANITIZE_ALLOW_ALL => '.*',
......
......@@ -473,7 +473,7 @@ class Store {
$rawVal = isset(self::$raw[$store][$finalKey]) ? self::$raw[$store][$finalKey] : null;
if (self::$sanitizeStore[$store] && $sanitizeClass != '') {
if ($sanitizeClass == SANITIZE_ALLOW_PATTERN || $sanitizeClass == SANITIZE_ALLOW_MIN_MAX || $sanitizeClass == SANITIZE_ALLOW_MIN_MAX_DATE) {
if ($sanitizeClass == SANITIZE_ALLOW_PATTERN) {
// We do not have any pattern at this point. For those who be affected, they already checked earlier. So set 'no check'
$sanitizeClass = SANITIZE_ALLOW_ALL;
}
......
......@@ -85,6 +85,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
// CheckType
// TODO: MIN/MAX
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_MIN_MAX;
$formElement[FE_CHECK_PATTERN] = '1|10';
$result = $build->buildInput($formElement, 'name:1', '', $json);
......@@ -172,24 +173,6 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
}
/**
* @expectedException \qfq\UserFormException
*
*/
public function testBuildInputException() {
$form = array();
$formElement = array();
$json = array();
$this->templateFormNFormElement($form, $formElement);
$build = new \qfq\BuildFormPlain($form, array(), [$formElement], $this->dbArray);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_MIN_MAX;
$formElement[FE_CHECK_PATTERN] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
}
/**
*
*/
......
......@@ -26,7 +26,6 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
# Check ''
$this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_ALNUMX), "SANITIZE_ALNUMX fails");
$this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_DIGIT), "SANITIZE_DIGIT fails");
$this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_MIN_MAX, '1|2'), "SANITIZE_MIN_MAX fails");
$this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_EMAIL), "SANITIZE_EMAIL fails");
$this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_PATTERN, '.*'), "SANITIZE_PATTERN fails");
$this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_ALL), "SANITIZE_ALL fails");
......@@ -35,7 +34,6 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
# Check '1'
$this->assertEquals('1', Sanitize::sanitize('1', SANITIZE_ALLOW_ALNUMX), "SANITIZE_ALNUMX fails");
$this->assertEquals('1', Sanitize::sanitize('1', SANITIZE_ALLOW_DIGIT), "SANITIZE_DIGIT fails");
$this->assertEquals('1', Sanitize::sanitize('1', SANITIZE_ALLOW_MIN_MAX, '1|2'), "SANITIZE_MIN_MAX fails");
$this->assertEquals('', Sanitize::sanitize('1', SANITIZE_ALLOW_EMAIL), "SANITIZE_EMAIL fails");
$this->assertEquals('1', Sanitize::sanitize('1', SANITIZE_ALLOW_PATTERN, '.*'), "SANITIZE_PATTERN fails");
$this->assertEquals('1', Sanitize::sanitize('1', SANITIZE_ALLOW_ALL), "SANITIZE_ALL fails");
......@@ -44,7 +42,6 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
# Check '-3'
$this->assertEquals('-3', Sanitize::sanitize('-3', SANITIZE_ALLOW_ALNUMX), "SANITIZE_ALNUMX fails");
$this->assertEquals('', Sanitize::sanitize('-3', SANITIZE_ALLOW_DIGIT), "SANITIZE_DIGIT fails");
$this->assertEquals('-3', Sanitize::sanitize('-3', SANITIZE_ALLOW_MIN_MAX, '-5|2'), "SANITIZE_MIN_MAX fails");
$this->assertEquals('', Sanitize::sanitize('-3', SANITIZE_ALLOW_EMAIL), "SANITIZE_EMAIL fails");
$this->assertEquals('-3', Sanitize::sanitize('-3', SANITIZE_ALLOW_PATTERN, '.*'), "SANITIZE_PATTERN fails");
$this->assertEquals('-3', Sanitize::sanitize('-3', SANITIZE_ALLOW_ALL), "SANITIZE_ALL fails");
......@@ -53,7 +50,6 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
# Check 'a'
$this->assertEquals('a', Sanitize::sanitize('a', SANITIZE_ALLOW_ALNUMX), "SANITIZE_ALNUMX fails");
$this->assertEquals('', Sanitize::sanitize('a', SANITIZE_ALLOW_DIGIT), "SANITIZE_DIGIT fails");
$this->assertEquals('', Sanitize::sanitize('a', SANITIZE_ALLOW_MIN_MAX, '-5|2'), "SANITIZE_MIN_MAX fails");
$this->assertEquals('', Sanitize::sanitize('a', SANITIZE_ALLOW_EMAIL), "SANITIZE_EMAIL fails");
$this->assertEquals('a', Sanitize::sanitize('a', SANITIZE_ALLOW_PATTERN, '.*'), "SANITIZE_PATTERN fails");
$this->assertEquals('a', Sanitize::sanitize('a', SANITIZE_ALLOW_ALL), "SANITIZE_ALL fails");
......@@ -64,7 +60,6 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
$val = 'a@-_.,;Z09';
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALNUMX), "SANITIZE_ALNUMX fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_DIGIT), "SANITIZE_DIGIT fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '-5|2'), "SANITIZE_MIN_MAX fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_EMAIL), "SANITIZE_EMAIL fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_PATTERN, '.*'), "SANITIZE_PATTERN fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL), "SANITIZE_ALL fails");
......@@ -74,7 +69,6 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
$val = 'a+Z09';
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALNUMX), "SANITIZE_ALNUMX fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_DIGIT), "SANITIZE_DIGIT fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '-5|2'), "SANITIZE_MIN_MAX fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_EMAIL), "SANITIZE_EMAIL fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_PATTERN, '.*'), "SANITIZE_PATTERN fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL), "SANITIZE_ALL fails");
......@@ -84,7 +78,6 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
$val = 'ÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜŸäëïöüÿ';
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALNUMX), "SANITIZE_ALNUMX fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_DIGIT), "SANITIZE_DIGIT fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '-5|2'), "SANITIZE_MIN_MAX fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_EMAIL), "SANITIZE_EMAIL fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_PATTERN, '.*'), "SANITIZE_PATTERN fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL), "SANITIZE_ALL fails");
......@@ -97,7 +90,7 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
* @throws UserFormException
*/
public function testSanitizeMinMax() {
// TODO: MIN/MAX
# Check min|max
$val = 56;
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '0|2'), "SANITIZE_MIN_MAX fails");
......@@ -109,38 +102,6 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '-100|200'), "SANITIZE_MIN_MAX fails");
}
/**
* @throws CodeException
* @throws UserFormException
*/
public function testSanitizeMinMaxDate() {
# Check min|max
$val = '15.04.2016';
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '01.06.2016|31.12.2016'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '01.01.2016|31.01.2016'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '01.01.2016|31.12.2016'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
# Check min|max
$val = '15.04.16';
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '01.06.16|31.12.16'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '01.01.16|31.01.16'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '01.01.16|31.12.16'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
# Check min|max
$val = '15.4.16';
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '1.6.16|31.12.16'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '1.1.16|31.1.16'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '1.1.16|31.12.16'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
# Check min|max
$val = '15.4.16';
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '01.06.2016|31.12.2016'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '01.01.2016|31.01.2016'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX_DATE, '01.01.2016|31.12.2016'), "SANITIZE_ALLOW_MIN_MAX_DATE fails");
}
/**
* @throws CodeException
* @throws UserFormException
......@@ -231,34 +192,6 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
Sanitize::sanitize('Hello World', 'invalid sanitize class');
}
/**
* @expectedException \qfq\UserFormException
*/
public function testSanitizeExceptionMinMaxMissing() {
Sanitize::sanitize(56, SANITIZE_ALLOW_MIN_MAX);
}
/**
* @expectedException \qfq\UserFormException
*/
public function testSanitizeExceptionMinMaxMissingMin() {
Sanitize::sanitize(56, SANITIZE_ALLOW_MIN_MAX, '|45');
}
/**
* @expectedException \qfq\UserFormException
*/
public function testSanitizeExceptionMinMaxMissingMax() {
Sanitize::sanitize(56, SANITIZE_ALLOW_MIN_MAX, '45|');
}
/**
* @expectedException \qfq\UserFormException
*/
public function testSanitizeExceptionMinMaxDateMissing() {
Sanitize::sanitize(56, SANITIZE_ALLOW_MIN_MAX);
}
/**
* @expectedException \qfq\UserFormException
*/
......
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