Skip to content

Commit

Permalink
Graduating the Validation objects to their own namspace as it is generic
Browse files Browse the repository at this point in the history
enough and do not have any dependencies
  • Loading branch information
lorenzo committed Nov 20, 2013
1 parent b3cf800 commit 0af58b7
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
12 changes: 6 additions & 6 deletions Cake/ORM/Table.php
Expand Up @@ -27,7 +27,7 @@
use Cake\ORM\Association\HasOne;
use Cake\ORM\BehaviorRegistry;
use Cake\ORM\Entity;
use Cake\ORM\Validator;
use Cake\Validation\Validator;
use Cake\Utility\Inflector;

/**
Expand Down Expand Up @@ -765,7 +765,7 @@ public function updateAll($fields, $conditions) {
* Otherwise, you can build the object by yourself and store it in the Table object:
*
* {{{
* $validator = new \Cake\ORM\Validator($table);
* $validator = new \Cake\Validation\Validator($table);
* $validator
* ->add('email', 'required', ['rule' => 'email', 'required' => true])
* ->add('password', 'valid', ['rule' => 'notEmpty', 'required' => true]);
Expand All @@ -777,8 +777,8 @@ public function updateAll($fields, $conditions) {
* set is specified.
*
* @param string $name the name of the validation set to return
* @param \Cake\ORM\Validator $validator
* @return \Cake\ORM\Validator
* @param \Cake\Validation\Validator $validator
* @return \Cake\Validation\Validator
*/
public function validator($name = 'default', $instance = null) {
if ($instance === null && isset($this->_validators[$name])) {
Expand All @@ -798,9 +798,9 @@ public function validator($name = 'default', $instance = null) {
* Returns the default validator object. Subclasses can override this function
* to add a default validation set to the validator object.
*
* @param \Cake\ORM\Validator $validator The validator that can be modified to
* @param \Cake\Validation\Validator $validator The validator that can be modified to
* add some rules to it.
* @return \Cake\ORM\Validator
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator) {
return $validator;
Expand Down
6 changes: 3 additions & 3 deletions Cake/Test/TestCase/ORM/TableTest.php
Expand Up @@ -1805,7 +1805,7 @@ public function testHasField() {
public function testValidatorDefault() {
$table = new Table();
$validator = $table->validator();
$this->assertInstanceOf('\Cake\ORM\Validator', $validator);
$this->assertInstanceOf('\Cake\Validation\Validator', $validator);
$default = $table->validator('default');
$this->assertSame($validator, $default);
}
Expand All @@ -1820,7 +1820,7 @@ public function functionTestValidationWithDefiner() {
$table->expects($this->once())->method('validationForOtherStuff')
->will($this->returnArgument(0));
$other = $table->validator('forOtherStuff');
$this->assertInstanceOf('\Cake\ORM\Validator', $other);
$this->assertInstanceOf('\Cake\Validation\Validator', $other);
$this->assertNotSame($other, $table->validator());
}

Expand All @@ -1831,7 +1831,7 @@ public function functionTestValidationWithDefiner() {
*/
public function testValidatorSetter() {
$table = new Table;
$validator = new \Cake\ORM\Validator;
$validator = new \Cake\Validation\Validator;
$table->validator('other', $validator);
$this->assertSame($validator, $table->validator('other'));
}
Expand Down
Expand Up @@ -6,18 +6,18 @@
* 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
* For full copyright and license infValidationation, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @since CakePHP(tm) v 2.2.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\Model\Validator;
namespace Cake\Test\TestCase\Validation;

use Cake\ORM\Validation\ValidationRule;
use Cake\ORM\Validation\ValidationSet;
use Cake\Validation\ValidationRule;
use Cake\Validation\ValidationSet;
use Cake\TestSuite\TestCase;

/**
Expand All @@ -35,7 +35,7 @@ public function testGetRule() {
$field = new ValidationSet;
$field->add('notEmpty', ['rule' => 'notEmpty', 'message' => 'Can not be empty']);
$result = $field->rule('notEmpty');
$this->assertInstanceOf('Cake\ORM\Validation\ValidationRule', $result);
$this->assertInstanceOf('Cake\Validation\ValidationRule', $result);
$expected = new ValidationRule(['rule' => 'notEmpty', 'message' => 'Can not be empty']);
$this->assertEquals($expected, $result);
}
Expand All @@ -51,7 +51,7 @@ public function testGetRules() {

$result = $field->rules();
$this->assertEquals(['notEmpty'], array_keys($result));
$this->assertInstanceOf('Cake\ORM\Validation\ValidationRule', $result['notEmpty']);
$this->assertInstanceOf('Cake\Validation\ValidationRule', $result['notEmpty']);
}

/**
Expand All @@ -66,15 +66,15 @@ public function testArrayAccessGet() {
->add('other', ['rule' => 'email']);

$rule = $set['notEmpty'];
$this->assertInstanceOf('Cake\ORM\Validation\ValidationRule', $rule);
$this->assertInstanceOf('Cake\Validation\ValidationRule', $rule);
$this->assertEquals(new ValidationRule(['rule' => 'notEmpty']), $rule);

$rule = $set['numeric'];
$this->assertInstanceOf('Cake\ORM\Validation\ValidationRule', $rule);
$this->assertInstanceOf('Cake\Validation\ValidationRule', $rule);
$this->assertEquals(new ValidationRule(['rule' => 'numeric']), $rule);

$rule = $set['other'];
$this->assertInstanceOf('Cake\ORM\Validation\ValidationRule', $rule);
$this->assertInstanceOf('Cake\Validation\ValidationRule', $rule);
$this->assertEquals(new ValidationRule(['rule' => 'email']), $rule);
}

Expand Down Expand Up @@ -107,7 +107,7 @@ public function testArrayAccessSet() {
$this->assertFalse(isset($set['other']));
$set['other'] = ['rule' => 'email'];
$rule = $set['other'];
$this->assertInstanceOf('Cake\ORM\Validation\ValidationRule', $rule);
$this->assertInstanceOf('Cake\Validation\ValidationRule', $rule);
$this->assertEquals(new ValidationRule(['rule' => 'email']), $rule);
}

Expand Down Expand Up @@ -154,7 +154,7 @@ public function testIterator() {
if ($i === 2) {
$this->assertEquals('other', $name);
}
$this->assertInstanceOf('Cake\ORM\Validation\ValidationRule', $rule);
$this->assertInstanceOf('Cake\Validation\ValidationRule', $rule);
$i++;
}
$this->assertEquals(3, $i);
Expand Down
Expand Up @@ -6,18 +6,18 @@
* 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
* For full copyright and license infValidationation, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 3.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\ORM;
namespace Cake\Test\TestCase\Validation;

use \Cake\ORM\Validation\ValidationSet;
use \Cake\ORM\Validator;
use \Cake\Validation\ValidationSet;
use \Cake\Validation\Validator;

/**
* Tests Validator class
Expand All @@ -34,7 +34,7 @@ public function testAddingRulesToField() {
$validator = new Validator;
$validator->add('title', 'not-empty', ['rule' => 'notEmpty']);
$set = $validator->field('title');
$this->assertInstanceOf('\Cake\ORM\Validation\ValidationSet', $set);
$this->assertInstanceOf('\Cake\Validation\ValidationSet', $set);
$this->assertCount(1, $set);

$validator->add('title', 'another', ['rule' => 'alphanumeric']);
Expand All @@ -53,7 +53,7 @@ public function testAddingRulesToField() {
public function testFieldDefault() {
$validator = new Validator;
$field = $validator->field('foo');
$this->assertInstanceOf('\Cake\ORM\Validation\ValidationSet', $field);
$this->assertInstanceOf('\Cake\Validation\ValidationSet', $field);
$this->assertCount(0, $field);
}

Expand Down
Expand Up @@ -16,7 +16,7 @@
* @since CakePHP(tm) v 2.2.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\ORM\Validation;
namespace Cake\Validation;

/**
* ValidationRule object. Represents a validation method, error message and
Expand Down
Expand Up @@ -16,7 +16,7 @@
* @since CakePHP(tm) v 2.2.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\ORM\Validation;
namespace Cake\Validation;

/**
* ValidationSet object. Holds all validation rules for a field and exposes
Expand Down
10 changes: 5 additions & 5 deletions Cake/ORM/Validator.php → Cake/Validation/Validator.php
Expand Up @@ -14,9 +14,9 @@
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\ORM;
namespace Cake\Validation;

use Cake\ORM\Validation\ValidationSet;
use Cake\Validation\ValidationSet;

/**
* Validator object encapsulates all methods related to data validations for a model
Expand Down Expand Up @@ -100,7 +100,7 @@ public function errors(array $data, $newRecord = true) {
* before
*
* @param string $name [optional] The fieldname to fetch.
* @param \Cake\ORM\Validation\ValidationSet $set The set of rules for field
* @param \Cake\Validation\ValidationSet $set The set of rules for field
* @return Cake\Model\Validator\ValidationSet
*/
public function field($name, ValidationSet $set = null) {
Expand Down Expand Up @@ -232,7 +232,7 @@ public function count() {
*
* @param string $field The name of the field from wich the rule will be removed
* @param array|string $name The alias for a single rule or multiple rules array
* @param array|Cake\ORM\Validation\ValidationRule $rule the rule to add
* @param array|Cake\Validation\ValidationRule $rule the rule to add
* @return Validator this instance
*/
public function add($field, $name, $rule = []) {
Expand Down Expand Up @@ -320,7 +320,7 @@ protected function _checkPresence($field, $newRecord) {
}

/**
*
*
* Returns whether the field can be left blank according to `allowEmpty`
*
* @param ValidationSet $field the set of rules for a field
Expand Down

0 comments on commit 0af58b7

Please sign in to comment.