r92184 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92183‎ | r92184 | r92185 >
Date:19:59, 14 July 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added test
Modified paths:
  • /trunk/extensions/Validator/includes/criteria/CriterionInRange.php (modified) (history)
  • /trunk/extensions/Validator/test/ValidatorCriteriaTests.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/test/ValidatorCriteriaTests.php
@@ -63,5 +63,35 @@
6464 );
6565 }
6666 }
 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+ }
6797
6898 }
Index: trunk/extensions/Validator/includes/criteria/CriterionInRange.php
@@ -54,7 +54,7 @@
5555 return false;
5656 }
5757
58 - $value = (int)$value;
 58+ $value = (float)$value;
5959
6060 return ( $this->upperBound === false || $value <= $this->upperBound )
6161 && ( $this->lowerBound === false || $value >= $this->lowerBound );

Follow-up revisions

RevisionCommit summaryAuthorDate
r92188fu r92184jeroendedauw20:24, 14 July 2011