Index: trunk/extensions/Validator/test/ValidatorCriteriaTests.php |
— | — | @@ -157,4 +157,32 @@ |
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
| 161 | + /** |
| 162 | + * Tests CriterionUniqueItems. |
| 163 | + */ |
| 164 | + public function testCriterionUniqueItems() { |
| 165 | + $tests = array( |
| 166 | + array( true, array( 'foo', 'bar', 'baz' ), false ), |
| 167 | + array( true, array( 'foo', 'bar', 'baz' ), true ), |
| 168 | + array( false, array( 'foo', 'bar', 'baz', 'foo' ), false ), |
| 169 | + array( false, array( 'foo', 'bar', 'baz', 'foo' ), true ), |
| 170 | + array( false, array( 'foo', 'bar', 'baz', 'FOO' ), false ), |
| 171 | + array( true, array( 'foo', 'bar', 'baz', 'FOO' ), true ), |
| 172 | + array( true, array(), false ), |
| 173 | + ); |
| 174 | + |
| 175 | + foreach ( $tests as $test ) { |
| 176 | + $c = new CriterionUniqueItems( $test[2] ); |
| 177 | + $p = new ListParameter( 'test' ); |
| 178 | + $p->setUserValue( 'test', '' ); |
| 179 | + $p->setValue( $test[1] ); |
| 180 | + |
| 181 | + $this->assertEquals( |
| 182 | + $test[0], |
| 183 | + $c->validate( $p, array() ), |
| 184 | + 'Value "'. $test[1] . '" should ' . ( $test[0] ? '' : 'not ' ) . " have unique items." |
| 185 | + ); |
| 186 | + } |
| 187 | + } |
| 188 | + |
161 | 189 | } |