Renaming CakeField to CakeValidationSet

This commit is contained in:
Jose Lorenzo Rodriguez 2012-05-05 13:43:40 -04:30
parent 843d95bb77
commit b6c8a345e7
5 changed files with 20 additions and 27 deletions

View file

@ -18,7 +18,7 @@
* @since CakePHP(tm) v 2.2.0 * @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
App::uses('CakeField', 'Model/Validator'); App::uses('CakeValidationSet', 'Model/Validator');
App::uses('CakeRule', 'Model/Validator'); App::uses('CakeRule', 'Model/Validator');
/** /**
@ -30,14 +30,7 @@ App::uses('CakeRule', 'Model/Validator');
class ModelValidator { class ModelValidator {
/** /**
* Holds the validationErrors * Holds the CakeValidationSet objects array
*
* @var array
*/
public $validationErrors = array();
/**
* Holds the CakeField objects array
* *
* @var array * @var array
*/ */
@ -279,7 +272,7 @@ class ModelValidator {
* Gets all fields if $name is null (default), or the field for fieldname $name if it's found. * Gets all fields if $name is null (default), or the field for fieldname $name if it's found.
* *
* @param string $name [optional] The fieldname to fetch. Defaults to null. * @param string $name [optional] The fieldname to fetch. Defaults to null.
* @return mixed Either array of CakeField objects , single object for $name or false when $name not present in fields * @return mixed Either array of CakeValidationSet objects , single object for $name or false when $name not present in fields
*/ */
public function getFields($name = null) { public function getFields($name = null) {
if ($name !== null && !empty($this->_fields[$name])) { if ($name !== null && !empty($this->_fields[$name])) {
@ -291,7 +284,7 @@ class ModelValidator {
} }
/** /**
* Sets the CakeField instances from the Model::$validate property after processing the fieldList and whiteList. * Sets the CakeValidationSet instances from the Model::$validate property after processing the fieldList and whiteList.
* If Model::$validate is not set or empty, this method returns false. True otherwise. * If Model::$validate is not set or empty, this method returns false. True otherwise.
* *
* @return boolean True if Model::$validate was processed, false otherwise * @return boolean True if Model::$validate was processed, false otherwise
@ -311,7 +304,7 @@ class ModelValidator {
$this->_fields = array(); $this->_fields = array();
$methods = $this->getMethods(); $methods = $this->getMethods();
foreach ($this->_validate as $fieldName => $ruleSet) { foreach ($this->_validate as $fieldName => $ruleSet) {
$this->_fields[$fieldName] = new CakeField($fieldName, $ruleSet, $methods); $this->_fields[$fieldName] = new CakeValidationSet($fieldName, $ruleSet, $methods);
} }
return true; return true;
} }

View file

@ -19,7 +19,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
App::uses('ModelValidator', 'Model'); App::uses('ModelValidator', 'Model');
App::uses('CakeField', 'Model/Validator'); App::uses('CakeValidationSet', 'Model/Validator');
App::uses('Validation', 'Utility'); App::uses('Validation', 'Utility');
/** /**

View file

@ -22,12 +22,12 @@ App::uses('ModelValidator', 'Model');
App::uses('CakeRule', 'Model/Validator'); App::uses('CakeRule', 'Model/Validator');
/** /**
* CakeField object. * CakeValidationSet object.
* *
* @package Cake.Model.Validator * @package Cake.Model.Validator
* @link http://book.cakephp.org/2.0/en/data-validation.html * @link http://book.cakephp.org/2.0/en/data-validation.html
*/ */
class CakeField { class CakeValidationSet {
/** /**
* Holds the ValidationRule objects * Holds the ValidationRule objects

View file

@ -34,7 +34,7 @@ class ModelTest extends PHPUnit_Framework_TestSuite {
public static function suite() { public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('All Model related class tests'); $suite = new PHPUnit_Framework_TestSuite('All Model related class tests');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'Validator' . DS .'CakeFieldTest.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'Validator' . DS .'CakeValidationSetTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'Validator' . DS .'CakeRuleTest.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'Validator' . DS .'CakeRuleTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'ModelReadTest.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'ModelReadTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'ModelWriteTest.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'ModelWriteTest.php');

View file

@ -1,6 +1,6 @@
<?php <?php
/** /**
* CakeFieldTest file * CakeValidationSetTest file
* *
* PHP 5 * PHP 5
* *
@ -17,14 +17,14 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
App::uses('CakeField', 'Model/Validator'); App::uses('CakeValidationSet', 'Model/Validator');
/** /**
* CakeFieldTest * CakeValidationSetTest
* *
* @package Cake.Test.Case.Model.Validator * @package Cake.Test.Case.Model.Validator
*/ */
class CakeFieldTest extends CakeTestModel { class CakeValidationSetTest extends CakeTestModel {
/** /**
* setUp method * setUp method
@ -41,7 +41,7 @@ class CakeFieldTest extends CakeTestModel {
* @return void * @return void
*/ */
public function testValidate() { public function testValidate() {
$Field = new CakeField('title', 'notEmpty'); $Field = new CakeValidationSet('title', 'notEmpty');
$data = array( $data = array(
'title' => '', 'title' => '',
'body' => 'a body' 'body' => 'a body'
@ -51,12 +51,12 @@ class CakeFieldTest extends CakeTestModel {
$expected = array('This field cannot be left blank'); $expected = array('This field cannot be left blank');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$Field = new CakeField('body', 'notEmpty'); $Field = new CakeValidationSet('body', 'notEmpty');
$result = $Field->validate($data); $result = $Field->validate($data);
$this->assertEmpty($result); $this->assertEmpty($result);
$Field = new CakeField('nothere', array('notEmpty' => array('rule' => 'notEmpty', 'required' => true))); $Field = new CakeValidationSet('nothere', array('notEmpty' => array('rule' => 'notEmpty', 'required' => true)));
$result = $Field->validate($data); $result = $Field->validate($data);
$expected = array('notEmpty'); $expected = array('notEmpty');
@ -70,7 +70,7 @@ class CakeFieldTest extends CakeTestModel {
*/ */
public function testGetRule() { public function testGetRule() {
$rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty')); $rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
$Field = new CakeField('title', $rules); $Field = new CakeValidationSet('title', $rules);
$data = array( $data = array(
'title' => '', 'title' => '',
'body' => 'a body' 'body' => 'a body'
@ -93,7 +93,7 @@ class CakeFieldTest extends CakeTestModel {
*/ */
public function testGetRules() { public function testGetRules() {
$rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty')); $rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
$Field = new CakeField('title', $rules); $Field = new CakeValidationSet('title', $rules);
$result = $Field->getRules(); $result = $Field->getRules();
$this->assertEquals(array('notEmpty'), array_keys($result)); $this->assertEquals(array('notEmpty'), array_keys($result));
@ -107,7 +107,7 @@ class CakeFieldTest extends CakeTestModel {
*/ */
public function testSetRule() { public function testSetRule() {
$rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty')); $rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
$Field = new CakeField('title', $rules); $Field = new CakeValidationSet('title', $rules);
$Rule = new CakeRule('notEmpty', $rules['notEmpty']); $Rule = new CakeRule('notEmpty', $rules['notEmpty']);
$this->assertEquals($Rule, $Field->getRule('notEmpty')); $this->assertEquals($Rule, $Field->getRule('notEmpty'));
@ -140,7 +140,7 @@ class CakeFieldTest extends CakeTestModel {
*/ */
public function testSetRules() { public function testSetRules() {
$rule = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty')); $rule = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
$Field = new CakeField('title', $rule); $Field = new CakeValidationSet('title', $rule);
$RuleEmpty = new CakeRule('title', $rule['notEmpty'], 'notEmpty'); $RuleEmpty = new CakeRule('title', $rule['notEmpty'], 'notEmpty');
$rule = array('validEmail' => array('rule' => 'email', 'message' => 'Invalid email')); $rule = array('validEmail' => array('rule' => 'email', 'message' => 'Invalid email'));