Skip to content
Permalink
Browse files

New Validation::(min|max)ByteLength() addition

  • Loading branch information...
tersmitten authored and chinpei215 committed Dec 16, 2016
1 parent 9999d36 commit 6818268a27e010af960a7e3f1cc5b56600bef84d
Showing with 52 additions and 2 deletions.
  1. +28 −0 lib/Cake/Test/Case/Utility/ValidationTest.php
  2. +24 −2 lib/Cake/Utility/Validation.php
@@ -1825,6 +1825,20 @@ public function testMaxLength() {
$this->assertFalse(Validation::maxLength('ÆΔΩЖÇ', 3));
}
/**
* maxLengthBytes method
*
* @return void
*/
public function testMaxLengthBytes() {
$this->assertTrue(Validation::maxLengthBytes('ab', 3));
$this->assertTrue(Validation::maxLengthBytes('abc', 3));
$this->assertTrue(Validation::maxLengthBytes('ÆΔΩЖÇ', 10));
$this->assertTrue(Validation::maxLengthBytes('ÆΔΩЖÇ', 11));
$this->assertFalse(Validation::maxLengthBytes('abcd', 3));
$this->assertFalse(Validation::maxLengthBytes('ÆΔΩЖÇ', 9));
}
/**
* testMinLength method
*
@@ -1839,6 +1853,20 @@ public function testMinLength() {
$this->assertTrue(Validation::minLength('ÆΔΩЖÇ', 2));
}
/**
* minLengthBytes method
*
* @return void
*/
public function testMinLengthBytes() {
$this->assertFalse(Validation::minLengthBytes('ab', 3));
$this->assertFalse(Validation::minLengthBytes('ÆΔΩЖÇ', 11));
$this->assertTrue(Validation::minLengthBytes('abc', 3));
$this->assertTrue(Validation::minLengthBytes('abcd', 3));
$this->assertTrue(Validation::minLengthBytes('ÆΔΩЖÇ', 10));
$this->assertTrue(Validation::minLengthBytes('ÆΔΩЖÇ', 9));
}
/**
* testUrl method
*
@@ -539,7 +539,7 @@ public static function ip($check, $type = 'both') {
}
/**
* Checks whether the length of a string is greater or equal to a minimal length.
* Checks whether the length of a string (in character) is greater or equal to a minimal length.
*
* @param string $check The string to test
* @param int $min The minimal string length
@@ -550,7 +550,7 @@ public static function minLength($check, $min) {
}
/**
* Checks whether the length of a string is smaller or equal to a maximal length..
* Checks whether the length of a string (in character) is smaller or equal to a maximal length..
*
* @param string $check The string to test
* @param int $max The maximal string length
@@ -560,6 +560,28 @@ public static function maxLength($check, $max) {
return mb_strlen($check) <= $max;
}
/**
* Checks whether the length of a string (in bytes) is greater or equal to a minimal length.
*
* @param string $check The string to test
* @param int $min The minimal string length
* @return bool Success
*/
public static function minLengthBytes($check, $min) {
return strlen($check) >= $min;
}
/**
* Checks whether the length of a string (in bytes) is smaller or equal to a maximal length..
*
* @param string $check The string to test
* @param int $max The maximal string length
* @return bool Success
*/
public static function maxLengthBytes($check, $max) {
return strlen($check) <= $max;
}
/**
* Checks that a value is a monetary amount.
*

0 comments on commit 6818268

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.