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

Update and write new unit tests

parent 59c1b246
......@@ -985,10 +985,6 @@ Only in FormElement:
+------------------+------+-------+-----------------------------------------------------------------------------------------+
| **email** | Form | Query | [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,} |
+------------------+------+-------+-----------------------------------------------------------------------------------------+
| **min|max** | Form | | Compares the value against an lower and upper limit (numeric or string). |
+------------------+------+-------+-----------------------------------------------------------------------------------------+
| **min|max date** | Form | | Compares the value against an lower and upper date or datetime. |
+------------------+------+-------+-----------------------------------------------------------------------------------------+
| **pattern** | Form | | Compares the value against a regexp. |
+------------------+------+-------+-----------------------------------------------------------------------------------------+
......@@ -2327,8 +2323,8 @@ Fields:
+---------------------+-----------------------------+-----------------------------------------------------------------------------------------------------+
|Encode | 'none', 'specialchar' | With 'specialchar' (default) the chars <>"'& will be encoded to their htmlentity. _`field-encode` |
+---------------------+-----------------------------+-----------------------------------------------------------------------------------------------------+
|Check Type | enum('min|max', 'pattern', | _`field-checkType` |
| | 'number', 'email') | |
|Check Type | enum('number', 'pattern', | _`field-checkType` |
| | 'email') | |
+---------------------+-----------------------------+-----------------------------------------------------------------------------------------------------+
|Check Pattern | 'regexp' |If $checkType=='pattern': pattern to match |
+---------------------+-----------------------------+-----------------------------------------------------------------------------------------------------+
......
......@@ -90,16 +90,28 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
* @throws UserFormException
*/
public function testSanitizeMinMax() {
// TODO: MIN/MAX
# Check min|max
$msg = "SANITIZE_MIN_MAX fails";
# Check numerical min/max
$val = 56;
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '0|2'), "SANITIZE_MIN_MAX fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '0|200'), "SANITIZE_MIN_MAX fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '-100|200'), "SANITIZE_MIN_MAX fails");
$this->assertEquals('', Sanitize::checkMinMax($val, [ FE_MIN => "0", FE_MAX => "2" ]), $msg);
$this->assertEquals($val, Sanitize::checkMinMax($val, [ FE_MIN => "0" ]), $msg);
$this->assertEquals('', Sanitize::checkMinMax($val, [ FE_MAX => "2" ]), $msg);
$this->assertEquals($val, Sanitize::checkMinMax($val, [ FE_MIN => "0", FE_MAX => "200" ]), $msg);
$this->assertEquals($val, Sanitize::checkMinMax($val, [ FE_MIN => "-100", FE_MAX => "200" ]), $msg);
$val = -56;
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '0|2'), "SANITIZE_MIN_MAX fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '-100|0'), "SANITIZE_MIN_MAX fails");
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '-100|200'), "SANITIZE_MIN_MAX fails");
$this->assertEquals('', Sanitize::checkMinMax($val, [ FE_MIN => "0", FE_MAX => "2" ]), $msg);
$this->assertEquals($val, Sanitize::checkMinMax($val, [ FE_MIN => "0", FE_MAX => "200" ]), $msg);
$this->assertEquals($val, Sanitize::checkMinMax($val, [ FE_MIN => "-100", FE_MAX => "200" ]), $msg);
# Check min/max dates
$val = "2010-05-01";
$this->assertEquals('', Sanitize::checkMinMax($val, [ FE_MIN => "2010-01-01", FE_MAX => "2010-12-31" ]), $msg);
$this->assertEquals('', Sanitize::checkMinMax('', [ FE_MIN => "2010-01-01", FE_MAX => "2010-04-30" ]), $msg);
$this->assertEquals('', Sanitize::checkMinMax('', [ FE_MIN => "2010-01-01", FE_MAX => "2009-12-31" ]), $msg);
$this->assertEquals('', Sanitize::checkMinMax('', [ FE_MIN => "2011-01-01", FE_MAX => "2009-12-31" ]), $msg);
$this->assertEquals('', Sanitize::checkMinMax('', [ FE_MIN => "2010-01-01", FE_MAX => "2010-04-30" ]), $msg);
$this->assertEquals('', Sanitize::checkMinMax($val, [ FE_MIN => "2010-05-01", FE_MAX => "2010-05-01" ]), $msg);
}
/**
......
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