Skip to content

Commit

Permalink
Added support for lazy loaded validators in hasValidator().
Browse files Browse the repository at this point in the history
Test added for hasValidator method.
  • Loading branch information
Robert Pustułka committed May 30, 2017
1 parent f59aae3 commit ac02317
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Validation/ValidatorAwareTrait.php
Expand Up @@ -214,6 +214,11 @@ public function setValidator($name, Validator $validator)
*/
public function hasValidator($name)
{
$method = 'validation' . ucfirst($name);
if (method_exists($this, $method)) {
return true;
}

return isset($this->_validators[$name]);
}

Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -3411,6 +3411,22 @@ public function testValidatorSetter()
$this->assertSame($table, $validator->provider('table'));
}

/**
* Tests hasValidator method.
*
* @return void
*/
public function testHasValidator()
{
$table = new Table;
$this->assertTrue($table->hasValidator('default'));
$this->assertFalse($table->hasValidator('other'));

$validator = new \Cake\Validation\Validator;
$table->setValidator('other', $validator);
$this->assertTrue($table->hasValidator('other'));
}

/**
* Tests that the source of an existing Entity is the same as a new one
*
Expand Down

0 comments on commit ac02317

Please sign in to comment.