Corrected view tests.

Added fix for Ticket #2245
Refactored loading of components and helpers to allow for use of dot notation with plugins.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4659 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-03-23 10:34:21 +00:00
parent 7cc6185076
commit c20a8c80f3
4 changed files with 14 additions and 10 deletions

View file

@ -353,6 +353,8 @@ class Dispatcher extends Object {
$controller->output =& $output; $controller->output =& $output;
foreach($controller->components as $c) { foreach($controller->components as $c) {
$path = preg_split('/\/|\./', $c);
$c = $path[count($path) - 1];
if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, 'shutdown'))) { if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, 'shutdown'))) {
if (!array_key_exists('enabled', get_object_vars($controller->{$c})) || $controller->{$c}->enabled == true) { if (!array_key_exists('enabled', get_object_vars($controller->{$c})) || $controller->{$c}->enabled == true) {
$controller->{$c}->shutdown($controller); $controller->{$c}->shutdown($controller);
@ -385,6 +387,8 @@ class Dispatcher extends Object {
$controller->beforeFilter(); $controller->beforeFilter();
foreach($controller->components as $c) { foreach($controller->components as $c) {
$path = preg_split('/\/|\./', $c);
$c = $path[count($path) - 1];
if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, 'startup'))) { if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, 'startup'))) {
if (!array_key_exists('enabled', get_object_vars($controller->{$c})) || $controller->{$c}->enabled == true) { if (!array_key_exists('enabled', get_object_vars($controller->{$c})) || $controller->{$c}->enabled == true) {
$controller->{$c}->startup($controller); $controller->{$c}->startup($controller);

View file

@ -85,13 +85,13 @@ class Component extends Object {
$components[] = 'Session'; $components[] = 'Session';
foreach($components as $component) { foreach($components as $component) {
$pos = strpos($component, '/'); $parts = preg_split('/\/|\./', $component);
if ($pos === false) {
if(count($parts) === 1) {
$plugin = $this->controller->plugin; $plugin = $this->controller->plugin;
} else { } else {
$parts = explode('/', $component);
$plugin = Inflector::underscore($parts['0']); $plugin = Inflector::underscore($parts['0']);
$component = $parts['1']; $component = $parts[count($parts) - 1];
} }
$componentCn = $component . 'Component'; $componentCn = $component . 'Component';

View file

@ -373,7 +373,7 @@ class View extends Object {
* @return string Rendered output * @return string Rendered output
*/ */
function renderElement($name, $params = array(), $loadHelpers = false) { function renderElement($name, $params = array(), $loadHelpers = false) {
if(isset($params['plugin'])) { if(isset($params['plugin'])) {
$this->plugin = $params['plugin']; $this->plugin = $params['plugin'];
$this->pluginPath = 'plugins' . DS . $this->plugin . DS; $this->pluginPath = 'plugins' . DS . $this->plugin . DS;
@ -824,13 +824,13 @@ class View extends Object {
$helpers[] = 'Session'; $helpers[] = 'Session';
foreach($helpers as $helper) { foreach($helpers as $helper) {
$pos = strpos($helper, '/'); $parts = preg_split('/\/|\./', $helper);
if ($pos === false) {
if(count($parts) === 1) {
$plugin = $this->plugin; $plugin = $this->plugin;
} else { } else {
$parts = explode('/', $helper);
$plugin = Inflector::underscore($parts['0']); $plugin = Inflector::underscore($parts['0']);
$helper = $parts['1']; $helper = $parts[count($parts) - 1];
} }
$helperCn = $helper . 'Helper'; $helperCn = $helper . 'Helper';

View file

@ -54,7 +54,7 @@ class ViewTest extends UnitTestCase {
} }
function testViewVars() { function testViewVars() {
$this->assertTrue($this->view->viewVars, array('testData' => 'Some test data', 'test2' => 'more data', 'test3' => 'even more data')); $this->assertEqual($this->view->viewVars, array('testData' => 'Some test data', 'test2' => 'more data', 'test3' => 'even more data'));
} }
function testUUIDGeneration() { function testUUIDGeneration() {