Deprecate notEmpty in favor of notBlank.

This commit is contained in:
Mark Scherer 2015-05-17 22:13:04 +02:00
parent ca768399bd
commit 866242643f
2 changed files with 32 additions and 19 deletions

View file

@ -129,15 +129,15 @@ class ValidationTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testNotEmpty() { public function testNotEmpty() {
$this->assertTrue(Validation::notEmpty('abcdefg')); $this->assertTrue(Validation::notBlank('abcdefg'));
$this->assertTrue(Validation::notEmpty('fasdf ')); $this->assertTrue(Validation::notBlank('fasdf '));
$this->assertTrue(Validation::notEmpty('fooo' . chr(243) . 'blabla')); $this->assertTrue(Validation::notBlank('fooo' . chr(243) . 'blabla'));
$this->assertTrue(Validation::notEmpty('abçďĕʑʘπй')); $this->assertTrue(Validation::notBlank('abçďĕʑʘπй'));
$this->assertTrue(Validation::notEmpty('José')); $this->assertTrue(Validation::notBlank('José'));
$this->assertTrue(Validation::notEmpty('é')); $this->assertTrue(Validation::notBlank('é'));
$this->assertTrue(Validation::notEmpty('π')); $this->assertTrue(Validation::notBlank('π'));
$this->assertFalse(Validation::notEmpty("\t ")); $this->assertFalse(Validation::notBlank("\t "));
$this->assertFalse(Validation::notEmpty("")); $this->assertFalse(Validation::notBlank(""));
} }
/** /**
@ -147,14 +147,14 @@ class ValidationTest extends CakeTestCase {
*/ */
public function testNotEmptyISO88591AppEncoding() { public function testNotEmptyISO88591AppEncoding() {
Configure::write('App.encoding', 'ISO-8859-1'); Configure::write('App.encoding', 'ISO-8859-1');
$this->assertTrue(Validation::notEmpty('abcdefg')); $this->assertTrue(Validation::notBlank('abcdefg'));
$this->assertTrue(Validation::notEmpty('fasdf ')); $this->assertTrue(Validation::notBlank('fasdf '));
$this->assertTrue(Validation::notEmpty('fooo' . chr(243) . 'blabla')); $this->assertTrue(Validation::notBlank('fooo' . chr(243) . 'blabla'));
$this->assertTrue(Validation::notEmpty('abçďĕʑʘπй')); $this->assertTrue(Validation::notBlank('abçďĕʑʘπй'));
$this->assertTrue(Validation::notEmpty('José')); $this->assertTrue(Validation::notBlank('José'));
$this->assertTrue(Validation::notEmpty(utf8_decode('José'))); $this->assertTrue(Validation::notBlank(utf8_decode('José')));
$this->assertFalse(Validation::notEmpty("\t ")); $this->assertFalse(Validation::notBlank("\t "));
$this->assertFalse(Validation::notEmpty("")); $this->assertFalse(Validation::notBlank(""));
} }
/** /**

View file

@ -48,6 +48,19 @@ class Validation {
*/ */
public static $errors = array(); public static $errors = array();
/**
* Backwards compatibility wrapper for Validation::notBlank().
*
* @param string|array $check Value to check.
* @return bool Success.
* @deprecated 2.7.0 Use Validation::notBlank() instead.
* @see Validation::notBlank()
*/
public function notEmpty($check) {
trigger_error('Validation::notEmpty() is deprecated. Use Validation::notBlank() instead.', E_USER_DEPRECATED);
return self::notBlank($check);
}
/** /**
* Checks that a string contains something other than whitespace * Checks that a string contains something other than whitespace
* *
@ -59,7 +72,7 @@ class Validation {
* @param string|array $check Value to check * @param string|array $check Value to check
* @return bool Success * @return bool Success
*/ */
public static function notEmpty($check) { public static function notBlank($check) {
if (is_array($check)) { if (is_array($check)) {
extract(self::_defaults($check)); extract(self::_defaults($check));
} }