Skip to content
Permalink
Browse files

Consistently remove plugin names in object collections.

We were sometimes removing plugin prefixes (set, and some subclass
methods). But many other methods were missing the pluginSplit() feature.
This change makes all of the methods in ObjectCollection strip plugin
prefixes, which increases consistency across the framework.

Refs #7098
  • Loading branch information...
markstory committed Jul 24, 2015
1 parent 45877df commit 418dcfd7f8a7767bc85bb4c51bde8cc20b3742ff
Showing with 34 additions and 0 deletions.
  1. +29 −0 lib/Cake/Test/Case/Utility/ObjectCollectionTest.php
  2. +5 −0 lib/Cake/Utility/ObjectCollection.php
@@ -583,4 +583,33 @@ public function testDispatchEventNoSubject() {
$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 @@ public function __isset($name) {
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 @@ public function setPriority($name, $priority = null) {
$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 @@ public function setPriority($name, $priority = null) {
*/
public function disable($name) {
foreach ((array)$name as $object) {
list(, $object) = pluginSplit($object);
unset($this->_enabled[$object]);
}
}
@@ -255,6 +258,7 @@ public function disable($name) {
*/
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 @@ public function attached($name = null) {
*/
public function loaded($name = null) {
if (!empty($name)) {
list(, $name) = pluginSplit($name);
return isset($this->_loaded[$name]);
}
return array_keys($this->_loaded);

0 comments on commit 418dcfd

Please sign in to comment.
You can’t perform that action at this time.