Merge pull request #7106 from cakephp/issue-7098

Consistently remove plugin names in object collections.
This commit is contained in:
José Lorenzo Rodríguez 2015-07-28 15:58:41 +02:00
commit 355eb1859c
2 changed files with 34 additions and 0 deletions

View file

@ -583,4 +583,33 @@ class ObjectCollectionTest extends CakeTestCase {
$this->assertTrue($this->Objects->trigger($event)); $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]);
}
} }

View file

@ -176,6 +176,7 @@ abstract class ObjectCollection {
public function enable($name, $prioritize = true) { public function enable($name, $prioritize = true) {
$enabled = false; $enabled = false;
foreach ((array)$name as $object) { foreach ((array)$name as $object) {
list(, $object) = pluginSplit($object);
if (isset($this->_loaded[$object]) && !isset($this->_enabled[$object])) { if (isset($this->_loaded[$object]) && !isset($this->_enabled[$object])) {
$priority = $this->defaultPriority; $priority = $this->defaultPriority;
if (isset($this->_loaded[$object]->settings['priority'])) { if (isset($this->_loaded[$object]->settings['priority'])) {
@ -219,6 +220,7 @@ abstract class ObjectCollection {
$name = array($name => $priority); $name = array($name => $priority);
} }
foreach ($name as $object => $objectPriority) { foreach ($name as $object => $objectPriority) {
list(, $object) = pluginSplit($object);
if (isset($this->_loaded[$object])) { if (isset($this->_loaded[$object])) {
if ($objectPriority === null) { if ($objectPriority === null) {
$objectPriority = $this->defaultPriority; $objectPriority = $this->defaultPriority;
@ -241,6 +243,7 @@ abstract class ObjectCollection {
*/ */
public function disable($name) { public function disable($name) {
foreach ((array)$name as $object) { foreach ((array)$name as $object) {
list(, $object) = pluginSplit($object);
unset($this->_enabled[$object]); unset($this->_enabled[$object]);
} }
} }
@ -255,6 +258,7 @@ abstract class ObjectCollection {
*/ */
public function enabled($name = null) { public function enabled($name = null) {
if (!empty($name)) { if (!empty($name)) {
list(, $name) = pluginSplit($name);
return isset($this->_enabled[$name]); return isset($this->_enabled[$name]);
} }
return array_keys($this->_enabled); return array_keys($this->_enabled);
@ -283,6 +287,7 @@ abstract class ObjectCollection {
*/ */
public function loaded($name = null) { public function loaded($name = null) {
if (!empty($name)) { if (!empty($name)) {
list(, $name) = pluginSplit($name);
return isset($this->_loaded[$name]); return isset($this->_loaded[$name]);
} }
return array_keys($this->_loaded); return array_keys($this->_loaded);