Index: trunk/extensions/Validator/test/ValidatorCriteriaTests.php |
— | — | @@ -63,5 +63,35 @@ |
64 | 64 | ); |
65 | 65 | } |
66 | 66 | } |
| 67 | + |
| 68 | + /** |
| 69 | + * Tests CriterionInRange. |
| 70 | + */ |
| 71 | + public function testCriterionInRange() { |
| 72 | + $tests = array( |
| 73 | + array( true, '42', Parameter::TYPE_INTEGER, 0, 99 ), |
| 74 | + array( false, '42', Parameter::TYPE_INTEGER, 0, 9 ), |
| 75 | + array( true, '42', Parameter::TYPE_INTEGER, 0, false ), |
| 76 | + array( true, '42', Parameter::TYPE_INTEGER, false, false ), |
| 77 | + array( false, '42', Parameter::TYPE_INTEGER, false, 9 ), |
| 78 | + array( false, '42', Parameter::TYPE_INTEGER, 99, false ), |
| 79 | + array( false, '42', Parameter::TYPE_INTEGER, 99, 100 ), |
| 80 | + array( true, '42', Parameter::TYPE_INTEGER, 42, 42 ), |
| 81 | + array( false, '4.2', Parameter::TYPE_FLOAT, 42, 42 ), |
| 82 | + array( true, '4.2', Parameter::TYPE_FLOAT, 4.2, 4.2 ), |
| 83 | + array( true, '4.2', Parameter::TYPE_FLOAT, 0, 9 ), |
| 84 | + ); |
| 85 | + |
| 86 | + foreach ( $tests as $test ) { |
| 87 | + $c = new CriterionInRange( $test[3], $test[4] ); |
| 88 | + $p = new Parameter( 'test' ); |
| 89 | + $p->setUserValue( 'test', $test[1] ); |
| 90 | + $this->assertEquals( |
| 91 | + $test[0], |
| 92 | + $c->validate( $p, array() )->isValid(), |
| 93 | + 'Value "'. $test[1] . '" should ' . ( $test[0] ? '' : 'not ' ) . "be between '$test[3]' and '$test[4]'." |
| 94 | + ); |
| 95 | + } |
| 96 | + } |
67 | 97 | |
68 | 98 | } |
Index: trunk/extensions/Validator/includes/criteria/CriterionInRange.php |
— | — | @@ -54,7 +54,7 @@ |
55 | 55 | return false; |
56 | 56 | } |
57 | 57 | |
58 | | - $value = (int)$value; |
| 58 | + $value = (float)$value; |
59 | 59 | |
60 | 60 | return ( $this->upperBound === false || $value <= $this->upperBound ) |
61 | 61 | && ( $this->lowerBound === false || $value >= $this->lowerBound ); |