Permalink
Browse files

Renaming CakeRule to CakeValidationRule

  • Loading branch information...
1 parent 52c7b23 commit 280893155a6b56f46b5e59ebae89843ae2c1c3a6 @lorenzo lorenzo committed May 11, 2012
@@ -496,7 +496,7 @@ public function count() {
* Adds a new rule to a field's rule set
*
* @param string $field The name of the field from wich the rule will be removed
- * @param array|CakeRule $rule the rule to be added to the field's rule set
+ * @param array|CakeValidationRule $rule the rule to be added to the field's rule set
* @return ModelValidator this instance
**/
public function add($field, $name, $rule) {
@@ -1,6 +1,6 @@
<?php
/**
- * CakeRule.
+ * CakeValidationRule.
*
* Provides the Model validation logic.
*
@@ -23,12 +23,12 @@
App::uses('Validation', 'Utility');
/**
- * CakeRule object.
+ * CakeValidationRule object.
*
* @package Cake.Model.Validator
* @link http://book.cakephp.org/2.0/en/data-validation.html
*/
-class CakeRule {
+class CakeValidationRule {
/**
* The 'valid' value
@@ -19,7 +19,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('ModelValidator', 'Model');
-App::uses('CakeRule', 'Model/Validator');
+App::uses('CakeValidationRule', 'Model/Validator');
/**
* CakeValidationSet object.
@@ -85,7 +85,7 @@ public function __construct($fieldName, $ruleSet) {
}
foreach ($ruleSet as $index => $validateProp) {
- $this->_rules[$index] = new CakeRule($validateProp);
+ $this->_rules[$index] = new CakeValidationRule($validateProp);
}
$this->ruleSet = $ruleSet;
}
@@ -166,12 +166,12 @@ public function getRules() {
* Sets a ValidationRule $rule for key $key
*
* @param mixed $key The key under which the rule should be set
- * @param CakeRule|array $rule The validation rule to be set
+ * @param CakeValidationRule|array $rule The validation rule to be set
* @return CakeValidationSet this instance
*/
public function setRule($key, $rule) {
- if (!$rule instanceof CakeRule) {
- $rule = new CakeRule($rule);
+ if (!$rule instanceof CakeValidationRule) {
+ $rule = new CakeValidationRule($rule);
}
$this->_rules[$key] = $rule;
return $this;
@@ -208,7 +208,7 @@ public function setRules($rules = array(), $mergeVars = true) {
* Fetches the correct error message for a failed validation
*
* @param string $name the name of the rule as it was configured
- * @param CakeRule $rule the object containing validation information
+ * @param CakeValidationRule $rule the object containing validation information
* @return string
*/
protected function _processValidationResponse($name, $rule) {
@@ -269,7 +269,7 @@ public function offsetExists($index) {
* Returns a rule object by its index
*
* @param string $index name of the rule
- * @return CakeRule
+ * @return CakeValidationRule
**/
public function offsetGet($index) {
return $this->_rules[$index];
@@ -279,7 +279,7 @@ public function offsetGet($index) {
* Sets or replace a validation rule
*
* @param string $index name of the rule
- * @param CakeRule|array rule to add to $index
+ * @param CakeValidationRule|array rule to add to $index
**/
public function offsetSet($index, $rule) {
$this->setRule($index, $rule);
@@ -35,7 +35,7 @@ public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('All Model related class tests');
$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 .'CakeValidationRuleTest.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 . 'ModelDeleteTest.php');
@@ -1,6 +1,6 @@
<?php
/**
- * CakeRuleTest file
+ * CakeValidationRuleTest file
*
* PHP 5
*
@@ -17,14 +17,14 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-App::uses('CakeRule', 'Model/Validator');
+App::uses('CakeValidationRule', 'Model/Validator');
/**
- * CakeRuleTest
+ * CakeValidationRuleTest
*
* @package Cake.Test.Case.Model.Validator
*/
-class CakeRuleTest extends CakeTestCase {
+class CakeValidationRuleTest extends CakeTestCase {
/**
* setUp method
@@ -74,7 +74,7 @@ public function testIsValid() {
);
$methods = array();
- $Rule = new CakeRule($def);
+ $Rule = new CakeValidationRule($def);
$Rule->process('fieldName', $data, $methods);
$this->assertFalse($Rule->isValid());
@@ -94,7 +94,7 @@ public function testCustomMethods() {
);
$methods = array('mytestrule' => array($this, 'myTestRule'));
- $Rule = new CakeRule($def);
+ $Rule = new CakeValidationRule($def);
$Rule->process('fieldName', $data, $methods);
$this->assertFalse($Rule->isValid());
@@ -114,19 +114,19 @@ public function testCustomMethods() {
*/
public function testIsRequired() {
$def = array('rule' => 'notEmpty', 'required' => true);
- $Rule = new CakeRule($def);
+ $Rule = new CakeValidationRule($def);
$this->assertTrue($Rule->isRequired());
$def = array('rule' => 'notEmpty', 'required' => false);
- $Rule = new CakeRule($def);
+ $Rule = new CakeValidationRule($def);
$this->assertFalse($Rule->isRequired());
$def = array('rule' => 'notEmpty', 'required' => 'create');
- $Rule = new CakeRule($def);
+ $Rule = new CakeValidationRule($def);
$this->assertTrue($Rule->isRequired());
$def = array('rule' => 'notEmpty', 'required' => 'update');
- $Rule = new CakeRule($def);
+ $Rule = new CakeValidationRule($def);
$this->assertFalse($Rule->isRequired());
$Rule->isUpdate(true);
@@ -77,7 +77,7 @@ public function testGetRule() {
);
$result = $Field->getRule('notEmpty');
- $this->assertInstanceOf('CakeRule', $result);
+ $this->assertInstanceOf('CakeValidationRule', $result);
$this->assertEquals('notEmpty', $result->rule);
$this->assertEquals(null, $result->required);
$this->assertEquals(false, $result->allowEmpty);
@@ -97,7 +97,7 @@ public function testGetRules() {
$result = $Field->getRules();
$this->assertEquals(array('notEmpty'), array_keys($result));
- $this->assertInstanceOf('CakeRule', $result['notEmpty']);
+ $this->assertInstanceOf('CakeValidationRule', $result['notEmpty']);
}
/**
@@ -108,23 +108,23 @@ public function testGetRules() {
public function testSetRule() {
$rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
$Field = new CakeValidationSet('title', $rules);
- $Rule = new CakeRule($rules['notEmpty']);
+ $Rule = new CakeValidationRule($rules['notEmpty']);
$this->assertEquals($Rule, $Field->getRule('notEmpty'));
$rules = array('validEmail' => array('rule' => 'email', 'message' => 'Invalid email'));
- $Rule = new CakeRule($rules['validEmail']);
+ $Rule = new CakeValidationRule($rules['validEmail']);
$Field->setRule('validEmail', $Rule);
$result = $Field->getRules();
$this->assertEquals(array('notEmpty', 'validEmail'), array_keys($result));
$rules = array('validEmail' => array('rule' => 'email', 'message' => 'Other message'));
- $Rule = new CakeRule($rules['validEmail']);
+ $Rule = new CakeValidationRule($rules['validEmail']);
$Field->setRule('validEmail', $Rule);
$result = $Field->getRules();
$this->assertEquals(array('notEmpty', 'validEmail'), array_keys($result));
$result = $Field->getRule('validEmail');
- $this->assertInstanceOf('CakeRule', $result);
+ $this->assertInstanceOf('CakeValidationRule', $result);
$this->assertEquals('email', $result->rule);
$this->assertEquals(null, $result->required);
$this->assertEquals(false, $result->allowEmpty);
@@ -141,10 +141,10 @@ public function testSetRule() {
public function testSetRules() {
$rule = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
$Field = new CakeValidationSet('title', $rule);
- $RuleEmpty = new CakeRule($rule['notEmpty']);
+ $RuleEmpty = new CakeValidationRule($rule['notEmpty']);
$rule = array('validEmail' => array('rule' => 'email', 'message' => 'Invalid email'));
- $RuleEmail = new CakeRule($rule['validEmail']);
+ $RuleEmail = new CakeValidationRule($rule['validEmail']);
$rules = array('validEmail' => $RuleEmail);
$Field->setRules($rules, false);
@@ -170,15 +170,15 @@ public function testArrayAccessGet() {
));
$rule = $Set['notEmpty'];
- $this->assertInstanceOf('CakeRule', $rule);
+ $this->assertInstanceOf('CakeValidationRule', $rule);
$this->assertEquals('notEmpty', $rule->rule);
$rule = $Set['numeric'];
- $this->assertInstanceOf('CakeRule', $rule);
+ $this->assertInstanceOf('CakeValidationRule', $rule);
$this->assertEquals('numeric', $rule->rule);
$rule = $Set['other'];
- $this->assertInstanceOf('CakeRule', $rule);
+ $this->assertInstanceOf('CakeValidationRule', $rule);
$this->assertEquals(array('other', 1), $rule->rule);
}
@@ -213,13 +213,13 @@ public function testArrayAccessSet() {
$this->assertFalse(isset($Set['other']));
$Set['other'] = array('rule' => array('other', 1));
$rule = $Set['other'];
- $this->assertInstanceOf('CakeRule', $rule);
+ $this->assertInstanceOf('CakeValidationRule', $rule);
$this->assertEquals(array('other', 1), $rule->rule);
$this->assertFalse(isset($Set['numeric']));
- $Set['numeric'] = new CakeRule(array('rule' => 'numeric'));
+ $Set['numeric'] = new CakeValidationRule(array('rule' => 'numeric'));
$rule = $Set['numeric'];
- $this->assertInstanceOf('CakeRule', $rule);
+ $this->assertInstanceOf('CakeValidationRule', $rule);
$this->assertEquals('numeric', $rule->rule);
}
@@ -268,7 +268,7 @@ public function testIterator() {
if ($i === 2) {
$this->assertEquals('other', $name);
}
- $this->assertInstanceOf('CakeRule', $rule);
+ $this->assertInstanceOf('CakeValidationRule', $rule);
$i++;
}
$this->assertEquals(3, $i);

0 comments on commit 2808931

Please sign in to comment.