From 7592db918f269db2fd5c33d9c1259df86f15e12b Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Fri, 12 Apr 2019 15:45:50 +0100 Subject: [PATCH] FIX: VirtualPage missing methods from target page (fixes #2408) --- code/Model/VirtualPage.php | 13 +++++++++++++ tests/php/Model/VirtualPageTest.php | 3 +++ 2 files changed, 16 insertions(+) diff --git a/code/Model/VirtualPage.php b/code/Model/VirtualPage.php index 1b4a9231..e7425f88 100644 --- a/code/Model/VirtualPage.php +++ b/code/Model/VirtualPage.php @@ -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. diff --git a/tests/php/Model/VirtualPageTest.php b/tests/php/Model/VirtualPageTest.php index 7951b9de..834324b7 100644 --- a/tests/php/Model/VirtualPageTest.php +++ b/tests/php/Model/VirtualPageTest.php @@ -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);