mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding Model::hasMethod() and tests.
This commit is contained in:
parent
c5fa93b0fb
commit
fd3b4b2cd5
2 changed files with 40 additions and 0 deletions
|
@ -1066,6 +1066,23 @@ class Model extends Object {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that a method is callable on a model. This will check both the model's own methods, its
|
||||||
|
* inherited methods and methods that could be callable through behaviors.
|
||||||
|
*
|
||||||
|
* @param string $method The method to be called.
|
||||||
|
* @return boolean True on method being callable.
|
||||||
|
*/
|
||||||
|
public function hasMethod($method) {
|
||||||
|
if (method_exists($this, $method)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ($this->Behaviors->hasMethod($method)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the supplied field is a model Virtual Field
|
* Returns true if the supplied field is a model Virtual Field
|
||||||
*
|
*
|
||||||
|
|
|
@ -2008,4 +2008,27 @@ class ModelIntegrationTest extends BaseModelTest {
|
||||||
$expected = $db->name('Domain.DomainHandle');
|
$expected = $db->name('Domain.DomainHandle');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that model->hasMethod checks self and behaviors.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testHasMethod() {
|
||||||
|
$Article = new Article();
|
||||||
|
$Article->Behaviors = $this->getMock('BehaviorCollection');
|
||||||
|
|
||||||
|
$Article->Behaviors->expects($this->at(0))
|
||||||
|
->method('hasMethod')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
|
$Article->Behaviors->expects($this->at(1))
|
||||||
|
->method('hasMethod')
|
||||||
|
->will($this->returnValue(false));
|
||||||
|
|
||||||
|
$this->assertTrue($Article->hasMethod('find'));
|
||||||
|
|
||||||
|
$this->assertTrue($Article->hasMethod('pass'));
|
||||||
|
$this->assertFalse($Article->hasMethod('fail'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue