Index: trunk/extensions/Validator/test/ValidatorCriteriaTests.php |
— | — | @@ -38,5 +38,30 @@ |
39 | 39 | ); |
40 | 40 | } |
41 | 41 | } |
| 42 | + |
| 43 | + /** |
| 44 | + * Tests CriterionInArray. |
| 45 | + */ |
| 46 | + public function testCriterionInArray() { |
| 47 | + $tests = array( |
| 48 | + array( true, 'foo', false, array( 'foo', 'bar', 'baz' ) ), |
| 49 | + array( true, 'FoO', false, array( 'fOo', 'bar', 'baz' ) ), |
| 50 | + array( false, 'FoO', true, array( 'fOo', 'bar', 'baz' ) ), |
| 51 | + array( false, 'foobar', false, array( 'foo', 'bar', 'baz' ) ), |
| 52 | + array( false, '', false, array( 'foo', 'bar', 'baz' ) ), |
| 53 | + array( false, '', false, array( 'foo', 'bar', 'baz', 0 ) ), |
| 54 | + ); |
| 55 | + |
| 56 | + foreach ( $tests as $test ) { |
| 57 | + $c = new CriterionInArray( $test[3], $test[2] ); |
| 58 | + $p = new Parameter( 'test' ); |
| 59 | + $p->setUserValue( 'test', $test[1] ); |
| 60 | + $this->assertEquals( |
| 61 | + $test[0], |
| 62 | + $c->validate( $p, array() )->isValid(), |
| 63 | + 'Value "'. $test[1] . '" should ' . ( $test[0] ? '' : 'not ' ) . "be in list '" . $GLOBALS['wgLang']->listToText( $test[3] ) . "'." |
| 64 | + ); |
| 65 | + } |
| 66 | + } |
42 | 67 | |
43 | 68 | } |