fixing bug in error handler when callbacks were moved to construct classes, moved callbacks back to dispatcher for now until we find a better place in the controller, fixed caching for the "home" page by adding check for "/', original test case was incorrect.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7177 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-06-12 18:36:08 +00:00
parent 75e157a167
commit 97a57a0f05
8 changed files with 64 additions and 12 deletions

View file

@ -223,6 +223,10 @@ class Dispatcher extends Object {
'url' => $url, 'url' => $url,
'base' => $this->base))); 'base' => $this->base)));
} }
$controller->Component->initialize($controller);
$controller->beforeFilter();
$controller->Component->startup($controller);
return $this->_invoke($controller, $this->params, $missingAction); return $this->_invoke($controller, $this->params, $missingAction);
} }
/** /**
@ -675,10 +679,16 @@ class Dispatcher extends Object {
} }
if (Configure::read('Cache.check') === true) { if (Configure::read('Cache.check') === true) {
$filename = CACHE . 'views' . DS . Inflector::slug($this->here) . '.php'; $path = $this->here;
if ($this->here == '/') {
$path = 'home';
}
$path = Inflector::slug($path);
$filename = CACHE . 'views' . DS . $path . '.php';
if (!file_exists($filename)) { if (!file_exists($filename)) {
$filename = CACHE . 'views' . DS . Inflector::slug($this->here) . '_index.php'; $filename = CACHE . 'views' . DS . $path . '_index.php';
} }
if (file_exists($filename)) { if (file_exists($filename)) {

View file

@ -375,6 +375,7 @@ class Controller extends Object {
/** /**
* Loads Model classes based on the the uses property * Loads Model classes based on the the uses property
* see Controller::loadModel(); for more info * see Controller::loadModel(); for more info
* Loads Components and prepares them for initailization
* *
* @return mixed true if models found and instance created, or cakeError if models not found. * @return mixed true if models found and instance created, or cakeError if models not found.
* @access public * @access public
@ -401,9 +402,6 @@ class Controller extends Object {
} }
} }
} }
$this->Component->initialize($this);
$this->beforeFilter();
$this->Component->startup($this);
return true; return true;
} }
/** /**

View file

@ -46,6 +46,7 @@ class CakeErrorController extends AppController {
$this->_set(Router::getPaths()); $this->_set(Router::getPaths());
$this->params = Router::getParams(); $this->params = Router::getParams();
$this->constructClasses(); $this->constructClasses();
$this->Component->initialize($this);
$this->_set(array('cacheAction' => false, 'viewPath' => 'errors')); $this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
} }

View file

@ -222,7 +222,11 @@ class CacheHelper extends AppHelper {
} else { } else {
$cacheTime = strtotime($timestamp, $now); $cacheTime = strtotime($timestamp, $now);
} }
$cache = Inflector::slug($this->here); $path = $this->here;
if ($this->here == '/') {
$path = 'home';
}
$cache = Inflector::slug($path);
if (empty($cache)) { if (empty($cache)) {
return; return;

View file

@ -1316,8 +1316,8 @@ class DispatcherTest extends UnitTestCase {
$url = '/'; $url = '/';
ob_start(); ob_start();
$out = $dispatcher->dispatch($url); $dispatcher->dispatch($url);
ob_get_clean(); $out = ob_get_clean();
ob_start(); ob_start();
$dispatcher->cached($url); $dispatcher->cached($url);
@ -1328,7 +1328,8 @@ class DispatcherTest extends UnitTestCase {
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php';
$filename = $this->__cachePath($dispatcher->here);
unlink($filename); unlink($filename);
$dispatcher->base = false; $dispatcher->base = false;
@ -1347,7 +1348,7 @@ class DispatcherTest extends UnitTestCase {
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php'; $filename = $this->__cachePath($dispatcher->here);
unlink($filename); unlink($filename);
$url = 'TestCachedPages/index'; $url = 'TestCachedPages/index';
@ -1365,7 +1366,7 @@ class DispatcherTest extends UnitTestCase {
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php'; $filename = $this->__cachePath($dispatcher->here);
unlink($filename); unlink($filename);
$url = 'TestCachedPages/test_nocache_tags'; $url = 'TestCachedPages/test_nocache_tags';
@ -1383,7 +1384,7 @@ class DispatcherTest extends UnitTestCase {
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php'; $filename = $this->__cachePath($dispatcher->here);
unlink($filename); unlink($filename);
} }
/** /**
@ -1610,6 +1611,27 @@ class DispatcherTest extends UnitTestCase {
} }
} }
} }
/**
* cachePath method
*
* @param mixed $her
* @access private
* @return string
*/
function __cachePath($here) {
$path = $here;
if ($here == '/') {
$path = 'home';
}
$path = Inflector::slug($path);
$filename = CACHE . 'views' . DS . $path . '.php';
if (!file_exists($filename)) {
$filename = CACHE . 'views' . DS . $path . '_index.php';
}
return $filename;
}
/** /**
* tearDown method * tearDown method
* *

View file

@ -292,6 +292,7 @@ class ComponentTest extends CakeTestCase {
$Controller =& new ComponentTestController(); $Controller =& new ComponentTestController();
$Controller->components = array('Apple'); $Controller->components = array('Apple');
$Controller->constructClasses(); $Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertTrue(is_a($Controller->Apple, 'AppleComponent')); $this->assertTrue(is_a($Controller->Apple, 'AppleComponent'));
$this->assertTrue(is_a($Controller->Apple->Orange, 'OrangeComponent')); $this->assertTrue(is_a($Controller->Apple->Orange, 'OrangeComponent'));
@ -306,6 +307,9 @@ class ComponentTest extends CakeTestCase {
$Controller =& new ComponentTestController(); $Controller =& new ComponentTestController();
$Controller->components = array('Apple'); $Controller->components = array('Apple');
$Controller->constructClasses(); $Controller->constructClasses();
$Controller->Component->initialize($Controller);
$Controller->beforeFilter();
$Controller->Component->startup($Controller);
$this->assertTrue(is_a($Controller->Apple, 'AppleComponent')); $this->assertTrue(is_a($Controller->Apple, 'AppleComponent'));
$this->assertEqual($Controller->Apple->testName, 'ComponentTest'); $this->assertEqual($Controller->Apple->testName, 'ComponentTest');
@ -319,6 +323,7 @@ class ComponentTest extends CakeTestCase {
$Controller =& new ComponentTestController(); $Controller =& new ComponentTestController();
$Controller->components = array('Orange', 'Banana'); $Controller->components = array('Orange', 'Banana');
$Controller->constructClasses(); $Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertEqual($Controller->Banana->testField, 'OrangeField'); $this->assertEqual($Controller->Banana->testField, 'OrangeField');
$this->assertEqual($Controller->Orange->Banana->testField, 'OrangeField'); $this->assertEqual($Controller->Orange->Banana->testField, 'OrangeField');
@ -336,6 +341,7 @@ class ComponentTest extends CakeTestCase {
$Controller->components = array('ParamTest' => array('test' => 'value', 'flag'), 'Apple'); $Controller->components = array('ParamTest' => array('test' => 'value', 'flag'), 'Apple');
$Controller->constructClasses(); $Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertTrue(is_a($Controller->ParamTest, 'ParamTestComponent')); $this->assertTrue(is_a($Controller->ParamTest, 'ParamTestComponent'));
$this->assertTrue(is_a($Controller->ParamTest->Banana, 'BananaComponent')); $this->assertTrue(is_a($Controller->ParamTest->Banana, 'BananaComponent'));
@ -349,6 +355,7 @@ class ComponentTest extends CakeTestCase {
$Controller =& new ComponentTestController(); $Controller =& new ComponentTestController();
$Controller->components = array('ParamTest' => array('test' => 'value'), 'Orange' => array('ripeness' => 'perfect')); $Controller->components = array('ParamTest' => array('test' => 'value'), 'Orange' => array('ripeness' => 'perfect'));
$Controller->constructClasses(); $Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertEqual($Controller->Orange->settings, array('colour' => 'blood orange', 'ripeness' => 'perfect')); $this->assertEqual($Controller->Orange->settings, array('colour' => 'blood orange', 'ripeness' => 'perfect'));
$this->assertEqual($Controller->ParamTest->test, 'value'); $this->assertEqual($Controller->ParamTest->test, 'value');

View file

@ -51,6 +51,9 @@ class CookieComponentTest extends CakeTestCase {
function start() { function start() {
$this->Controller = new CookieComponentTestController(); $this->Controller = new CookieComponentTestController();
$this->Controller->constructClasses(); $this->Controller->constructClasses();
$this->Controller->Component->initialize($this->Controller);
$this->Controller->beforeFilter();
$this->Controller->Component->startup($this->Controller);
$this->Controller->Cookie->destroy(); $this->Controller->Cookie->destroy();
} }

View file

@ -138,9 +138,16 @@ class RequestHandlerComponentTest extends CakeTestCase {
function testDisabling() { function testDisabling() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->_init(); $this->_init();
$this->Controller->Component->initialize($this->Controller);
$this->Controller->beforeFilter();
$this->Controller->Component->startup($this->Controller);
$this->assertEqual($this->Controller->params, array('isAjax' => true)); $this->assertEqual($this->Controller->params, array('isAjax' => true));
$this->Controller = new RequestHandlerTestDisabledController(array('components' => array('RequestHandler'))); $this->Controller = new RequestHandlerTestDisabledController(array('components' => array('RequestHandler')));
$this->Controller->constructClasses();
$this->Controller->Component->initialize($this->Controller);
$this->Controller->beforeFilter();
$this->Controller->Component->startup($this->Controller);
$this->assertEqual($this->Controller->params, array()); $this->assertEqual($this->Controller->params, array());
unset($_SERVER['HTTP_X_REQUESTED_WITH']); unset($_SERVER['HTTP_X_REQUESTED_WITH']);
} }