Removing extraneous error catching from Dispatcher and View tests

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6701 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-04-19 13:43:07 +00:00
parent 16bfee9831
commit b7774103f8
2 changed files with 5 additions and 67 deletions

View file

@ -574,9 +574,7 @@ class DispatcherTest extends UnitTestCase {
$Dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
Configure::write('App.baseUrl','/index.php'); Configure::write('App.baseUrl','/index.php');
$url = 'some_controller/home/param:value/param2:value2'; $url = 'some_controller/home/param:value/param2:value2';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'missingController'; $expected = 'missingController';
$this->assertEqual($expected, $controller); $this->assertEqual($expected, $controller);
@ -586,10 +584,7 @@ class DispatcherTest extends UnitTestCase {
$Dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
Configure::write('App.baseUrl','/index.php'); Configure::write('App.baseUrl','/index.php');
$url = 'some_pages/redirect/param:value/param2:value2'; $url = 'some_pages/redirect/param:value/param2:value2';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'privateAction'; $expected = 'privateAction';
$this->assertEqual($expected, $controller); $this->assertEqual($expected, $controller);
@ -600,9 +595,7 @@ class DispatcherTest extends UnitTestCase {
Configure::write('App.baseUrl','/index.php'); Configure::write('App.baseUrl','/index.php');
$url = 'some_pages/home/param:value/param2:value2'; $url = 'some_pages/home/param:value/param2:value2';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return'=> 1)); $controller = $Dispatcher->dispatch($url, array('return'=> 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'missingAction'; $expected = 'missingAction';
$this->assertEqual($expected, $controller); $this->assertEqual($expected, $controller);
} }
@ -612,31 +605,23 @@ class DispatcherTest extends UnitTestCase {
Configure::write('App.baseUrl','/index.php'); Configure::write('App.baseUrl','/index.php');
$url = 'pages/home/param:value/param2:value2'; $url = 'pages/home/param:value/param2:value2';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'Pages'; $expected = 'Pages';
$this->assertEqual($expected, $controller->name); $this->assertEqual($expected, $controller->name);
$expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2'); $expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
$this->assertIdentical($expected, $controller->passedArgs); $this->assertIdentical($expected, $controller->passedArgs);
Configure::write('App.baseUrl','/pages/index.php'); Configure::write('App.baseUrl','/pages/index.php');
$url = 'pages/home'; $url = 'pages/home';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'Pages'; $expected = 'Pages';
$this->assertEqual($expected, $controller->name); $this->assertEqual($expected, $controller->name);
$url = 'pages/home/'; $url = 'pages/home/';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'Pages'; $expected = 'Pages';
$this->assertEqual($expected, $controller->name); $this->assertEqual($expected, $controller->name);
@ -647,17 +632,13 @@ class DispatcherTest extends UnitTestCase {
Configure::write('App.baseUrl','/timesheets/index.php'); Configure::write('App.baseUrl','/timesheets/index.php');
$url = 'timesheets'; $url = 'timesheets';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'Timesheets'; $expected = 'Timesheets';
$this->assertEqual($expected, $controller->name); $this->assertEqual($expected, $controller->name);
$url = 'timesheets/'; $url = 'timesheets/';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$this->assertEqual('Timesheets', $controller->name); $this->assertEqual('Timesheets', $controller->name);
$this->assertEqual('/timesheets/index.php', $Dispatcher->base); $this->assertEqual('/timesheets/index.php', $Dispatcher->base);
@ -672,10 +653,7 @@ class DispatcherTest extends UnitTestCase {
Router::reload(); Router::reload();
$Router =& Router::getInstance(); $Router =& Router::getInstance();
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'TestDispatchPages'; $expected = 'TestDispatchPages';
$this->assertEqual($expected, $controller->name); $this->assertEqual($expected, $controller->name);
@ -701,11 +679,7 @@ class DispatcherTest extends UnitTestCase {
$Dispatcher->base = false; $Dispatcher->base = false;
$url = 'my_plugin/some_pages/home/param:value/param2:value2'; $url = 'my_plugin/some_pages/home/param:value/param2:value2';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$result = $Dispatcher->parseParams($url); $result = $Dispatcher->parseParams($url);
$expected = array( $expected = array(
@ -746,10 +720,7 @@ class DispatcherTest extends UnitTestCase {
$Dispatcher->base = false; $Dispatcher->base = false;
$url = 'my_plugin/other_pages/index/param:value/param2:value2'; $url = 'my_plugin/other_pages/index/param:value/param2:value2';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'my_plugin'; $expected = 'my_plugin';
$this->assertIdentical($expected, $controller->plugin); $this->assertIdentical($expected, $controller->plugin);
@ -760,7 +731,7 @@ class DispatcherTest extends UnitTestCase {
$expected = 'index'; $expected = 'index';
$this->assertIdentical($expected, $controller->action); $this->assertIdentical($expected, $controller->action);
$expected = array('param'=>'value', 'param2'=>'value2'); $expected = array('param' => 'value', 'param2' => 'value2');
$this->assertIdentical($expected, $controller->passedArgs); $this->assertIdentical($expected, $controller->passedArgs);
$expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2'; $expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2';
@ -780,9 +751,7 @@ class DispatcherTest extends UnitTestCase {
$url = 'my_plugin/add/param:value/param2:value2'; $url = 'my_plugin/add/param:value/param2:value2';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'my_plugin'; $expected = 'my_plugin';
$this->assertIdentical($controller->plugin, $expected); $this->assertIdentical($controller->plugin, $expected);
@ -804,10 +773,7 @@ class DispatcherTest extends UnitTestCase {
$Dispatcher->base = false; $Dispatcher->base = false;
$url = 'admin/my_plugin/add/5/param:value/param2:value2'; $url = 'admin/my_plugin/add/5/param:value/param2:value2';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'my_plugin'; $expected = 'my_plugin';
$this->assertIdentical($controller->plugin, $expected); $this->assertIdentical($controller->plugin, $expected);
@ -826,11 +792,7 @@ class DispatcherTest extends UnitTestCase {
$Dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
$Dispatcher->base = false; $Dispatcher->base = false;
$url = 'admin/articles_test'; $controller = $Dispatcher->dispatch('admin/articles_test', array('return' => 1));
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'articles_test'; $expected = 'articles_test';
$this->assertIdentical($controller->plugin, $expected); $this->assertIdentical($controller->plugin, $expected);
@ -857,9 +819,7 @@ class DispatcherTest extends UnitTestCase {
$Dispatcher->base = false; $Dispatcher->base = false;
$url = 'my_plugin/param:value/param2:value2'; $url = 'my_plugin/param:value/param2:value2';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return'=> 1)); $controller = $Dispatcher->dispatch($url, array('return'=> 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'missingAction'; $expected = 'missingAction';
$this->assertIdentical($expected, $controller); $this->assertIdentical($expected, $controller);
@ -876,9 +836,7 @@ class DispatcherTest extends UnitTestCase {
$Dispatcher->base = false; $Dispatcher->base = false;
$url = 'test_dispatch_pages/admin_index/param:value/param2:value2'; $url = 'test_dispatch_pages/admin_index/param:value/param2:value2';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'privateAction'; $expected = 'privateAction';
$this->assertIdentical($expected, $controller); $this->assertIdentical($expected, $controller);
@ -887,10 +845,7 @@ class DispatcherTest extends UnitTestCase {
function testChangingParamsFromBeforeFilter() { function testChangingParamsFromBeforeFilter() {
$Dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
$url = 'some_posts/index/param:value/param2:value2'; $url = 'some_posts/index/param:value/param2:value2';
restore_error_handler();
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler');
$expected = 'SomePosts'; $expected = 'SomePosts';
$this->assertEqual($expected, $controller->name); $this->assertEqual($expected, $controller->name);
@ -915,20 +870,16 @@ class DispatcherTest extends UnitTestCase {
Configure::write('debug', 0); Configure::write('debug', 0);
$Dispatcher->params = $Dispatcher->parseParams('css/test_asset.css'); $Dispatcher->params = $Dispatcher->parseParams('css/test_asset.css');
restore_error_handler();
ob_start(); ob_start();
$Dispatcher->cached('css/test_asset.css'); $Dispatcher->cached('css/test_asset.css');
$result = ob_get_clean(); $result = ob_get_clean();
set_error_handler('simpleTestErrorHandler');
$this->assertEqual('this is the test asset css file', $result); $this->assertEqual('this is the test asset css file', $result);
Configure::write('debug', 0); Configure::write('debug', 0);
$Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css'); $Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css');
restore_error_handler();
ob_start(); ob_start();
$Dispatcher->cached('test_plugin/css/test_plugin_asset.css'); $Dispatcher->cached('test_plugin/css/test_plugin_asset.css');
$result = ob_get_clean(); $result = ob_get_clean();
set_error_handler('simpleTestErrorHandler');
$this->assertEqual('this is the test plugin asset css file', $result); $this->assertEqual('this is the test plugin asset css file', $result);
} }
@ -950,7 +901,6 @@ class DispatcherTest extends UnitTestCase {
$url = '/'; $url = '/';
restore_error_handler();
ob_start(); ob_start();
$dispatcher->dispatch($url); $dispatcher->dispatch($url);
$out = ob_get_clean(); $out = ob_get_clean();
@ -959,8 +909,6 @@ class DispatcherTest extends UnitTestCase {
$dispatcher->cached($url); $dispatcher->cached($url);
$cached = ob_get_clean(); $cached = ob_get_clean();
set_error_handler('simpleTestErrorHandler');
$result = str_replace(array("\t", "\r\n", "\n"), "", $out); $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached); $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
@ -969,12 +917,9 @@ class DispatcherTest extends UnitTestCase {
$filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php'; $filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php';
unlink($filename); unlink($filename);
$dispatcher->base = false; $dispatcher->base = false;
$url = 'test_cached_pages/index'; $url = 'test_cached_pages/index';
restore_error_handler();
ob_start(); ob_start();
$dispatcher->dispatch($url); $dispatcher->dispatch($url);
$out = ob_get_clean(); $out = ob_get_clean();
@ -983,8 +928,6 @@ class DispatcherTest extends UnitTestCase {
$dispatcher->cached($url); $dispatcher->cached($url);
$cached = ob_get_clean(); $cached = ob_get_clean();
set_error_handler('simpleTestErrorHandler');
$result = str_replace(array("\t", "\r\n", "\n"), "", $out); $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached); $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
@ -995,7 +938,6 @@ class DispatcherTest extends UnitTestCase {
$url = 'TestCachedPages/index'; $url = 'TestCachedPages/index';
restore_error_handler();
ob_start(); ob_start();
$dispatcher->dispatch($url); $dispatcher->dispatch($url);
$out = ob_get_clean(); $out = ob_get_clean();
@ -1004,8 +946,6 @@ class DispatcherTest extends UnitTestCase {
$dispatcher->cached($url); $dispatcher->cached($url);
$cached = ob_get_clean(); $cached = ob_get_clean();
set_error_handler('simpleTestErrorHandler');
$result = str_replace(array("\t", "\r\n", "\n"), "", $out); $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached); $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);

View file

@ -136,12 +136,11 @@ class ViewTest extends UnitTestCase {
$this->Controller->action = 'display'; $this->Controller->action = 'display';
$this->Controller->params['pass'] = array('home'); $this->Controller->params['pass'] = array('home');
restore_error_handler();
$View = new TestView($this->Controller); $View = new TestView($this->Controller);
ob_start(); ob_start();
$result = $View->getViewFileName('does_not_exist'); $result = $View->getViewFileName('does_not_exist');
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean()); $expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
set_error_handler('simpleTestErrorHandler');
$this->assertPattern("/PagesController::/", $expected); $this->assertPattern("/PagesController::/", $expected);
$this->assertPattern("/pages\/does_not_exist.ctp/", $expected); $this->assertPattern("/pages\/does_not_exist.ctp/", $expected);
} }
@ -152,12 +151,11 @@ class ViewTest extends UnitTestCase {
$this->Controller->viewPath = 'posts'; $this->Controller->viewPath = 'posts';
$this->Controller->layout = 'whatever'; $this->Controller->layout = 'whatever';
restore_error_handler();
$View = new TestView($this->Controller); $View = new TestView($this->Controller);
ob_start(); ob_start();
$result = $View->getLayoutFileName(); $result = $View->getLayoutFileName();
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean()); $expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
set_error_handler('simpleTestErrorHandler');
$this->assertPattern("/Missing Layout/", $expected); $this->assertPattern("/Missing Layout/", $expected);
$this->assertPattern("/layouts\/whatever.ctp/", $expected); $this->assertPattern("/layouts\/whatever.ctp/", $expected);