Skip to content

Commit

Permalink
Renaming CakeRule to CakeValidationRule
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 11, 2012
1 parent 52c7b23 commit 2808931
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Model/ModelValidator.php
Expand Up @@ -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) {
Expand Down
@@ -1,6 +1,6 @@
<?php
/**
* CakeRule.
* CakeValidationRule.
*
* Provides the Model validation logic.
*
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions lib/Cake/Model/Validator/CakeValidationSet.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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];
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Model/ModelTest.php
Expand Up @@ -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');
Expand Down
@@ -1,6 +1,6 @@
<?php
/**
* CakeRuleTest file
* CakeValidationRuleTest file
*
* PHP 5
*
Expand All @@ -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
Expand Down Expand Up @@ -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());

Expand All @@ -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());

Expand All @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions lib/Cake/Test/Case/Model/Validator/CakeValidationSetTest.php
Expand Up @@ -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);
Expand All @@ -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']);
}

/**
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2808931

Please sign in to comment.