updating dispatcher, added test, fixes #3504

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5940 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-11-03 16:39:29 +00:00
parent acc197827e
commit 6a7b7a5c36
2 changed files with 157 additions and 155 deletions

View file

@ -94,7 +94,7 @@ class Dispatcher extends Object {
*/ */
function __construct($url = null, $base = false) { function __construct($url = null, $base = false) {
parent::__construct(); parent::__construct();
if($base !== false) { if ($base !== false) {
Configure::write('App.base', $base); Configure::write('App.base', $base);
} }
$this->base = Configure::read('App.base'); $this->base = Configure::read('App.base');
@ -128,24 +128,16 @@ class Dispatcher extends Object {
$this->params = array_merge($this->parseParams($url), $additionalParams); $this->params = array_merge($this->parseParams($url), $additionalParams);
$controller = $this->__getController(); $controller = $this->__getController();
if(!is_object($controller)) { if (!is_object($controller)) {
if (preg_match('/([\\.]+)/', $controller)) { Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot)));
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot))); return $this->cakeError('missingController', array(
array(
return $this->cakeError('error404', array(array('url' => strtolower($controller), 'className' => Inflector::camelize($this->params['controller']) . 'Controller',
'message' => __('Was not found on this server', true), 'webroot' => $this->webroot,
'base' => $this->base))); 'url' => $url,
} else { 'base' => $this->base
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot))); )
return $this->cakeError('missingController', array( ));
array(
'className' => Inflector::camelize($this->params['controller']) . 'Controller',
'webroot' => $this->webroot,
'url' => $url,
'base' => $this->base
)
));
}
} }
$missingAction = $missingView = $privateAction = false; $missingAction = $missingView = $privateAction = false;
@ -225,7 +217,7 @@ class Dispatcher extends Object {
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot))); Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot)));
$controller->_initComponents(); $controller->_initComponents();
if(isset($this->plugin)) { if (isset($this->plugin)) {
loadPluginModels($this->plugin); loadPluginModels($this->plugin);
} }
@ -403,54 +395,57 @@ class Dispatcher extends Object {
* @access public * @access public
*/ */
function baseUrl() { function baseUrl() {
if($this->base !== false) {
$this->webroot = $this->base .'/';
return $this->base;
}
$base = '';
$this->webroot = '/';
$config = Configure::read('App'); $config = Configure::read('App');
extract($config); extract($config);
$file = null; if (!$base) {
$base = $this->base;
}
if ($base !== false) {
$this->webroot = $base .'/';
return $base;
}
if (!$baseUrl) { if (!$baseUrl) {
$base = env('PHP_SELF'); $base = dirname(env('PHP_SELF'));
} elseif ($baseUrl) {
$base = $baseUrl;
$file = '/' . basename($base);
}
$base = dirname($base); if (in_array($base, array(DS, '.'))) {
if (in_array($base, array(DS, '.'))) { $base = '';
$base = ''; }
} if ($base == '') {
if(!$baseUrl) {
if($base == '') {
$this->webroot = '/'; $this->webroot = '/';
return $base; return $base;
} }
if($dir === 'app') { if ($webroot === 'webroot' && $webroot === basename($base)) {
$base = str_replace('/app', '', $base); $base = dirname($base);
} }
if ($webroot === 'webroot') { if ($dir === 'app' && $dir === basename($base)) {
$base = str_replace('/webroot', '', $base); $base = dirname($base);
} }
$this->webroot = $base .'/'; $this->webroot = $base .'/';
return $base; return $base;
} }
$this->webroot = $base .'/'; $file = null;
if ($baseUrl) {
$file = '/' . basename($baseUrl);
$base = dirname($baseUrl);
if (in_array($base, array(DS, '.'))) {
$base = '';
}
$this->webroot = $base .'/';
if (strpos($this->webroot, $dir) === false) { if (strpos($this->webroot, $dir) === false) {
$this->webroot .= $dir . '/' ; $this->webroot .= $dir . '/' ;
}
if (strpos($this->webroot, $webroot) === false) {
$this->webroot .= $webroot . '/';
}
return $base . $file;
} }
if (strpos($this->webroot, $webroot) === false) { return false;
$this->webroot .= $webroot . '/';
}
return $base . $file;
} }
/** /**
* Restructure params in case we're serving a plugin. * Restructure params in case we're serving a plugin.
@ -485,7 +480,7 @@ class Dispatcher extends Object {
$controller = false; $controller = false;
if (!$ctrlClass = $this->__loadController($params)) { if (!$ctrlClass = $this->__loadController($params)) {
if(!isset($params['plugin'])) { if (!isset($params['plugin'])) {
$params = $this->_restructureParams($params); $params = $this->_restructureParams($params);
} }
if (!$ctrlClass = $this->__loadController($params)) { if (!$ctrlClass = $this->__loadController($params)) {
@ -612,7 +607,7 @@ class Dispatcher extends Object {
} else { } else {
$url = $_GET['url']; $url = $_GET['url'];
} }
if($url{0} == '/') { if ($url{0} == '/') {
$url = substr($url, 1); $url = substr($url, 1);
} }
return $url; return $url;

View file

@ -153,6 +153,7 @@ class DispatcherTest extends UnitTestCase {
function setUp() { function setUp() {
$this->_get = $_GET; $this->_get = $_GET;
$_GET = array(); $_GET = array();
Configure::write('App.base', false);
Configure::write('App.baseUrl', false); Configure::write('App.baseUrl', false);
Configure::write('App.dir', 'app'); Configure::write('App.dir', 'app');
Configure::write('App.webroot', 'webroot'); Configure::write('App.webroot', 'webroot');
@ -160,8 +161,8 @@ class DispatcherTest extends UnitTestCase {
} }
function testParseParamsWithoutZerosAndEmptyPost() { function testParseParamsWithoutZerosAndEmptyPost() {
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3"); $test = $Dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3");
$this->assertIdentical($test['controller'], 'testcontroller'); $this->assertIdentical($test['controller'], 'testcontroller');
$this->assertIdentical($test['action'], 'testaction'); $this->assertIdentical($test['action'], 'testaction');
$this->assertIdentical($test['pass'][0], 'params1'); $this->assertIdentical($test['pass'][0], 'params1');
@ -172,15 +173,15 @@ class DispatcherTest extends UnitTestCase {
function testParseParamsReturnsPostedData() { function testParseParamsReturnsPostedData() {
$_POST['testdata'] = "My Posted Content"; $_POST['testdata'] = "My Posted Content";
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/"); $test = $Dispatcher->parseParams("/");
$this->assertTrue($test['form'], "Parsed URL not returning post data"); $this->assertTrue($test['form'], "Parsed URL not returning post data");
$this->assertIdentical($test['form']['testdata'], "My Posted Content"); $this->assertIdentical($test['form']['testdata'], "My Posted Content");
} }
function testParseParamsWithSingleZero() { function testParseParamsWithSingleZero() {
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/1/0/23"); $test = $Dispatcher->parseParams("/testcontroller/testaction/1/0/23");
$this->assertIdentical($test['controller'], 'testcontroller'); $this->assertIdentical($test['controller'], 'testcontroller');
$this->assertIdentical($test['action'], 'testaction'); $this->assertIdentical($test['action'], 'testaction');
$this->assertIdentical($test['pass'][0], '1'); $this->assertIdentical($test['pass'][0], '1');
@ -189,8 +190,8 @@ class DispatcherTest extends UnitTestCase {
} }
function testParseParamsWithManySingleZeros() { function testParseParamsWithManySingleZeros() {
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/0/0/0/0/0/0"); $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'][0]);
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][2]); $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][2]);
@ -200,8 +201,8 @@ class DispatcherTest extends UnitTestCase {
} }
function testParseParamsWithManyZerosInEachSectionOfUrl() { function testParseParamsWithManyZerosInEachSectionOfUrl() {
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000"); $test = $Dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
$this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0]); $this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0]);
$this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1]); $this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1]);
$this->assertPattern('/\\A(?:00000)\\z/', $test['pass'][2]); $this->assertPattern('/\\A(?:00000)\\z/', $test['pass'][2]);
@ -211,8 +212,8 @@ class DispatcherTest extends UnitTestCase {
} }
function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() { function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400"); $test = $Dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
$this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]); $this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]);
$this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1]); $this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1]);
$this->assertPattern('/\\A(?:04010)\\z/', $test['pass'][2]); $this->assertPattern('/\\A(?:04010)\\z/', $test['pass'][2]);
@ -222,80 +223,87 @@ class DispatcherTest extends UnitTestCase {
} }
function testGetUrl() { function testGetUrl() {
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
$dispatcher->base = '/app/webroot/index.php'; $Dispatcher->base = '/app/webroot/index.php';
$uri = '/app/webroot/index.php/posts/add'; $uri = '/app/webroot/index.php/posts/add';
$result = $dispatcher->getUrl($uri); $result = $Dispatcher->getUrl($uri);
$expected = 'posts/add'; $expected = 'posts/add';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
Configure::write('App.baseUrl', '/app/webroot/index.php'); Configure::write('App.baseUrl', '/app/webroot/index.php');
$uri = '/posts/add'; $uri = '/posts/add';
$result = $dispatcher->getUrl($uri); $result = $Dispatcher->getUrl($uri);
$expected = 'posts/add'; $expected = 'posts/add';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$_GET['url'] = array(); $_GET['url'] = array();
Configure::write('App.base', '/control'); Configure::write('App.base', '/control');
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
$uri = '/control/students/browse'; $uri = '/control/students/browse';
$result = $dispatcher->getUrl($uri); $result = $Dispatcher->getUrl($uri);
$expected = 'students/browse'; $expected = 'students/browse';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
} }
function testBaseUrlAndWebrootWithModRewrite() { function testBaseUrlAndWebrootWithModRewrite() {
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
Configure::write('App.baseUrl', false); $Dispatcher->base = false;
$dispatcher->base = false;
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches'; $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php'; $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
$_SERVER['PHP_SELF'] = '/1.2.x.x/app/webroot/index.php'; $_SERVER['PHP_SELF'] = '/1.2.x.x/app/webroot/index.php';
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/1.2.x.x'; $expected = '/1.2.x.x';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/1.2.x.x/'; $expectedWebroot = '/1.2.x.x/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
$dispatcher->base = false; $Dispatcher->base = false;
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/app/webroot'; $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/app/webroot';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php'; $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
$_SERVER['PHP_SELF'] = '/index.php'; $_SERVER['PHP_SELF'] = '/index.php';
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = ''; $expected = '';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/'; $expectedWebroot = '/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
$Dispatcher->base = false;;
$_SERVER['DOCUMENT_ROOT'] = '/some/apps/where';
$_SERVER['SCRIPT_FILENAME'] = '/some/apps/where/app/webroot/index.php';
$_SERVER['PHP_SELF'] = '/some/apps/where/app/webroot/index.php';
$result = $Dispatcher->baseUrl();
$expected = '/some/apps/where';
$this->assertEqual($expected, $result);
$expectedWebroot = '/some/apps/where/';
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.dir', 'auth'); Configure::write('App.dir', 'auth');
$dispatcher->base = false;; $Dispatcher->base = false;;
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches'; $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/demos/auth/webroot/index.php'; $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/demos/auth/webroot/index.php';
$_SERVER['PHP_SELF'] = '/demos/auth/webroot/index.php'; $_SERVER['PHP_SELF'] = '/demos/auth/webroot/index.php';
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/demos/auth'; $expected = '/demos/auth';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/demos/auth/'; $expectedWebroot = '/demos/auth/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.dir', 'code'); Configure::write('App.dir', 'code');
$dispatcher->base = false;; $Dispatcher->base = false;;
$_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents'; $_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents';
$_SERVER['SCRIPT_FILENAME'] = '/Library/WebServer/Documents/clients/PewterReport/code/webroot/index.php'; $_SERVER['SCRIPT_FILENAME'] = '/Library/WebServer/Documents/clients/PewterReport/code/webroot/index.php';
$_SERVER['PHP_SELF'] = '/clients/PewterReport/code/webroot/index.php'; $_SERVER['PHP_SELF'] = '/clients/PewterReport/code/webroot/index.php';
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/clients/PewterReport/code'; $expected = '/clients/PewterReport/code';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/clients/PewterReport/code/'; $expectedWebroot = '/clients/PewterReport/code/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
} }
function testBaseUrlwithModRewriteAlias() { function testBaseUrlwithModRewriteAlias() {
@ -305,12 +313,12 @@ class DispatcherTest extends UnitTestCase {
Configure::write('App.base', '/control'); Configure::write('App.base', '/control');
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/control'; $expected = '/control';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/control/'; $expectedWebroot = '/control/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.base', false); Configure::write('App.base', false);
Configure::write('App.dir', 'affiliate'); Configure::write('App.dir', 'affiliate');
@ -319,111 +327,110 @@ class DispatcherTest extends UnitTestCase {
$_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html'; $_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php'; $_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php';
$_SERVER['PHP_SELF'] = '/newaffiliate/index.php'; $_SERVER['PHP_SELF'] = '/newaffiliate/index.php';
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/newaffiliate'; $expected = '/newaffiliate';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/newaffiliate/'; $expectedWebroot = '/newaffiliate/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
} }
function testBaseUrlAndWebrootWithBaseUrl() { function testBaseUrlAndWebrootWithBaseUrl() {
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
Configure::write('App.dir', 'app'); Configure::write('App.dir', 'app');
Configure::write('App.baseUrl', '/app/webroot/index.php'); Configure::write('App.baseUrl', '/app/webroot/index.php');
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/app/webroot/index.php'; $expected = '/app/webroot/index.php';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/app/webroot/'; $expectedWebroot = '/app/webroot/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.baseUrl', '/app/webroot/test.php'); Configure::write('App.baseUrl', '/app/webroot/test.php');
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/app/webroot/test.php'; $expected = '/app/webroot/test.php';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/app/webroot/'; $expectedWebroot = '/app/webroot/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.baseUrl', '/app/index.php'); Configure::write('App.baseUrl', '/app/index.php');
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/app/index.php'; $expected = '/app/index.php';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/app/webroot/'; $expectedWebroot = '/app/webroot/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.baseUrl', '/index.php'); Configure::write('App.baseUrl', '/index.php');
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/index.php'; $expected = '/index.php';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/app/webroot/'; $expectedWebroot = '/app/webroot/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php'); Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/CakeBB/app/webroot/index.php'; $expected = '/CakeBB/app/webroot/index.php';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/CakeBB/app/webroot/'; $expectedWebroot = '/CakeBB/app/webroot/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.baseUrl', '/CakeBB/app/index.php'); Configure::write('App.baseUrl', '/CakeBB/app/index.php');
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/CakeBB/app/index.php'; $expected = '/CakeBB/app/index.php';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/CakeBB/app/webroot/'; $expectedWebroot = '/CakeBB/app/webroot/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.baseUrl', '/CakeBB/index.php'); Configure::write('App.baseUrl', '/CakeBB/index.php');
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/CakeBB/index.php'; $expected = '/CakeBB/index.php';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/CakeBB/app/webroot/'; $expectedWebroot = '/CakeBB/app/webroot/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.baseUrl', '/dbhauser/index.php'); Configure::write('App.baseUrl', '/dbhauser/index.php');
$_SERVER['DOCUMENT_ROOT'] = '/kunden/homepages/4/d181710652/htdocs/joomla'; $_SERVER['DOCUMENT_ROOT'] = '/kunden/homepages/4/d181710652/htdocs/joomla';
$_SERVER['SCRIPT_FILENAME'] = '/kunden/homepages/4/d181710652/htdocs/joomla/dbhauser/index.php'; $_SERVER['SCRIPT_FILENAME'] = '/kunden/homepages/4/d181710652/htdocs/joomla/dbhauser/index.php';
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/dbhauser/index.php'; $expected = '/dbhauser/index.php';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/dbhauser/app/webroot/'; $expectedWebroot = '/dbhauser/app/webroot/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
} }
function testBaseUrlAndWebrootWithBase() { function testBaseUrlAndWebrootWithBase() {
$dispatcher =& new Dispatcher(); $Dispatcher =& new Dispatcher();
Configure::write('App.baseUrl',false); $Dispatcher->base = '/app';
$dispatcher->base = '/app'; $result = $Dispatcher->baseUrl();
$result = $dispatcher->baseUrl();
$expected = '/app'; $expected = '/app';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/app/'; $expectedWebroot = '/app/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
$dispatcher->base = ''; $Dispatcher->base = '';
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = ''; $expected = '';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/'; $expectedWebroot = '/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.dir', 'testbed'); Configure::write('App.dir', 'testbed');
$dispatcher->base = '/cake/testbed/webroot'; $Dispatcher->base = '/cake/testbed/webroot';
$result = $dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/cake/testbed/webroot'; $expected = '/cake/testbed/webroot';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/cake/testbed/webroot/'; $expectedWebroot = '/cake/testbed/webroot/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
} }
function testMissingController() { function testMissingController() {
$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(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'missingController'; $expected = 'missingController';
@ -431,12 +438,12 @@ class DispatcherTest extends UnitTestCase {
} }
function testPrivate() { function testPrivate() {
$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(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'privateAction'; $expected = 'privateAction';
@ -444,24 +451,24 @@ class DispatcherTest extends UnitTestCase {
} }
function testMissingAction() { function testMissingAction() {
$dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
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(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return'=> 1)); $controller = $Dispatcher->dispatch($url, array('return'=> 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'missingAction'; $expected = 'missingAction';
$this->assertEqual($expected, $controller); $this->assertEqual($expected, $controller);
} }
function testDispatch() { function testDispatch() {
$dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
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(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'Pages'; $expected = 'Pages';
@ -473,7 +480,7 @@ class DispatcherTest extends UnitTestCase {
function testAdminDispatch() { function testAdminDispatch() {
$_POST = array(); $_POST = array();
$dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
Configure::write('Routing.admin', 'admin'); Configure::write('Routing.admin', 'admin');
Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php'); Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php');
$url = 'admin/test_dispatch_pages/index/param:value/param2:value2'; $url = 'admin/test_dispatch_pages/index/param:value/param2:value2';
@ -482,7 +489,7 @@ class DispatcherTest extends UnitTestCase {
$Router =& Router::getInstance(); $Router =& Router::getInstance();
restore_error_handler(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'TestDispatchPages'; $expected = 'TestDispatchPages';
@ -505,18 +512,18 @@ class DispatcherTest extends UnitTestCase {
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
Router::reload(); Router::reload();
$dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
Router::connect('/my_plugin/:controller/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display')); Router::connect('/my_plugin/:controller/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display'));
$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(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$result = $dispatcher->parseParams($url); $result = $Dispatcher->parseParams($url);
$expected = array('pass' => array('home'), $expected = array('pass' => array('home'),
'named' => array('param'=> 'value', 'param2'=> 'value2'), 'named' => array('param'=> 'value', 'param2'=> 'value2'),
'plugin'=> 'my_plugin', 'controller'=> 'some_pages', 'action'=> 'display', 'plugin'=> 'my_plugin', 'controller'=> 'some_pages', 'action'=> 'display',
@ -549,13 +556,13 @@ class DispatcherTest extends UnitTestCase {
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
Router::reload(); Router::reload();
$dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
$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';
restore_error_handler(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return'=> 1)); $controller = $Dispatcher->dispatch($url, array('return'=> 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'my_plugin'; $expected = 'my_plugin';
@ -582,13 +589,13 @@ class DispatcherTest extends UnitTestCase {
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
Router::reload(); Router::reload();
$dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
$dispatcher->base = false; $Dispatcher->base = false;
$url = 'my_plugin/add/param:value/param2:value2'; $url = 'my_plugin/add/param:value/param2:value2';
restore_error_handler(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'my_plugin'; $expected = 'my_plugin';
@ -606,13 +613,13 @@ class DispatcherTest extends UnitTestCase {
Router::reload(); Router::reload();
Router::connect('/admin/:controller/:action/*', array('controller' => 'pages', 'action' => 'index', 'admin' => true, 'prefix' => 'admin')); Router::connect('/admin/:controller/:action/*', array('controller' => 'pages', 'action' => 'index', 'admin' => true, 'prefix' => 'admin'));
$dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
$dispatcher->base = false; $Dispatcher->base = false;
$url = 'admin/articles_test'; $url = 'admin/articles_test';
restore_error_handler(); restore_error_handler();
@$controller = $dispatcher->dispatch($url, array('return' => 1)); @$controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'articles_test'; $expected = 'articles_test';
@ -635,12 +642,12 @@ class DispatcherTest extends UnitTestCase {
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
Router::reload(); Router::reload();
$dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
$dispatcher->base = false; $Dispatcher->base = false;
$url = 'my_plugin/param:value/param2:value2'; $url = 'my_plugin/param:value/param2:value2';
restore_error_handler(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return'=> 1)); $controller = $Dispatcher->dispatch($url, array('return'=> 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'missingAction'; $expected = 'missingAction';
@ -654,12 +661,12 @@ class DispatcherTest extends UnitTestCase {
Router::reload(); Router::reload();
Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin'), array('controller', 'action')); Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin'), array('controller', 'action'));
$dispatcher =& new TestDispatcher(); $Dispatcher =& new TestDispatcher();
$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(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'privateAction'; $expected = 'privateAction';
@ -667,11 +674,11 @@ 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(); restore_error_handler();
$controller = $dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$expected = 'SomePosts'; $expected = 'SomePosts';