mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #7106 from cakephp/issue-7098
Consistently remove plugin names in object collections.
This commit is contained in:
commit
355eb1859c
2 changed files with 34 additions and 0 deletions
|
@ -583,4 +583,33 @@ class ObjectCollectionTest extends CakeTestCase {
|
|||
$this->assertTrue($this->Objects->trigger($event));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that the various methods ignore plugin prefixes
|
||||
*
|
||||
* plugin prefixes should be removed consistently as load() will
|
||||
* remove them. Furthermore the __get() method does not support
|
||||
* names with '.' in them.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPluginPrefixes() {
|
||||
$this->Objects->load('TestPlugin.First');
|
||||
$this->assertTrue($this->Objects->loaded('First'));
|
||||
$this->assertTrue($this->Objects->loaded('TestPlugin.First'));
|
||||
|
||||
$this->assertTrue($this->Objects->enabled('First'));
|
||||
$this->assertTrue($this->Objects->enabled('TestPlugin.First'));
|
||||
|
||||
$this->assertNull($this->Objects->disable('TestPlugin.First'));
|
||||
$this->assertFalse($this->Objects->enabled('First'));
|
||||
$this->assertFalse($this->Objects->enabled('TestPlugin.First'));
|
||||
|
||||
$this->assertNull($this->Objects->enable('TestPlugin.First'));
|
||||
$this->assertTrue($this->Objects->enabled('First'));
|
||||
$this->assertTrue($this->Objects->enabled('TestPlugin.First'));
|
||||
$this->Objects->setPriority('TestPlugin.First', 1000);
|
||||
|
||||
$result = $this->Objects->prioritize();
|
||||
$this->assertEquals(1000, $result['First'][0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,6 +176,7 @@ abstract class ObjectCollection {
|
|||
public function enable($name, $prioritize = true) {
|
||||
$enabled = false;
|
||||
foreach ((array)$name as $object) {
|
||||
list(, $object) = pluginSplit($object);
|
||||
if (isset($this->_loaded[$object]) && !isset($this->_enabled[$object])) {
|
||||
$priority = $this->defaultPriority;
|
||||
if (isset($this->_loaded[$object]->settings['priority'])) {
|
||||
|
@ -219,6 +220,7 @@ abstract class ObjectCollection {
|
|||
$name = array($name => $priority);
|
||||
}
|
||||
foreach ($name as $object => $objectPriority) {
|
||||
list(, $object) = pluginSplit($object);
|
||||
if (isset($this->_loaded[$object])) {
|
||||
if ($objectPriority === null) {
|
||||
$objectPriority = $this->defaultPriority;
|
||||
|
@ -241,6 +243,7 @@ abstract class ObjectCollection {
|
|||
*/
|
||||
public function disable($name) {
|
||||
foreach ((array)$name as $object) {
|
||||
list(, $object) = pluginSplit($object);
|
||||
unset($this->_enabled[$object]);
|
||||
}
|
||||
}
|
||||
|
@ -255,6 +258,7 @@ abstract class ObjectCollection {
|
|||
*/
|
||||
public function enabled($name = null) {
|
||||
if (!empty($name)) {
|
||||
list(, $name) = pluginSplit($name);
|
||||
return isset($this->_enabled[$name]);
|
||||
}
|
||||
return array_keys($this->_enabled);
|
||||
|
@ -283,6 +287,7 @@ abstract class ObjectCollection {
|
|||
*/
|
||||
public function loaded($name = null) {
|
||||
if (!empty($name)) {
|
||||
list(, $name) = pluginSplit($name);
|
||||
return isset($this->_loaded[$name]);
|
||||
}
|
||||
return array_keys($this->_loaded);
|
||||
|
|
Loading…
Reference in a new issue