mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #10126 from chinpei215/2.x-min-length-bytes
Add Validation::minBytes() and Validation::maxBytes() Resolve build errors in #9882
This commit is contained in:
commit
be87a157b6
3 changed files with 57 additions and 7 deletions
|
@ -315,7 +315,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
$this->Task->initValidations();
|
$this->Task->initValidations();
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->expects($this->any())->method('in')
|
$this->Task->expects($this->any())->method('in')
|
||||||
->will($this->onConsecutiveCalls('24', 'y', '18', 'n'));
|
->will($this->onConsecutiveCalls('26', 'y', '18', 'n'));
|
||||||
|
|
||||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||||
$expected = array('notBlank' => 'notBlank', 'maxLength' => 'maxLength');
|
$expected = array('notBlank' => 'notBlank', 'maxLength' => 'maxLength');
|
||||||
|
@ -333,7 +333,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
|
|
||||||
$this->Task->expects($this->any())->method('in')
|
$this->Task->expects($this->any())->method('in')
|
||||||
->will($this->onConsecutiveCalls('999999', '24', 'n'));
|
->will($this->onConsecutiveCalls('999999', '26', 'n'));
|
||||||
|
|
||||||
$this->Task->expects($this->at(10))->method('out')
|
$this->Task->expects($this->at(10))->method('out')
|
||||||
->with($this->stringContains('make a valid'));
|
->with($this->stringContains('make a valid'));
|
||||||
|
@ -368,7 +368,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
$this->Task->initValidations();
|
$this->Task->initValidations();
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->expects($this->any())->method('in')
|
$this->Task->expects($this->any())->method('in')
|
||||||
->will($this->onConsecutiveCalls('24', 'y', 's'));
|
->will($this->onConsecutiveCalls('26', 'y', 's'));
|
||||||
|
|
||||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||||
$expected = array('notBlank' => 'notBlank', '_skipFields' => true);
|
$expected = array('notBlank' => 'notBlank', '_skipFields' => true);
|
||||||
|
@ -384,7 +384,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
$this->Task->initValidations();
|
$this->Task->initValidations();
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->expects($this->any())->method('in')
|
$this->Task->expects($this->any())->method('in')
|
||||||
->will($this->onConsecutiveCalls('24', 's'));
|
->will($this->onConsecutiveCalls('26', 's'));
|
||||||
|
|
||||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||||
$expected = array('notBlank' => 'notBlank', '_skipFields' => true);
|
$expected = array('notBlank' => 'notBlank', '_skipFields' => true);
|
||||||
|
@ -400,7 +400,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
public function testInteractiveDoValidationWithSkipping() {
|
public function testInteractiveDoValidationWithSkipping() {
|
||||||
$this->Task->expects($this->any())
|
$this->Task->expects($this->any())
|
||||||
->method('in')
|
->method('in')
|
||||||
->will($this->onConsecutiveCalls('35', '24', 'n', '10', 's'));
|
->will($this->onConsecutiveCalls('37', '26', 'n', '10', 's'));
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$Model = $this->getMock('Model');
|
$Model = $this->getMock('Model');
|
||||||
$Model->primaryKey = 'id';
|
$Model->primaryKey = 'id';
|
||||||
|
|
|
@ -1825,6 +1825,20 @@ class ValidationTest extends CakeTestCase {
|
||||||
$this->assertFalse(Validation::maxLength('ÆΔΩЖÇ', 3));
|
$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
|
* testMinLength method
|
||||||
*
|
*
|
||||||
|
@ -1839,6 +1853,20 @@ class ValidationTest extends CakeTestCase {
|
||||||
$this->assertTrue(Validation::minLength('ÆΔΩЖÇ', 2));
|
$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
|
* testUrl method
|
||||||
*
|
*
|
||||||
|
|
|
@ -539,7 +539,7 @@ class Validation {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the length of a string is greater or equal to a minimal length.
|
* Checks whether the length of a string (in characters) is greater or equal to a minimal length.
|
||||||
*
|
*
|
||||||
* @param string $check The string to test
|
* @param string $check The string to test
|
||||||
* @param int $min The minimal string length
|
* @param int $min The minimal string length
|
||||||
|
@ -550,7 +550,7 @@ class Validation {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the length of a string is smaller or equal to a maximal length..
|
* Checks whether the length of a string (in characters) is smaller or equal to a maximal length..
|
||||||
*
|
*
|
||||||
* @param string $check The string to test
|
* @param string $check The string to test
|
||||||
* @param int $max The maximal string length
|
* @param int $max The maximal string length
|
||||||
|
@ -560,6 +560,28 @@ class Validation {
|
||||||
return mb_strlen($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.
|
* Checks that a value is a monetary amount.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue