From 08bcf4a615ab12eaf7e3f7bcc37fdddf19f647bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Tue, 8 Jun 2010 23:58:01 -0430 Subject: [PATCH] Migrating DispatcherTest to PHPUnit, alos removing class dependencies from test folder home.ctp file --- cake/tests/cases/dispatcher.test.php | 125 ++++++++++++----------- cake/tests/test_app/views/pages/home.ctp | 12 +-- 2 files changed, 66 insertions(+), 71 deletions(-) diff --git a/cake/tests/cases/dispatcher.test.php b/cake/tests/cases/dispatcher.test.php index 517e1b52b91..5cd41fd14f6 100644 --- a/cake/tests/cases/dispatcher.test.php +++ b/cake/tests/cases/dispatcher.test.php @@ -42,14 +42,11 @@ class TestDispatcher extends Dispatcher { * @return void */ protected function _invoke(&$controller, $params) { - restore_error_handler(); if ($result = parent::_invoke($controller, $params)) { if ($result[0] === 'missingAction') { return $result; } } - set_error_handler('simpleTestErrorHandler'); - return $controller; } @@ -537,7 +534,7 @@ class DispatcherTest extends CakeTestCase { * * @return void */ - public function startTest() { + public function setUp() { $this->_get = $_GET; $_GET = array(); $this->_post = $_POST; @@ -563,7 +560,7 @@ public function startTest() { * * @return void */ - public function endTest() { + public function tearDown() { $_GET = $this->_get; $_POST = $this->_post; $_FILES = $this->_files; @@ -580,7 +577,7 @@ public function endTest() { * @return void */ public function testParseParamsWithoutZerosAndEmptyPost() { - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $test = $Dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3"); $this->assertIdentical($test['controller'], 'testcontroller'); $this->assertIdentical($test['action'], 'testaction'); @@ -597,10 +594,10 @@ public function testParseParamsWithoutZerosAndEmptyPost() { */ public function testParseParamsReturnsPostedData() { $_POST['testdata'] = "My Posted Content"; - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $test = $Dispatcher->parseParams("/"); - $this->assertTrue($test['form'], "Parsed URL not returning post data"); - $this->assertIdentical($test['form']['testdata'], "My Posted Content"); + $this->assertFalse(empty($test['form']), "Parsed URL not returning post data"); + $this->assertEquals($test['form']['testdata'], "My Posted Content"); } /** @@ -609,7 +606,7 @@ public function testParseParamsReturnsPostedData() { * @return void */ public function testParseParamsWithSingleZero() { - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $test = $Dispatcher->parseParams("/testcontroller/testaction/1/0/23"); $this->assertIdentical($test['controller'], 'testcontroller'); $this->assertIdentical($test['action'], 'testaction'); @@ -624,7 +621,7 @@ public function testParseParamsWithSingleZero() { * @return void */ public function testParseParamsWithManySingleZeros() { - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $test = $Dispatcher->parseParams("/testcontroller/testaction/0/0/0/0/0/0"); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][0]); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]); @@ -640,7 +637,7 @@ public function testParseParamsWithManySingleZeros() { * @return void */ public function testParseParamsWithManyZerosInEachSectionOfUrl() { - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $test = $Dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000"); $this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0]); $this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1]); @@ -656,7 +653,7 @@ public function testParseParamsWithManyZerosInEachSectionOfUrl() { * @return void */ public function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() { - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $test = $Dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400"); $this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]); $this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1]); @@ -677,7 +674,7 @@ public function testQueryStringOnRoot() { Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); $_GET = array('coffee' => 'life', 'sleep' => 'sissies'); - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $uri = 'posts/home/?coffee=life&sleep=sissies'; $result = $Dispatcher->parseParams($uri); $this->assertPattern('/posts/', $result['controller']); @@ -685,7 +682,7 @@ public function testQueryStringOnRoot() { $this->assertTrue(isset($result['url']['sleep'])); $this->assertTrue(isset($result['url']['coffee'])); - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $uri = '/?coffee=life&sleep=sissy'; $result = $Dispatcher->parseParams($uri); $this->assertPattern('/pages/', $result['controller']); @@ -748,7 +745,7 @@ public function testFileUploadArrayStructure() { ), )); - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $result = $Dispatcher->parseParams('/'); $expected = array( @@ -866,7 +863,7 @@ public function testFileUploadArrayStructure() { ) ) ); - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $result = $Dispatcher->parseParams('/'); $expected = array( 'Document' => array( @@ -931,7 +928,7 @@ public function testFileUploadArrayStructure() { ) ); - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $result = $Dispatcher->parseParams('/'); $expected = array( @@ -953,7 +950,7 @@ public function testFileUploadArrayStructure() { * @return void */ public function testGetUrl() { - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $Dispatcher->base = '/app/webroot/index.php'; $uri = '/app/webroot/index.php/posts/add'; $result = $Dispatcher->getUrl($uri); @@ -969,7 +966,7 @@ public function testGetUrl() { $_GET['url'] = array(); Configure::write('App.base', '/control'); - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $Dispatcher->baseUrl(); $uri = '/control/students/browse'; $result = $Dispatcher->getUrl($uri); @@ -977,7 +974,7 @@ public function testGetUrl() { $this->assertEqual($expected, $result); $_GET['url'] = array(); - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $Dispatcher->base = ''; $uri = '/?/home'; $result = $Dispatcher->getUrl($uri); @@ -992,7 +989,7 @@ public function testGetUrl() { * @return void */ public function testBaseUrlAndWebrootWithModRewrite() { - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $Dispatcher->base = false; $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches'; @@ -1073,7 +1070,7 @@ public function testBaseUrlwithModRewriteAlias() { Configure::write('App.base', '/control'); - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $result = $Dispatcher->baseUrl(); $expected = '/control'; $this->assertEqual($expected, $result); @@ -1087,7 +1084,7 @@ public function testBaseUrlwithModRewriteAlias() { $_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html'; $_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php'; $_SERVER['PHP_SELF'] = '/newaffiliate/index.php'; - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $result = $Dispatcher->baseUrl(); $expected = '/newaffiliate'; $this->assertEqual($expected, $result); @@ -1101,7 +1098,7 @@ public function testBaseUrlwithModRewriteAlias() { * @return void */ public function testBaseUrlAndWebrootWithBaseUrl() { - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); Configure::write('App.dir', 'app'); @@ -1170,7 +1167,7 @@ public function testBaseUrlAndWebrootWithBaseUrl() { * @return void */ public function testBaseUrlAndWebrootWithBase() { - $Dispatcher =& new Dispatcher(); + $Dispatcher = new Dispatcher(); $Dispatcher->base = '/app'; $result = $Dispatcher->baseUrl(); $expected = '/app'; @@ -1200,7 +1197,7 @@ public function testBaseUrlAndWebrootWithBase() { * @return void */ public function testMissingController() { - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl', '/index.php'); $url = 'some_controller/home/param:value/param2:value2'; $controller = $Dispatcher->dispatch($url, array('return' => 1)); @@ -1219,7 +1216,7 @@ public function testMissingController() { * @return void */ public function testPrivate() { - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl','/index.php'); $url = 'some_pages/_protected/param:value/param2:value2'; @@ -1241,7 +1238,7 @@ public function testPrivate() { * @return void */ public function testMissingAction() { - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl', '/index.php'); $url = 'some_pages/home/param:value/param2:value2'; @@ -1256,7 +1253,7 @@ public function testMissingAction() { ))); $this->assertEqual($expected, $controller); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl','/index.php'); $url = 'some_pages/redirect/param:value/param2:value2'; @@ -1278,7 +1275,10 @@ public function testMissingAction() { * @return void */ public function testDispatch() { - $Dispatcher =& new TestDispatcher(); + App::build(array( + 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) + )); + $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl','/index.php'); $url = 'pages/home/param:value/param2:value2'; @@ -1307,7 +1307,7 @@ public function testDispatch() { unset($Dispatcher); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl','/timesheets/index.php'); $url = 'timesheets'; @@ -1339,7 +1339,10 @@ public function testDispatch() { * @return void */ public function testDispatchWithArray() { - $Dispatcher =& new TestDispatcher(); + App::build(array( + 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) + )); + $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl','/index.php'); $url = 'pages/home/param:value/param2:value2'; @@ -1359,13 +1362,13 @@ public function testDispatchWithArray() { */ public function testAdminDispatch() { $_POST = array(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Configure::write('Routing.prefixes', array('admin')); Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php'); $url = 'admin/test_dispatch_pages/index/param:value/param2:value2'; Router::reload(); - $Router =& Router::getInstance(); + $Router = Router::getInstance(); $controller = $Dispatcher->dispatch($url, array('return' => 1)); $this->assertEqual($controller->name, 'TestDispatchPages'); @@ -1390,7 +1393,7 @@ public function testPluginDispatch() { $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; Router::reload(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Router::connect( '/my_plugin/:controller/*', array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display') @@ -1404,7 +1407,7 @@ public function testPluginDispatch() { $expected = array( 'pass' => array('home'), 'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin', - 'controller'=> 'some_pages', 'action'=> 'display', 'form'=> null, + 'controller'=> 'some_pages', 'action'=> 'display', 'form'=> array(), 'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'), ); ksort($expected); @@ -1434,7 +1437,7 @@ public function testAutomaticPluginDispatch() { $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; Router::reload(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Router::connect( '/my_plugin/:controller/:action/*', array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display') @@ -1473,7 +1476,7 @@ public function testAutomaticPluginControllerDispatch() { App::setObjects('plugin', $plugins); Router::reload(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $Dispatcher->base = false; $url = 'my_plugin/my_plugin/add/param:value/param2:value2'; @@ -1487,7 +1490,7 @@ public function testAutomaticPluginControllerDispatch() { Router::reload(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $Dispatcher->base = false; // Simulates the Route for a real plugin, installed in APP/plugins @@ -1509,7 +1512,7 @@ public function testAutomaticPluginControllerDispatch() { Configure::write('Routing.prefixes', array('admin')); Router::reload(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $Dispatcher->base = false; $url = 'admin/my_plugin/my_plugin/add/5/param:value/param2:value2'; @@ -1530,7 +1533,7 @@ public function testAutomaticPluginControllerDispatch() { Configure::write('Routing.prefixes', array('admin')); Router::reload(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $Dispatcher->base = false; $controller = $Dispatcher->dispatch('admin/articles_test', array('return' => 1)); @@ -1568,7 +1571,7 @@ public function testAutomaticPluginDispatchWithShortAccess() { App::setObjects('plugin', $plugins); Router::reload(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $Dispatcher->base = false; $url = 'my_plugin/'; @@ -1596,7 +1599,7 @@ function testPluginShortCutUrlsWithControllerThatNeedsToBeLoaded() { ), true); App::objects('plugin', null, false); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $Dispatcher->base = false; $url = 'test_plugin/'; @@ -1633,7 +1636,7 @@ public function testAutomaticPluginControllerMissingActionDispatch() { $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; Router::reload(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $Dispatcher->base = false; $url = 'my_plugin/not_here/param:value/param2:value2'; @@ -1649,7 +1652,7 @@ public function testAutomaticPluginControllerMissingActionDispatch() { $this->assertIdentical($expected, $controller); Router::reload(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $Dispatcher->base = false; $url = 'my_plugin/param:value/param2:value2'; @@ -1677,7 +1680,7 @@ public function testPrefixProtection() { Router::reload(); Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin'), array('controller', 'action')); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $Dispatcher->base = false; $url = 'test_dispatch_pages/admin_index/param:value/param2:value2'; @@ -1699,7 +1702,7 @@ public function testPrefixProtection() { * @return void */ public function testTestPluginDispatch() { - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); App::build(array( 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) )); @@ -1728,7 +1731,7 @@ public function testTestPluginDispatch() { */ public function testChangingParamsFromBeforeFilter() { $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $url = 'some_posts/index/param:value/param2:value2'; $controller = $Dispatcher->dispatch($url, array('return' => 1)); @@ -1761,7 +1764,7 @@ public function testChangingParamsFromBeforeFilter() { */ public function testAssets() { Router::reload(); - $Configure =& Configure::getInstance(); + $Configure = Configure::getInstance(); $Configure->__objects = null; App::build(array( @@ -1770,19 +1773,19 @@ public function testAssets() { 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) )); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); $debug = Configure::read('debug'); Configure::write('debug', 0); ob_start(); $Dispatcher->dispatch('theme/test_theme/../webroot/css/test_asset.css'); $result = ob_get_clean(); - $this->assertFalse($result); + $this->assertEquals($result, ''); ob_start(); $Dispatcher->dispatch('theme/test_theme/pdfs'); $result = ob_get_clean(); - $this->assertFalse($result); + $this->assertEquals($result, ''); ob_start(); $Dispatcher->dispatch('theme/test_theme/flash/theme_test.swf'); @@ -1904,7 +1907,7 @@ public function testAssets() { * @return void */ function testMissingAssetProcessor404() { - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Configure::write('Asset.filter', array( 'js' => '', 'css' => null @@ -1925,7 +1928,7 @@ function testMissingAssetProcessor404() { * @return void */ function testAssetFilterForThemeAndPlugins() { - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Configure::write('Asset.filter', array( 'js' => '', 'css' => '' @@ -1973,7 +1976,7 @@ public function testFullPageCachingDispatch() { 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS), ), true); - $dispatcher =& new TestDispatcher(); + $dispatcher = new TestDispatcher(); $dispatcher->base = false; $url = '/'; @@ -2107,7 +2110,7 @@ function testCachedRegisteringViewObject() { 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) )); - $dispatcher =& new TestDispatcher(); + $dispatcher = new TestDispatcher(); $dispatcher->base = false; $url = 'test_cached_pages/cache_form'; @@ -2141,7 +2144,7 @@ public function testHttpMethodOverrides() { Router::mapResources('Posts'); $_SERVER['REQUEST_METHOD'] = 'POST'; - $dispatcher =& new Dispatcher(); + $dispatcher = new Dispatcher(); $dispatcher->base = false; $result = $dispatcher->parseParams('/posts'); @@ -2195,7 +2198,7 @@ public function testBasePathInjection() { "/index.php/%22%3E%3Ch1%20onclick=%22alert('xss');%22%3Eheya%3C/h1%3E" ); - $dispatcher =& new Dispatcher(); + $dispatcher = new Dispatcher(); $result = $dispatcher->baseUrl(); $expected = '/index.php/h1 onclick=alert(xss);heya'; $this->assertEqual($result, $expected); @@ -2207,7 +2210,7 @@ public function testBasePathInjection() { * @return void */ public function testEnvironmentDetection() { - $dispatcher =& new Dispatcher(); + $dispatcher = new Dispatcher(); $environments = array( 'IIS' => array( @@ -2316,7 +2319,7 @@ public function testTrailingSlash() { $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; Router::reload(); - $Dispatcher =& new TestDispatcher(); + $Dispatcher = new TestDispatcher(); Router::connect('/myalias/:action/*', array('controller' => 'my_controller', 'action' => null)); $Dispatcher->base = false; diff --git a/cake/tests/test_app/views/pages/home.ctp b/cake/tests/test_app/views/pages/home.ctp index 196f1af6de7..17ab0dfc815 100644 --- a/cake/tests/test_app/views/pages/home.ctp +++ b/cake/tests/test_app/views/pages/home.ctp @@ -1,10 +1,4 @@

Sweet, "Test App" got Baked by CakePHP!

- - 0): - Debugger::checkSecurityKeys(); -endif; -?>

'; printf(__('The %s is being used for caching. To change the config edit APP/config/core.php '), ''. $settings['engine'] . 'Engine'); @@ -54,12 +48,10 @@ if (!empty($filePresent)): if (!class_exists('ConnectionManager')) { require LIBS . 'model' . DS . 'connection_manager.php'; } - $db = ConnectionManager::getInstance(); - $connected = $db->getDataSource('default'); ?>

isConnected()): + if (true): echo ''; echo __('Cake is able to connect to the database.'); echo '';