http://www.mediawiki.org/wiki/Special:Code/MediaWiki/91963

Revision: 91963
Author:   jeroendedauw
Date:     2011-07-12 14:26:15 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
added tests for length criterion

Modified Paths:
--------------
    trunk/extensions/Validator/includes/criteria/CriterionHasLength.php
    trunk/extensions/Validator/test/ValidatorCriteriaTests.php

Modified: trunk/extensions/Validator/includes/criteria/CriterionHasLength.php
===================================================================
--- trunk/extensions/Validator/includes/criteria/CriterionHasLength.php 
2011-07-12 14:17:21 UTC (rev 91962)
+++ trunk/extensions/Validator/includes/criteria/CriterionHasLength.php 
2011-07-12 14:26:15 UTC (rev 91963)
@@ -19,8 +19,8 @@
        /**
         * Constructor.
         * 
-        * @param integer $lowerBound
-        * @param mixed $upperBound
+        * @param integer $lowerBound Null for no lower bound (since 0.4.8).
+        * @param mixed $upperBound False for same value as lower bound. Null 
for no upper bound (since 0.4.8).
         * 
         * @since 0.4
         */
@@ -36,7 +36,8 @@
         */     
        protected function doValidation( $value, Parameter $parameter, array 
$parameters ) {
                $strlen = strlen( $value );
-               return $strlen <= $this->upperBound && $strlen >= 
$this->lowerBound;
+               return ( is_null( $this->upperBound ) || $strlen <= 
$this->upperBound )
+                       && ( is_null( $this->lowerBound ) || $strlen >= 
$this->lowerBound );
        }
        
        /**

Modified: trunk/extensions/Validator/test/ValidatorCriteriaTests.php
===================================================================
--- trunk/extensions/Validator/test/ValidatorCriteriaTests.php  2011-07-12 
14:17:21 UTC (rev 91962)
+++ trunk/extensions/Validator/test/ValidatorCriteriaTests.php  2011-07-12 
14:26:15 UTC (rev 91963)
@@ -18,13 +18,24 @@
                $tests = array(
                        array( true, 0, 5, 'foo' ),
                        array( false, 0, 5, 'foobar' ),
+                       array( false, 3, null, 'a' ),
+                       array( true, 3, null, 
'aw<dfxdfwdxgtdfgdfhfdgsfdxgtffds' ),
+                       array( true, null, null, 
'aw<dfxdfwdxgtdfgdfhfdgsfdxgtffds' ),
+                       array( true, null, null, '' ),
+                       array( false, 2, 3, '' ),
+                       array( true, 3, false, 'foo' ),
+                       array( false, 3, false, 'foobar' ),
                );
                
                foreach ( $tests as $test ) {
                        $c = new CriterionHasLength( $test[1], $test[2] );
                        $p = new Parameter( 'test' );
                        $p->setUserValue( 'test', $test[3] );
-                       $this->assertEquals( $test[0], $c->validate( $p, 
array() )->isValid() );
+                       $this->assertEquals(
+                               $test[0],
+                               $c->validate( $p, array() )->isValid(),
+                               'Lenght of value "'. $test[3] . '" should ' . ( 
$test[0] ? '' : 'not ' ) . "be between $test[1] and $test[2] ."
+                       );
                }
        }
 


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to