Merge branch '2.6' of github.com:cakephp/cakephp into 2.6

This commit is contained in:
mark_story 2014-05-27 20:55:16 -04:00
commit 2546b79c62
11 changed files with 76 additions and 36 deletions

View file

@ -45,6 +45,8 @@ class MemcachedEngine extends CacheEngine {
* - serialize = string, default => php. The serializer engine used to serialize data. * - serialize = string, default => php. The serializer engine used to serialize data.
* Available engines are php, igbinary and json. Beside php, the memcached extension * Available engines are php, igbinary and json. Beside php, the memcached extension
* must be compiled with the appropriate serializer support. * must be compiled with the appropriate serializer support.
* - options - Additional options for the memcached client. Should be an array of option => value.
* Use the Memcached::OPT_* constants as keys.
* *
* @var array * @var array
*/ */
@ -92,7 +94,8 @@ class MemcachedEngine extends CacheEngine {
'persistent' => false, 'persistent' => false,
'login' => null, 'login' => null,
'password' => null, 'password' => null,
'serialize' => 'php' 'serialize' => 'php',
'options' => array()
); );
parent::init($settings); parent::init($settings);
@ -128,6 +131,11 @@ class MemcachedEngine extends CacheEngine {
} }
$this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']); $this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']);
} }
if (is_array($this->settings['options'])) {
foreach ($this->settings['options'] as $opt => $value) {
$this->_Memcached->setOption($opt, $value);
}
}
return true; return true;
} }

View file

@ -142,8 +142,8 @@ class Model extends Object implements CakeEventListener {
* *
* {{{ * {{{
* public $validate = array( * public $validate = array(
* 'age' => array( * 'length' => array(
* 'rule' => array('between', 5, 25) * 'rule' => array('lengthBetween', 5, 25)
* ) * )
* ); * );
* }}} * }}}
@ -171,9 +171,9 @@ class Model extends Object implements CakeEventListener {
* *
* {{{ * {{{
* public $validate = array( * public $validate = array(
* 'age' => array( * 'length' => array(
* 'rule' => array('between', 5, 25), * 'rule' => array('lengthBetween', 5, 15),
* 'message' => array('The age must be between %d and %d.') * 'message' => array('Between %d to %d characters')
* ) * )
* ); * );
* }}} * }}}

View file

@ -539,7 +539,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
* ->add('user_id', 'valid', array('rule' => 'numeric', 'message' => 'Invalid User')) * ->add('user_id', 'valid', array('rule' => 'numeric', 'message' => 'Invalid User'))
* *
* $validator->add('password', array( * $validator->add('password', array(
* 'size' => array('rule' => array('between', 8, 20)), * 'size' => array('rule' => array('lengthBetween', 8, 20)),
* 'hasSpecialCharacter' => array('rule' => 'validateSpecialchar', 'message' => 'not valid') * 'hasSpecialCharacter' => array('rule' => 'validateSpecialchar', 'message' => 'not valid')
* )); * ));
* }}} * }}}

View file

@ -186,7 +186,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
* {{{ * {{{
* $set * $set
* ->setRule('required', array('rule' => 'notEmpty', 'required' => true)) * ->setRule('required', array('rule' => 'notEmpty', 'required' => true))
* ->setRule('inRange', array('rule' => array('between', 4, 10)) * ->setRule('between', array('rule' => array('lengthBetween', 4, 10))
* }}} * }}}
* *
* @param string $name The name under which the rule should be set * @param string $name The name under which the rule should be set

View file

@ -103,7 +103,8 @@ class MemcachedEngineTest extends CakeTestCase {
'login' => null, 'login' => null,
'password' => null, 'password' => null,
'groups' => array(), 'groups' => array(),
'serialize' => 'php' 'serialize' => 'php',
'options' => array()
); );
$this->assertEquals($expecting, $settings); $this->assertEquals($expecting, $settings);
} }
@ -133,6 +134,23 @@ class MemcachedEngineTest extends CakeTestCase {
$this->assertTrue($MemcachedCompressed->getMemcached()->getOption(Memcached::OPT_COMPRESSION)); $this->assertTrue($MemcachedCompressed->getMemcached()->getOption(Memcached::OPT_COMPRESSION));
} }
/**
* test setting options
*
* @return void
*/
public function testOptionsSetting() {
$memcached = new TestMemcachedEngine();
$memcached->init(array(
'engine' => 'Memcached',
'servers' => array('127.0.0.1:11211'),
'options' => array(
Memcached::OPT_BINARY_PROTOCOL => true
)
));
$this->assertEquals(1, $memcached->getMemcached()->getOption(Memcached::OPT_BINARY_PROTOCOL));
}
/** /**
* test accepts only valid serializer engine * test accepts only valid serializer engine
* *

View file

@ -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('25', 'y', '19', '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('notEmpty' => 'notEmpty', 'maxLength' => 'maxLength'); $expected = array('notEmpty' => 'notEmpty', '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', '25', '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('25', '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('notEmpty' => 'notEmpty', '_skipFields' => true); $expected = array('notEmpty' => 'notEmpty', '_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('25', '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('notEmpty' => 'notEmpty', '_skipFields' => true); $expected = array('notEmpty' => 'notEmpty', '_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', '11', 's')); ->will($this->onConsecutiveCalls('36', '25', 'n', '11', 's'));
$this->Task->interactive = true; $this->Task->interactive = true;
$Model = $this->getMock('Model'); $Model = $this->getMock('Model');
$Model->primaryKey = 'id'; $Model->primaryKey = 'id';

View file

@ -767,7 +767,7 @@ class ModelValidationTest extends BaseModelTest {
'last' => false 'last' => false
), ),
'between' => array( 'between' => array(
'rule' => array('between', 5, 15), 'rule' => array('lengthBetween', 5, 15),
'message' => array('You may enter up to %s chars (minimum is %s chars)', 14, 6) 'message' => array('You may enter up to %s chars (minimum is %s chars)', 14, 6)
) )
) )
@ -1844,7 +1844,7 @@ class ModelValidationTest extends BaseModelTest {
$set = array( $set = array(
'numeric' => array('rule' => 'numeric', 'allowEmpty' => false), 'numeric' => array('rule' => 'numeric', 'allowEmpty' => false),
'range' => array('rule' => array('between', 1, 5), 'allowEmpty' => false), 'between' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false),
); );
$Validator['other'] = $set; $Validator['other'] = $set;
$rules = $Validator['other']; $rules = $Validator['other'];
@ -1853,7 +1853,7 @@ class ModelValidationTest extends BaseModelTest {
$validators = $rules->getRules(); $validators = $rules->getRules();
$this->assertCount(2, $validators); $this->assertCount(2, $validators);
$this->assertEquals('numeric', $validators['numeric']->rule); $this->assertEquals('numeric', $validators['numeric']->rule);
$this->assertEquals(array('between', 1, 5), $validators['range']->rule); $this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule);
$Validator['new'] = new CakeValidationSet('new', $set, array()); $Validator['new'] = new CakeValidationSet('new', $set, array());
$rules = $Validator['new']; $rules = $Validator['new'];
@ -1862,7 +1862,7 @@ class ModelValidationTest extends BaseModelTest {
$validators = $rules->getRules(); $validators = $rules->getRules();
$this->assertCount(2, $validators); $this->assertCount(2, $validators);
$this->assertEquals('numeric', $validators['numeric']->rule); $this->assertEquals('numeric', $validators['numeric']->rule);
$this->assertEquals(array('between', 1, 5), $validators['range']->rule); $this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule);
} }
/** /**
@ -1917,7 +1917,7 @@ class ModelValidationTest extends BaseModelTest {
$set = array( $set = array(
'numeric' => array('rule' => 'numeric', 'allowEmpty' => false), 'numeric' => array('rule' => 'numeric', 'allowEmpty' => false),
'range' => array('rule' => array('between', 1, 5), 'allowEmpty' => false), 'range' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false),
); );
$Validator['other'] = $set; $Validator['other'] = $set;
$this->assertCount(4, $Validator); $this->assertCount(4, $Validator);
@ -1938,14 +1938,14 @@ class ModelValidationTest extends BaseModelTest {
$Validator = $TestModel->validator(); $Validator = $TestModel->validator();
$Validator->add('other', 'numeric', array('rule' => 'numeric', 'allowEmpty' => false)); $Validator->add('other', 'numeric', array('rule' => 'numeric', 'allowEmpty' => false));
$Validator->add('other', 'range', array('rule' => array('between', 1, 5), 'allowEmpty' => false)); $Validator->add('other', 'between', array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false));
$rules = $Validator['other']; $rules = $Validator['other'];
$this->assertEquals('other', $rules->field); $this->assertEquals('other', $rules->field);
$validators = $rules->getRules(); $validators = $rules->getRules();
$this->assertCount(2, $validators); $this->assertCount(2, $validators);
$this->assertEquals('numeric', $validators['numeric']->rule); $this->assertEquals('numeric', $validators['numeric']->rule);
$this->assertEquals(array('between', 1, 5), $validators['range']->rule); $this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule);
} }
/** /**
@ -1962,13 +1962,13 @@ class ModelValidationTest extends BaseModelTest {
$this->assertFalse(isset($Validator['title'])); $this->assertFalse(isset($Validator['title']));
$Validator->add('other', 'numeric', array('rule' => 'numeric', 'allowEmpty' => false)); $Validator->add('other', 'numeric', array('rule' => 'numeric', 'allowEmpty' => false));
$Validator->add('other', 'range', array('rule' => array('between', 1, 5), 'allowEmpty' => false)); $Validator->add('other', 'between', array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false));
$this->assertTrue(isset($Validator['other'])); $this->assertTrue(isset($Validator['other']));
$Validator->remove('other', 'numeric'); $Validator->remove('other', 'numeric');
$this->assertTrue(isset($Validator['other'])); $this->assertTrue(isset($Validator['other']));
$this->assertFalse(isset($Validator['other']['numeric'])); $this->assertFalse(isset($Validator['other']['numeric']));
$this->assertTrue(isset($Validator['other']['range'])); $this->assertTrue(isset($Validator['other']['between']));
} }
/** /**
@ -2126,7 +2126,7 @@ class ModelValidationTest extends BaseModelTest {
$set = array( $set = array(
'numeric' => array('rule' => 'numeric', 'allowEmpty' => false), 'numeric' => array('rule' => 'numeric', 'allowEmpty' => false),
'range' => array('rule' => array('between', 1, 5), 'allowEmpty' => false), 'between' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false),
); );
$Validator->add('other', $set); $Validator->add('other', $set);
@ -2136,11 +2136,11 @@ class ModelValidationTest extends BaseModelTest {
$validators = $rules->getRules(); $validators = $rules->getRules();
$this->assertCount(2, $validators); $this->assertCount(2, $validators);
$this->assertEquals('numeric', $validators['numeric']->rule); $this->assertEquals('numeric', $validators['numeric']->rule);
$this->assertEquals(array('between', 1, 5), $validators['range']->rule); $this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule);
$set = new CakeValidationSet('other', array( $set = new CakeValidationSet('other', array(
'a' => array('rule' => 'numeric', 'allowEmpty' => false), 'a' => array('rule' => 'numeric', 'allowEmpty' => false),
'b' => array('rule' => array('between', 1, 5), 'allowEmpty' => false), 'b' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false),
)); ));
$Validator->add('other', $set); $Validator->add('other', $set);

View file

@ -203,17 +203,17 @@ class ValidationTest extends CakeTestCase {
} }
/** /**
* testBetween method * testLengthBetween method
* *
* @return void * @return void
*/ */
public function testBetween() { public function testLengthBetween() {
$this->assertTrue(Validation::between('abcdefg', 1, 7)); $this->assertTrue(Validation::lengthBetween('abcdefg', 1, 7));
$this->assertTrue(Validation::between('', 0, 7)); $this->assertTrue(Validation::lengthBetween('', 0, 7));
$this->assertTrue(Validation::between('אกあアꀀ豈', 1, 7)); $this->assertTrue(Validation::lengthBetween('אกあアꀀ豈', 1, 7));
$this->assertFalse(Validation::between('abcdefg', 1, 6)); $this->assertFalse(Validation::lengthBetween('abcdefg', 1, 6));
$this->assertFalse(Validation::between('ÆΔΩЖÇ', 1, 3)); $this->assertFalse(Validation::lengthBetween('ÆΔΩЖÇ', 1, 3));
} }
/** /**

View file

@ -36,7 +36,7 @@ class Extract extends AppModel {
'message' => 'double "quoted" validation' 'message' => 'double "quoted" validation'
), ),
'between' => array( 'between' => array(
'rule' => array('between', 5, 15), 'rule' => array('lengthBetween', 5, 15),
'message' => "single 'quoted' validation" 'message' => "single 'quoted' validation"
) )
), ),

View file

@ -38,7 +38,7 @@ class PersisterOne extends AppModel {
'message' => 'Post title is required' 'message' => 'Post title is required'
), ),
'between' => array( 'between' => array(
'rule' => array('between', 5, 15), 'rule' => array('lengthBetween', 5, 15),
'message' => array('You may enter up to %s chars (minimum is %s chars)', 14, 6) 'message' => array('You may enter up to %s chars (minimum is %s chars)', 14, 6)
) )
), ),

View file

@ -104,11 +104,25 @@ class Validation {
* @param integer $max Maximum value in range (inclusive) * @param integer $max Maximum value in range (inclusive)
* @return boolean Success * @return boolean Success
*/ */
public static function between($check, $min, $max) { public static function lengthBetween($check, $min, $max) {
$length = mb_strlen($check); $length = mb_strlen($check);
return ($length >= $min && $length <= $max); return ($length >= $min && $length <= $max);
} }
/**
* Alias of Validator::lengthBetween() for backwards compatibility.
*
* @see Validator::lengthBetween()
* @deprecated Deprecated since 2.6, use Validator::lengthBetween() instead.
* @param string $check Value to check for length
* @param integer $min Minimum value in range (inclusive)
* @param integer $max Maximum value in range (inclusive)
* @return boolean Success
*/
public static function between($check, $min, $max) {
return self::lengthBetween($check, $min, $max);
}
/** /**
* Returns true if field is left blank -OR- only whitespace characters are present in its value * Returns true if field is left blank -OR- only whitespace characters are present in its value
* Whitespace characters include Space, Tab, Carriage Return, Newline * Whitespace characters include Space, Tab, Carriage Return, Newline