Index: trunk/extensions/Validator/test/ValidatorCriteriaTests.php |
— | — | @@ -18,13 +18,13 @@ |
19 | 19 | $tests = array( |
20 | 20 | array( true, 0, 5, 'foo' ), |
21 | 21 | array( false, 0, 5, 'foobar' ), |
22 | | - array( false, 3, null, 'a' ), |
23 | | - array( true, 3, null, 'aw<dfxdfwdxgtdfgdfhfdgsfdxgtffds' ), |
24 | | - array( true, null, null, 'aw<dfxdfwdxgtdfgdfhfdgsfdxgtffds' ), |
25 | | - array( true, null, null, '' ), |
| 22 | + array( false, 3, false, 'a' ), |
| 23 | + array( true, 3, false, 'aw<dfxdfwdxgtdfgdfhfdgsfdxgtffds' ), |
| 24 | + array( true, false, false, 'aw<dfxdfwdxgtdfgdfhfdgsfdxgtffds' ), |
| 25 | + array( true, false, false, '' ), |
26 | 26 | array( false, 2, 3, '' ), |
27 | | - array( true, 3, false, 'foo' ), |
28 | | - array( false, 3, false, 'foobar' ), |
| 27 | + array( true, 3, null, 'foo' ), |
| 28 | + array( false, 3, null, 'foobar' ), |
29 | 29 | ); |
30 | 30 | |
31 | 31 | foreach ( $tests as $test ) { |
— | — | @@ -185,4 +185,34 @@ |
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
| 189 | + /** |
| 190 | + * Tests CriterionItemCount. |
| 191 | + */ |
| 192 | + public function testCriterionItemCount() { |
| 193 | + $tests = array( |
| 194 | + array( true, array( 'foo', 'bar', 'baz' ), 0, 5 ), |
| 195 | + array( false, array( 'foo', 'bar', 'baz' ), 0, 2 ), |
| 196 | + array( true, array( 'foo', 'bar', 'baz' ), 0, false ), |
| 197 | + array( true, array( 'foo', 'bar', 'baz' ), false, 99 ), |
| 198 | + array( true, array( 'foo', 'bar', 'baz' ), 3, 3 ), |
| 199 | + array( false, array(), 1, 1 ), |
| 200 | + array( true, array( 'foo', 'bar', 'baz' ), false, false ), |
| 201 | + array( true, array( 'foo', 'bar', 'baz' ), 3, null ), |
| 202 | + array( false, array( 'foo', 'bar', 'baz' ), 2, null ), |
| 203 | + ); |
| 204 | + |
| 205 | + foreach ( $tests as $test ) { |
| 206 | + $c = new CriterionItemCount( $test[2], $test[3] ); |
| 207 | + $p = new ListParameter( 'test' ); |
| 208 | + $p->setUserValue( 'test', '' ); |
| 209 | + $p->setValue( $test[1] ); |
| 210 | + |
| 211 | + $this->assertEquals( |
| 212 | + $test[0], |
| 213 | + $c->validate( $p, array() ), |
| 214 | + 'List "'. $GLOBALS['wgLang']->listToText( $test[1] ) . '" should ' . ( $test[0] ? '' : 'not ' ) . " have between and $test[2], $test[3] items." |
| 215 | + ); |
| 216 | + } |
| 217 | + } |
| 218 | + |
189 | 219 | } |
Index: trunk/extensions/Validator/includes/criteria/CriterionHasLength.php |
— | — | @@ -19,16 +19,16 @@ |
20 | 20 | /** |
21 | 21 | * Constructor. |
22 | 22 | * |
23 | | - * @param integer $lowerBound Null for no lower bound (since 0.4.8). |
24 | | - * @param mixed $upperBound False for same value as lower bound. Null for no upper bound (since 0.4.8). |
| 23 | + * @param integer $lowerBound False for no lower bound (since 0.4.8). |
| 24 | + * @param mixed $upperBound False for same value as lower bound. False for no upper bound (since 0.4.8). |
25 | 25 | * |
26 | 26 | * @since 0.4 |
27 | 27 | */ |
28 | | - public function __construct( $lowerBound, $upperBound = false ) { |
| 28 | + public function __construct( $lowerBound, $upperBound = null ) { |
29 | 29 | parent::__construct(); |
30 | 30 | |
31 | 31 | $this->lowerBound = $lowerBound; |
32 | | - $this->upperBound = $upperBound === false ? $lowerBound : $upperBound; |
| 32 | + $this->upperBound = is_null( $upperBound ) ? $lowerBound : $upperBound; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
— | — | @@ -36,8 +36,8 @@ |
37 | 37 | */ |
38 | 38 | protected function doValidation( $value, Parameter $parameter, array $parameters ) { |
39 | 39 | $strlen = strlen( $value ); |
40 | | - return ( is_null( $this->upperBound ) || $strlen <= $this->upperBound ) |
41 | | - && ( is_null( $this->lowerBound ) || $strlen >= $this->lowerBound ); |
| 40 | + return ( $this->upperBound === false || $strlen <= $this->upperBound ) |
| 41 | + && ( $this->lowerBound === false || $strlen >= $this->lowerBound ); |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
Index: trunk/extensions/Validator/includes/criteria/CriterionItemCount.php |
— | — | @@ -19,16 +19,16 @@ |
20 | 20 | /** |
21 | 21 | * Constructor. |
22 | 22 | * |
23 | | - * @param integer $lowerBound |
24 | | - * @param mixed $upperBound |
| 23 | + * @param integer $lowerBound False for no lower bound (since 0.4.8). |
| 24 | + * @param mixed $upperBound False for no lower bound (since 0.4.8). |
25 | 25 | * |
26 | 26 | * @since 0.4 |
27 | 27 | */ |
28 | | - public function __construct( $lowerBound, $upperBound = false ) { |
| 28 | + public function __construct( $lowerBound, $upperBound = null ) { |
29 | 29 | parent::__construct(); |
30 | 30 | |
31 | 31 | $this->lowerBound = $lowerBound; |
32 | | - $this->upperBound = $upperBound === false ? $lowerBound : $upperBound; |
| 32 | + $this->upperBound = is_null( $upperBound ) ? $lowerBound : $upperBound; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
— | — | @@ -36,7 +36,8 @@ |
37 | 37 | */ |
38 | 38 | public function validate( Parameter $parameter, array $parameters) { |
39 | 39 | $count = count( $parameter->getValue() ); |
40 | | - return $count <= $this->upperBound && $count >= $this->lowerBound; |
| 40 | + return ( $this->upperBound === false || $count <= $this->upperBound ) |
| 41 | + && ( $this->lowerBound === false || $count >= $this->lowerBound ); |
41 | 42 | } |
42 | 43 | |
43 | 44 | } |
\ No newline at end of file |