Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,19 +2,18 @@
/**
* CakeValidationRuleTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Validator
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('CakeValidationRule', 'Model/Validator');
@ -29,8 +28,8 @@ class CakeValidationRuleTest extends CakeTestCase {
/**
* Auxiliary method to test custom validators
*
* @return boolean
**/
* @return bool
*/
public function myTestRule() {
return false;
}
@ -38,8 +37,8 @@ class CakeValidationRuleTest extends CakeTestCase {
/**
* Auxiliary method to test custom validators
*
* @return boolean
**/
* @return bool
*/
public function myTestRule2() {
return true;
}
@ -48,7 +47,7 @@ class CakeValidationRuleTest extends CakeTestCase {
* Auxiliary method to test custom validators
*
* @return string
**/
*/
public function myTestRule3() {
return 'string';
}
@ -59,7 +58,7 @@ class CakeValidationRuleTest extends CakeTestCase {
* @return void
*/
public function testIsValid() {
$def = array('rule' => 'notEmpty', 'message' => 'Can not be empty');
$def = array('rule' => 'notBlank', 'message' => 'Can not be empty');
$data = array(
'fieldName' => ''
);
@ -123,19 +122,19 @@ class CakeValidationRuleTest extends CakeTestCase {
* @return void
*/
public function testIsRequired() {
$def = array('rule' => 'notEmpty', 'required' => true);
$def = array('rule' => 'notBlank', 'required' => true);
$Rule = new CakeValidationRule($def);
$this->assertTrue($Rule->isRequired());
$def = array('rule' => 'notEmpty', 'required' => false);
$def = array('rule' => 'notBlank', 'required' => false);
$Rule = new CakeValidationRule($def);
$this->assertFalse($Rule->isRequired());
$def = array('rule' => 'notEmpty', 'required' => 'create');
$def = array('rule' => 'notBlank', 'required' => 'create');
$Rule = new CakeValidationRule($def);
$this->assertTrue($Rule->isRequired());
$def = array('rule' => 'notEmpty', 'required' => 'update');
$def = array('rule' => 'notBlank', 'required' => 'update');
$Rule = new CakeValidationRule($def);
$this->assertFalse($Rule->isRequired());
@ -157,14 +156,14 @@ class CakeValidationRuleTest extends CakeTestCase {
$Rule = new CakeValidationRule($def);
$this->assertFalse($Rule->isEmptyAllowed());
$def = array('rule' => 'notEmpty', 'allowEmpty' => false, 'on' => 'update');
$def = array('rule' => 'notBlank', 'allowEmpty' => false, 'on' => 'update');
$Rule = new CakeValidationRule($def);
$this->assertTrue($Rule->isEmptyAllowed());
$Rule->isUpdate(true);
$this->assertFalse($Rule->isEmptyAllowed());
$def = array('rule' => 'notEmpty', 'allowEmpty' => false, 'on' => 'create');
$def = array('rule' => 'notBlank', 'allowEmpty' => false, 'on' => 'create');
$Rule = new CakeValidationRule($def);
$this->assertFalse($Rule->isEmptyAllowed());

View file

@ -2,19 +2,18 @@
/**
* CakeValidationSetTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Validator
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('CakeValidationSet', 'Model/Validator');
@ -24,7 +23,17 @@ App::uses('CakeValidationSet', 'Model/Validator');
*
* @package Cake.Test.Case.Model.Validator
*/
class CakeValidationSetTest extends CakeTestCase {
class CakeValidationSetTest extends CakeTestCase {
/**
* override locale to the default (eng).
*
* @return void
*/
public function setUp() {
parent::setUp();
Configure::write('Config.language', 'eng');
}
/**
* testValidate method
@ -32,7 +41,7 @@ class CakeValidationSetTest extends CakeTestCase {
* @return void
*/
public function testValidate() {
$Field = new CakeValidationSet('title', 'notEmpty');
$Field = new CakeValidationSet('title', 'notBlank');
$data = array(
'title' => '',
'body' => 'a body'
@ -42,20 +51,20 @@ class CakeValidationSetTest extends CakeTestCase {
$expected = array('This field cannot be left blank');
$this->assertEquals($expected, $result);
$Field = new CakeValidationSet('body', 'notEmpty');
$Field = new CakeValidationSet('body', 'notBlank');
$result = $Field->validate($data);
$this->assertEmpty($result);
$Field = new CakeValidationSet('nothere', array(
'notEmpty' => array(
'rule' => 'notEmpty',
'notBlank' => array(
'rule' => 'notBlank',
'required' => true
)
));
$result = $Field->validate($data);
$expected = array('notEmpty');
$expected = array('notBlank');
$this->assertEquals($expected, $result);
$Field = new CakeValidationSet('body', array(
@ -74,16 +83,11 @@ class CakeValidationSetTest extends CakeTestCase {
* @return void
*/
public function testGetRule() {
$rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
$rules = array('notBlank' => array('rule' => 'notBlank', 'message' => 'Can not be empty'));
$Field = new CakeValidationSet('title', $rules);
$data = array(
'title' => '',
'body' => 'a body'
);
$result = $Field->getRule('notEmpty');
$result = $Field->getRule('notBlank');
$this->assertInstanceOf('CakeValidationRule', $result);
$this->assertEquals('notEmpty', $result->rule);
$this->assertEquals('notBlank', $result->rule);
$this->assertEquals(null, $result->required);
$this->assertEquals(false, $result->allowEmpty);
$this->assertEquals(null, $result->on);
@ -97,12 +101,12 @@ class CakeValidationSetTest extends CakeTestCase {
* @return void
*/
public function testGetRules() {
$rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
$rules = array('notBlank' => array('rule' => 'notBlank', 'message' => 'Can not be empty'));
$Field = new CakeValidationSet('title', $rules);
$result = $Field->getRules();
$this->assertEquals(array('notEmpty'), array_keys($result));
$this->assertInstanceOf('CakeValidationRule', $result['notEmpty']);
$this->assertEquals(array('notBlank'), array_keys($result));
$this->assertInstanceOf('CakeValidationRule', $result['notBlank']);
}
/**
@ -111,23 +115,23 @@ class CakeValidationSetTest extends CakeTestCase {
* @return void
*/
public function testSetRule() {
$rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
$rules = array('notBlank' => array('rule' => 'notBlank', 'message' => 'Can not be empty'));
$Field = new CakeValidationSet('title', $rules);
$Rule = new CakeValidationRule($rules['notEmpty']);
$Rule = new CakeValidationRule($rules['notBlank']);
$this->assertEquals($Rule, $Field->getRule('notEmpty'));
$this->assertEquals($Rule, $Field->getRule('notBlank'));
$rules = array('validEmail' => array('rule' => 'email', 'message' => 'Invalid email'));
$Rule = new CakeValidationRule($rules['validEmail']);
$Field->setRule('validEmail', $Rule);
$result = $Field->getRules();
$this->assertEquals(array('notEmpty', 'validEmail'), array_keys($result));
$this->assertEquals(array('notBlank', 'validEmail'), array_keys($result));
$rules = array('validEmail' => array('rule' => 'email', 'message' => 'Other message'));
$Rule = new CakeValidationRule($rules['validEmail']);
$Field->setRule('validEmail', $Rule);
$result = $Field->getRules();
$this->assertEquals(array('notEmpty', 'validEmail'), array_keys($result));
$this->assertEquals(array('notBlank', 'validEmail'), array_keys($result));
$result = $Field->getRule('validEmail');
$this->assertInstanceOf('CakeValidationRule', $result);
$this->assertEquals('email', $result->rule);
@ -144,9 +148,9 @@ class CakeValidationSetTest extends CakeTestCase {
* @return void
*/
public function testSetRules() {
$rule = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
$rule = array('notBlank' => array('rule' => 'notBlank', 'message' => 'Can not be empty'));
$Field = new CakeValidationSet('title', $rule);
$RuleEmpty = new CakeValidationRule($rule['notEmpty']);
$RuleEmpty = new CakeValidationRule($rule['notBlank']);
$rule = array('validEmail' => array('rule' => 'email', 'message' => 'Invalid email'));
$RuleEmail = new CakeValidationRule($rule['validEmail']);
@ -161,15 +165,15 @@ class CakeValidationSetTest extends CakeTestCase {
$this->assertEquals(array('validEmail'), array_keys($result));
$this->assertTrue(array_pop($result) instanceof CakeValidationRule);
$rules = array('notEmpty' => $RuleEmpty);
$rules = array('notBlank' => $RuleEmpty);
$Field->setRules($rules, true);
$result = $Field->getRules();
$this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result));
$this->assertEquals(array('validEmail', 'notBlank'), array_keys($result));
$rules = array('notEmpty' => array('rule' => 'notEmpty'));
$rules = array('notBlank' => array('rule' => 'notBlank'));
$Field->setRules($rules, true);
$result = $Field->getRules();
$this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result));
$this->assertEquals(array('validEmail', 'notBlank'), array_keys($result));
$this->assertTrue(array_pop($result) instanceof CakeValidationRule);
$this->assertTrue(array_pop($result) instanceof CakeValidationRule);
}
@ -181,14 +185,14 @@ class CakeValidationSetTest extends CakeTestCase {
*/
public function testArrayAccessGet() {
$Set = new CakeValidationSet('title', array(
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
'notBlank' => array('rule' => 'notBlank', 'required' => true),
'numeric' => array('rule' => 'numeric'),
'other' => array('rule' => array('other', 1)),
));
$rule = $Set['notEmpty'];
$rule = $Set['notBlank'];
$this->assertInstanceOf('CakeValidationRule', $rule);
$this->assertEquals('notEmpty', $rule->rule);
$this->assertEquals('notBlank', $rule->rule);
$rule = $Set['numeric'];
$this->assertInstanceOf('CakeValidationRule', $rule);
@ -206,12 +210,12 @@ class CakeValidationSetTest extends CakeTestCase {
*/
public function testArrayAccessExists() {
$Set = new CakeValidationSet('title', array(
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
'notBlank' => array('rule' => 'notBlank', 'required' => true),
'numeric' => array('rule' => 'numeric'),
'other' => array('rule' => array('other', 1)),
));
$this->assertTrue(isset($Set['notEmpty']));
$this->assertTrue(isset($Set['notBlank']));
$this->assertTrue(isset($Set['numeric']));
$this->assertTrue(isset($Set['other']));
$this->assertFalse(isset($Set['fail']));
@ -224,7 +228,7 @@ class CakeValidationSetTest extends CakeTestCase {
*/
public function testArrayAccessSet() {
$Set = new CakeValidationSet('title', array(
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
'notBlank' => array('rule' => 'notBlank', 'required' => true),
));
$this->assertFalse(isset($Set['other']));
@ -247,19 +251,19 @@ class CakeValidationSetTest extends CakeTestCase {
*/
public function testArrayAccessUnset() {
$Set = new CakeValidationSet('title', array(
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
'notBlank' => array('rule' => 'notBlank', 'required' => true),
'numeric' => array('rule' => 'numeric'),
'other' => array('rule' => array('other', 1)),
));
unset($Set['notEmpty']);
$this->assertFalse(isset($Set['notEmpty']));
unset($Set['notBlank']);
$this->assertFalse(isset($Set['notBlank']));
unset($Set['numeric']);
$this->assertFalse(isset($Set['notEmpty']));
$this->assertFalse(isset($Set['notBlank']));
unset($Set['other']);
$this->assertFalse(isset($Set['notEmpty']));
$this->assertFalse(isset($Set['notBlank']));
}
/**
@ -269,7 +273,7 @@ class CakeValidationSetTest extends CakeTestCase {
*/
public function testIterator() {
$Set = new CakeValidationSet('title', array(
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
'notBlank' => array('rule' => 'notBlank', 'required' => true),
'numeric' => array('rule' => 'numeric'),
'other' => array('rule' => array('other', 1)),
));
@ -277,7 +281,7 @@ class CakeValidationSetTest extends CakeTestCase {
$i = 0;
foreach ($Set as $name => $rule) {
if ($i === 0) {
$this->assertEquals('notEmpty', $name);
$this->assertEquals('notBlank', $name);
}
if ($i === 1) {
$this->assertEquals('numeric', $name);
@ -298,7 +302,7 @@ class CakeValidationSetTest extends CakeTestCase {
*/
public function testCount() {
$Set = new CakeValidationSet('title', array(
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
'notBlank' => array('rule' => 'notBlank', 'required' => true),
'numeric' => array('rule' => 'numeric'),
'other' => array('rule' => array('other', 1)),
));
@ -315,13 +319,13 @@ class CakeValidationSetTest extends CakeTestCase {
*/
public function testRemoveRule() {
$Set = new CakeValidationSet('title', array(
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
'notBlank' => array('rule' => 'notBlank', 'required' => true),
'numeric' => array('rule' => 'numeric'),
'other' => array('rule' => array('other', 1)),
));
$Set->removeRule('notEmpty');
$this->assertFalse(isset($Set['notEmpty']));
$Set->removeRule('notBlank');
$this->assertFalse(isset($Set['notBlank']));
$Set->removeRule('numeric');
$this->assertFalse(isset($Set['numeric']));