Skip to content
Permalink
Browse files

Fixing issue where webroot paths would be incorrect when using a virt…

…ual host setup and no mod_rewrite. An additional app/webroot would be appended. Incorrect tests updated. Fixes #259
  • Loading branch information...
markstory committed Jan 27, 2010
1 parent fc30405 commit 2d81d25f410ec9c2527fab92c769e72e04134a0e
Showing with 17 additions and 14 deletions.
  1. +10 −7 cake/dispatcher.php
  2. +7 −7 cake/tests/cases/dispatcher.test.php
@@ -367,21 +367,24 @@ function baseUrl() {
$this->webroot = $base .'/'; $this->webroot = $base .'/';
return $base; return $base;
} }
$file = '/' . basename($baseUrl);
$base = dirname($baseUrl);
if ($base === DS || $base === '.') { $file = '/' . basename($baseUrl);
$base = ''; $base = dirname($baseUrl);
}
$this->webroot = $base .'/';
if ($base === DS || $base === '.') {
$base = '';
}
$this->webroot = $base .'/';
if (!empty($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) { if (strpos($this->webroot, $webroot) === false) {
$this->webroot .= $webroot . '/'; $this->webroot .= $webroot . '/';
} }
return $base . $file; }
return $base . $file;
} }
/** /**
* Restructure params in case we're serving a plugin. * Restructure params in case we're serving a plugin.
@@ -1103,7 +1103,7 @@ function testBaseUrlAndWebrootWithBaseUrl() {
$result = $Dispatcher->baseUrl(); $result = $Dispatcher->baseUrl();
$expected = '/index.php'; $expected = '/index.php';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$expectedWebroot = '/app/webroot/'; $expectedWebroot = '/';
$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');
@@ -1174,12 +1174,12 @@ function testBaseUrlAndWebrootWithBase() {
*/ */
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';
$controller = $Dispatcher->dispatch($url, array('return' => 1)); $controller = $Dispatcher->dispatch($url, array('return' => 1));
$expected = array('missingController', array(array( $expected = array('missingController', array(array(
'className' => 'SomeControllerController', 'className' => 'SomeControllerController',
'webroot' => '/app/webroot/', 'webroot' => '/',
'url' => 'some_controller/home/param:value/param2:value2', 'url' => 'some_controller/home/param:value/param2:value2',
'base' => '/index.php' 'base' => '/index.php'
))); )));
@@ -1201,7 +1201,7 @@ function testPrivate() {
$expected = array('privateAction', array(array( $expected = array('privateAction', array(array(
'className' => 'SomePagesController', 'className' => 'SomePagesController',
'action' => '_protected', 'action' => '_protected',
'webroot' => '/app/webroot/', 'webroot' => '/',
'url' => 'some_pages/_protected/param:value/param2:value2', 'url' => 'some_pages/_protected/param:value/param2:value2',
'base' => '/index.php' 'base' => '/index.php'
))); )));
@@ -1215,15 +1215,15 @@ function testPrivate() {
*/ */
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';
$controller = $Dispatcher->dispatch($url, array('return'=> 1)); $controller = $Dispatcher->dispatch($url, array('return'=> 1));
$expected = array('missingAction', array(array( $expected = array('missingAction', array(array(
'className' => 'SomePagesController', 'className' => 'SomePagesController',
'action' => 'home', 'action' => 'home',
'webroot' => '/app/webroot/', 'webroot' => '/',
'url' => '/index.php/some_pages/home/param:value/param2:value2', 'url' => '/index.php/some_pages/home/param:value/param2:value2',
'base' => '/index.php' 'base' => '/index.php'
))); )));
@@ -1238,7 +1238,7 @@ function testMissingAction() {
$expected = array('missingAction', array(array( $expected = array('missingAction', array(array(
'className' => 'SomePagesController', 'className' => 'SomePagesController',
'action' => 'redirect', 'action' => 'redirect',
'webroot' => '/app/webroot/', 'webroot' => '/',
'url' => '/index.php/some_pages/redirect/param:value/param2:value2', 'url' => '/index.php/some_pages/redirect/param:value/param2:value2',
'base' => '/index.php' 'base' => '/index.php'
))); )));

0 comments on commit 2d81d25

Please sign in to comment.
You can’t perform that action at this time.