From a292ef0f167b3f14ec413c170d26991e224cf5c4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 15 Nov 2009 19:54:33 -0500 Subject: [PATCH] Adding ability to provide default plugin value to pluginSplit(). --- cake/basics.php | 5 +++-- cake/tests/cases/basics.test.php | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 039d1c42e..516fe746b 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -220,9 +220,10 @@ if (!function_exists('array_combine')) { * * @param string $name The name you want to plugin split. * @param boolean $dotAppend Set to true if you want the plugin to have a '.' appended to it. + * @param string $plugin Optional default plugin to use if no plugin is found. Defaults to null. * @return array Array with 2 indexes. 0 => plugin name, 1 => classname */ - function pluginSplit($name, $dotAppend = false) { + function pluginSplit($name, $dotAppend = false, $plugin = null) { if (strpos($name, '.') !== false) { $parts = explode('.', $name, 2); if ($dotAppend) { @@ -230,7 +231,7 @@ if (!function_exists('array_combine')) { } return $parts; } - return array(null, $name); + return array($plugin, $name); } /** diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index ff39e9fa1..bb24c70f9 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -773,18 +773,24 @@ class BasicsTest extends CakeTestCase { function testPluginSplit() { $result = pluginSplit('Something.else'); $this->assertEqual($result, array('Something', 'else')); - + $result = pluginSplit('Something.else.more.dots'); $this->assertEqual($result, array('Something', 'else.more.dots')); $result = pluginSplit('Somethingelse'); $this->assertEqual($result, array(null, 'Somethingelse')); - + $result = pluginSplit('Something.else', true); $this->assertEqual($result, array('Something.', 'else')); - + $result = pluginSplit('Something.else.more.dots', true); $this->assertEqual($result, array('Something.', 'else.more.dots')); + + $result = pluginSplit('Post', false, 'Blog'); + $this->assertEqual($result, array('Blog', 'Post')); + + $result = pluginSplit('Blog.Post', false, 'Ultimate'); + $this->assertEqual($result, array('Blog', 'Post')); } } ?> \ No newline at end of file