Merge pull request #8840 from open-sausages/pulls/4.3/has-extension-injectable

ENHANCEMENT: has_extension() should allow injector overrides
This commit is contained in:
Guy Marriott 2019-03-27 13:23:30 +13:00 committed by GitHub
commit 0f00154563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 8 deletions

View File

@ -388,6 +388,10 @@ trait Extensible
if (!$strict && is_subclass_of($extension, $requiredExtension)) { if (!$strict && is_subclass_of($extension, $requiredExtension)) {
return true; return true;
} }
$inst = Injector::inst()->get($extension);
if ($inst instanceof $requiredExtension) {
return $strict ? strcasecmp(get_class($inst), $requiredExtension) === 0 : true;
}
} }
return false; return false;

View File

@ -58,9 +58,9 @@ class CmsUiContext implements Context
$timeoutMs = $this->getMainContext()->getAjaxTimeout(); $timeoutMs = $this->getMainContext()->getAjaxTimeout();
$this->getSession()->wait( $this->getSession()->wait(
$timeoutMs, $timeoutMs,
"(". "(" .
"document.getElementsByClassName('cms-content-loading-overlay').length +". "document.getElementsByClassName('cms-content-loading-overlay').length +" .
"document.getElementsByClassName('cms-loading-container').length". "document.getElementsByClassName('cms-loading-container').length" .
") == 0" ") == 0"
); );
} }

View File

@ -11,6 +11,7 @@ use SilverStripe\Core\Tests\ObjectTest\ExtendTest1;
use SilverStripe\Core\Tests\ObjectTest\ExtendTest2; use SilverStripe\Core\Tests\ObjectTest\ExtendTest2;
use SilverStripe\Core\Tests\ObjectTest\ExtendTest3; use SilverStripe\Core\Tests\ObjectTest\ExtendTest3;
use SilverStripe\Core\Tests\ObjectTest\ExtendTest4; use SilverStripe\Core\Tests\ObjectTest\ExtendTest4;
use SilverStripe\Core\Tests\ObjectTest\ExtendTest5;
use SilverStripe\Core\Tests\ObjectTest\ExtensionRemoveTest; use SilverStripe\Core\Tests\ObjectTest\ExtensionRemoveTest;
use SilverStripe\Core\Tests\ObjectTest\ExtensionTest; use SilverStripe\Core\Tests\ObjectTest\ExtensionTest;
use SilverStripe\Core\Tests\ObjectTest\ExtensionTest2; use SilverStripe\Core\Tests\ObjectTest\ExtensionTest2;
@ -290,6 +291,13 @@ class ObjectTest extends SapphireTest
"Extensions are detected with instance hasExtension() when added through add_extension()" "Extensions are detected with instance hasExtension() when added through add_extension()"
); );
// load in a custom implementation
Injector::inst()->registerService(new ExtendTest5(), ExtendTest4::class);
$this->assertTrue(
ExtensionTest3::has_extension(ExtendTest5::class),
"Injected sub-extensions are detected with static has_extension() when added through add_extension()"
);
// @todo At the moment, this does NOT remove the extension due to parameterized naming, // @todo At the moment, this does NOT remove the extension due to parameterized naming,
// meaning the extension will remain added in further test cases // meaning the extension will remain added in further test cases
ExtensionTest::remove_extension(ExtendTest3::class); ExtensionTest::remove_extension(ExtendTest3::class);

View File

@ -0,0 +1,11 @@
<?php
namespace SilverStripe\Core\Tests\ObjectTest;
class ExtendTest5 extends ExtendTest4
{
public function extendableMethod($argument = null)
{
return "ExtendTest5($argument)";
}
}