Merge pull request #2411 from kinglozzer/virtualpage-definemethods

FIX: VirtualPage missing methods from target page (fixes #2408)
This commit is contained in:
Robbie Averill 2019-08-05 13:16:08 +12:00 committed by GitHub
commit 59b9a0d664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -489,6 +489,19 @@ class VirtualPage extends Page
return $copy && $copy->exists() && $copy->hasField($field);
}
/**
* @param string $method
* @return bool
*/
public function hasMethod($method)
{
if (parent::hasMethod($method)) {
return true;
}
$copy = $this->CopyContentFrom();
return $copy && $copy->exists() && $copy->hasMethod($method);
}
/**
* Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field
* on this object.

View File

@ -669,6 +669,9 @@ class VirtualPageTest extends FunctionalTest
{
/** @var VirtualPage $virtualPage */
$virtualPage = $this->objFromFixture(VirtualPage::class, 'vp4');
$this->assertTrue($virtualPage->hasMethod('modelMethod'));
$this->assertEquals('hi there', $virtualPage->modelMethod());
/** @var VirtualPageTest_ClassAController $controller */
$controller = ModelAsController::controller_for($virtualPage);
$this->assertInstanceOf(VirtualPageTest_ClassAController::class, $controller);