updating Dispatcher::baseUrl() and added tests, fixes #3527

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5952 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-11-05 14:56:21 +00:00
parent 0b217acd18
commit 23467f8800
2 changed files with 42 additions and 15 deletions

View file

@ -411,19 +411,17 @@ class Dispatcher extends Object {
if (!$baseUrl) {
$base = dirname(env('PHP_SELF'));
if (in_array($base, array(DS, '.'))) {
$base = '';
}
if ($base == '') {
$this->webroot = '/';
return $base;
}
if ($webroot === 'webroot' && $webroot === basename($base)) {
$base = dirname($base);
}
if ($dir === 'app' && $dir === basename($base)) {
$base = dirname($base);
}
if (in_array($base, array(DS, '.'))) {
$base = '';
}
$this->webroot = $base .'/';
return $base;
}
@ -646,9 +644,11 @@ class Dispatcher extends Object {
$filename = CACHE . 'views' . DS . convertSlash($url) . '_index.php';
}
if (file_exists($filename)) {
uses('controller' . DS . 'component', DS . 'view' . DS . 'view');
$v = null;
$view = new View($v);
if (!class_exists('View')) {
uses('controller' . DS . 'component', DS . 'view' . DS . 'view');
}
$controller = null;
$view = new View($controller);
$view->renderCache($filename, getMicrotime());
}
}

View file

@ -142,6 +142,24 @@ class SomePostsController extends AppController {
return true;
}
}
class TestCachedPagesController extends AppController {
var $name = 'TestCachedPages';
var $uses = array();
var $helpers = array('Cache');
var $cacheAction = array('index'=> '+2 sec', 'nocache'=>'+2 sec');
function index() {
$this->render(null, null, LIBS . 'view' . DS . 'templates' . DS . 'pages' . DS . 'home.ctp');
}
function nocache() {
//$this->cacheAction = '+2 sec';
$this->render(null, null, CAKE . 'tests' . DS . 'cases' . DS . 'libs' . DS . 'view' . DS . 'templates' . DS . 'nocache.ctp');
}
}
/**
* Short description for class.
*
@ -248,7 +266,7 @@ class DispatcherTest extends UnitTestCase {
function testBaseUrlAndWebrootWithModRewrite() {
$Dispatcher =& new Dispatcher();
$Dispatcher->base = false;
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
@ -258,7 +276,7 @@ class DispatcherTest extends UnitTestCase {
$this->assertEqual($expected, $result);
$expectedWebroot = '/1.2.x.x/';
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
$Dispatcher->base = false;
$_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';
@ -268,7 +286,17 @@ class DispatcherTest extends UnitTestCase {
$this->assertEqual($expected, $result);
$expectedWebroot = '/';
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
$Dispatcher->base = false;
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/test/';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/test/webroot/index.php';
$_SERVER['PHP_SELF'] = '/webroot/index.php';
$result = $Dispatcher->baseUrl();
$expected = '';
$this->assertEqual($expected, $result);
$expectedWebroot = '/';
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
$Dispatcher->base = false;;
$_SERVER['DOCUMENT_ROOT'] = '/some/apps/where';
$_SERVER['SCRIPT_FILENAME'] = '/some/apps/where/app/webroot/index.php';
@ -278,7 +306,7 @@ class DispatcherTest extends UnitTestCase {
$this->assertEqual($expected, $result);
$expectedWebroot = '/some/apps/where/';
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
Configure::write('App.dir', 'auth');
@ -692,7 +720,6 @@ class DispatcherTest extends UnitTestCase {
$this->assertIdentical($expected, $controller->params['pass']);
}
function tearDown() {
$_GET = $this->_get;
}