Permalink
Browse files

Fixing how webroot is calculated for installs not using url rewriting…

…. Also fixes using the top level index.php file.

Test cases added for using both index.php files.
Cleaned up existing tests for environment detection.
Fixes #1261, Fixes #1432
  • Loading branch information...
1 parent 3747e39 commit 703272965106532764817b661ef08791d29464ac @markstory markstory committed Jan 23, 2011
Showing with 95 additions and 7 deletions.
  1. +6 −2 cake/dispatcher.php
  2. +89 −5 cake/tests/cases/dispatcher.test.php
View
@@ -357,9 +357,13 @@ function baseUrl() {
if ($base === DS || $base === '.') {
$base = '';
}
- $this->webroot = $base .'/';
+ $this->webroot = $base . '/';
- if (!empty($base)) {
+ $docRoot = env('DOCUMENT_ROOT');
@0x20h

0x20h Feb 16, 2011

Contributor

I really would appreciate using realpath(env(...)) here as it makes the whole story work even when using symlinked docroots.

@markstory

markstory Feb 17, 2011

Owner

Seems reasonable. Done in a95d4ac

+ $script = realpath(env('SCRIPT_FILENAME'));
@0x20h

0x20h Feb 16, 2011

Contributor

thats a leftover, never used again anywhere...

@markstory

markstory Feb 17, 2011

Owner

So it is.

+ $docRootContainsWebroot = strpos($docRoot, $dir . '/' . $webroot);
+
+ if (!empty($base) || !$docRootContainsWebroot) {
if (strpos($this->webroot, $dir) === false) {
$this->webroot .= $dir . '/' ;
}
@@ -1208,6 +1208,42 @@ function testBaseUrlAndWebrootWithBaseUrl() {
}
/**
+ * test baseUrl with no rewrite and using the top level index.php.
+ *
+ * @return void
+ */
+ function testBaseUrlNoRewriteTopLevelIndex() {
+ $Dispatcher =& new Dispatcher();
+
+ Configure::write('App.baseUrl', '/index.php');
+ $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev';
+ $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/index.php';
+
+ $result = $Dispatcher->baseUrl();
+ $this->assertEqual('/index.php', $result);
+ $this->assertEqual('/app/webroot/', $Dispatcher->webroot);
+ $this->assertEqual('', $Dispatcher->base);
+ }
+
+/**
+ * test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts.
+ *
+ * @return void
+ */
+ function testBaseUrlNoRewriteWebrootIndex() {
+ $Dispatcher =& new Dispatcher();
+
+ Configure::write('App.baseUrl', '/index.php');
+ $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev/app/webroot';
+ $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/app/webroot/index.php';
+
+ $result = $Dispatcher->baseUrl();
+ $this->assertEqual('/index.php', $result);
+ $this->assertEqual('/', $Dispatcher->webroot);
+ $this->assertEqual('', $Dispatcher->base);
+ }
+
+/**
* testBaseUrlAndWebrootWithBase method
*
* @return void
@@ -2304,7 +2340,7 @@ function testEnvironmentDetection() {
'IIS' => array(
'No rewrite base path' => array(
'App' => array('base' => false, 'baseUrl' => '/index.php?', 'server' => 'IIS'),
- 'SERVER' => array('HTTPS' => 'off', 'SCRIPT_NAME' => '/index.php', 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot', 'QUERY_STRING' => '', 'REMOTE_ADDR' => '127.0.0.1', 'REMOTE_HOST' => '127.0.0.1', 'REQUEST_METHOD' => 'GET', 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => '80', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'SERVER_SOFTWARE' => 'Microsoft-IIS/5.1', 'APPL_PHYSICAL_PATH' => 'C:\\Inetpub\\wwwroot\\', 'REQUEST_URI' => '/index.php', 'URL' => '/index.php', 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php', 'ORIG_PATH_INFO' => '/index.php', 'PATH_INFO' => '', 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\index.php', 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot', 'PHP_SELF' => '/index.php', 'HTTP_ACCEPT' => '*/*', 'HTTP_ACCEPT_LANGUAGE' => 'en-us', 'HTTP_CONNECTION' => 'Keep-Alive', 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'argv' => array(), 'argc' => 0),
+ 'SERVER' => array('HTTPS' => 'off', 'SCRIPT_NAME' => '/index.php', 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot', 'QUERY_STRING' => '', 'REMOTE_ADDR' => '127.0.0.1', 'REMOTE_HOST' => '127.0.0.1', 'REQUEST_METHOD' => 'GET', 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => '80', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'APPL_PHYSICAL_PATH' => 'C:\\Inetpub\\wwwroot\\', 'REQUEST_URI' => '/index.php', 'URL' => '/index.php', 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php', 'ORIG_PATH_INFO' => '/index.php', 'PATH_INFO' => '', 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\index.php', 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot', 'PHP_SELF' => '/index.php', 'HTTP_HOST' => 'localhost', 'argv' => array(), 'argc' => 0),
'reload' => true,
'path' => ''
),
@@ -2343,18 +2379,54 @@ function testEnvironmentDetection() {
'Apache' => array(
'No rewrite base path' => array(
'App' => array('base' => false, 'baseUrl' => '/index.php', 'dir' => 'app', 'webroot' => 'webroot'),
- 'SERVER' => array('SERVER_NAME' => 'localhost', 'SERVER_ADDR' => '::1', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '::1', 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot', 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php', 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => '', 'REQUEST_URI' => '/', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php', 'argv' => array(), 'argc' => 0),
+ 'SERVER' => array(
+ 'SERVER_NAME' => 'localhost',
+ 'SERVER_ADDR' => '::1',
+ 'SERVER_PORT' => '80',
+ 'REMOTE_ADDR' => '::1',
+ 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot',
+ 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
+ 'QUERY_STRING' => '',
+ 'REQUEST_URI' => '/',
+ 'SCRIPT_NAME' => '/index.php',
+ 'PHP_SELF' => '/index.php',
+ 'argv' => array(),
+ 'argc' => 0
+ ),
'reload' => true,
'path' => ''
),
'No rewrite with path' => array(
- 'SERVER' => array('UNIQUE_ID' => 'VardGqn@17IAAAu7LY8AAAAK', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-us) AppleWebKit/523.10.5 (KHTML, like Gecko) Version/3.0.4 Safari/523.10.6', 'HTTP_ACCEPT' => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'HTTP_ACCEPT_LANGUAGE' => 'en-us', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'HTTP_CONNECTION' => 'keep-alive', 'HTTP_HOST' => 'localhost', 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot', 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/officespace/app/webroot/index.php', 'QUERY_STRING' => '', 'REQUEST_URI' => '/index.php/posts/add', 'SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/posts/add', 'PHP_SELF' => '/index.php/posts/add', 'argv' => array(), 'argc' => 0),
+ 'SERVER' => array(
+ 'HTTP_HOST' => 'localhost',
+ 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot',
+ 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/officespace/app/webroot/index.php',
+ 'QUERY_STRING' => '',
+ 'REQUEST_URI' => '/index.php/posts/add',
+ 'SCRIPT_NAME' => '/index.php',
+ 'PATH_INFO' => '/posts/add',
+ 'PHP_SELF' => '/index.php/posts/add',
+ 'argv' => array(),
+ 'argc' => 0),
'reload' => false,
'path' => '/posts/add'
),
'GET Request at base domain' => array(
'App' => array('base' => false, 'baseUrl' => null, 'dir' => 'app', 'webroot' => 'webroot'),
- 'SERVER' => array('UNIQUE_ID' => '2A-v8sCoAQ8AAAc-2xUAAAAB', 'HTTP_ACCEPT_LANGUAGE' => 'en-us', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'HTTP_COOKIE' => 'CAKEPHP=jcbv51apn84kd9ucv5aj2ln3t3', 'HTTP_CONNECTION' => 'keep-alive', 'HTTP_HOST' => 'cake.1.2', 'SERVER_NAME' => 'cake.1.2', 'SERVER_ADDR' => '127.0.0.1', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot', 'SERVER_ADMIN' => 'you@example.com', 'SCRIPT_FILENAME' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot/index.php', 'REMOTE_PORT' => '53550', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => 'a=b', 'REQUEST_URI' => '/?a=b', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php'),
+ 'SERVER' => array(
+ 'HTTP_HOST' => 'cake.1.2',
+ 'SERVER_NAME' => 'cake.1.2',
+ 'SERVER_ADDR' => '127.0.0.1',
+ 'SERVER_PORT' => '80',
+ 'REMOTE_ADDR' => '127.0.0.1',
+ 'DOCUMENT_ROOT' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot',
+ 'SCRIPT_FILENAME' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot/index.php',
+ 'REMOTE_PORT' => '53550',
+ 'QUERY_STRING' => 'a=b',
+ 'REQUEST_URI' => '/?a=b',
+ 'SCRIPT_NAME' => '/index.php',
+ 'PHP_SELF' => '/index.php'
+ ),
'GET' => array('a' => 'b'),
'POST' => array(),
'reload' => true,
@@ -2364,7 +2436,19 @@ function testEnvironmentDetection() {
),
'New CGI no mod_rewrite' => array(
'App' => array('base' => false, 'baseUrl' => '/limesurvey20/index.php', 'dir' => 'app', 'webroot' => 'webroot'),
- 'SERVER' => array('DOCUMENT_ROOT' => '/home/.sites/110/site313/web', 'PATH_INFO' => '/installations', 'PATH_TRANSLATED' => '/home/.sites/110/site313/web/limesurvey20/index.php', 'PHPRC' => '/home/.sites/110/site313', 'QUERY_STRING' => '', 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/limesurvey20/index.php/installations', 'SCRIPT_FILENAME' => '/home/.sites/110/site313/web/limesurvey20/index.php', 'SCRIPT_NAME' => '/limesurvey20/index.php', 'SCRIPT_URI' => 'http://www.gisdat-umfragen.at/limesurvey20/index.php/installations', 'PHP_SELF' => '/limesurvey20/index.php/installations', 'CGI_MODE' => true),
+ 'SERVER' => array(
+ 'DOCUMENT_ROOT' => '/home/.sites/110/site313/web',
+ 'PATH_INFO' => '/installations',
+ 'PATH_TRANSLATED' => '/home/.sites/110/site313/web/limesurvey20/index.php',
+ 'PHPRC' => '/home/.sites/110/site313',
+ 'QUERY_STRING' => '',
+ 'REQUEST_URI' => '/limesurvey20/index.php/installations',
+ 'SCRIPT_FILENAME' => '/home/.sites/110/site313/web/limesurvey20/index.php',
+ 'SCRIPT_NAME' => '/limesurvey20/index.php',
+ 'SCRIPT_URI' => 'http://www.gisdat-umfragen.at/limesurvey20/index.php/installations',
+ 'PHP_SELF' => '/limesurvey20/index.php/installations',
+ 'CGI_MODE' => true
+ ),
'GET' => array(),
'POST' => array(),
'reload' => true,

0 comments on commit 7032729

Please sign in to comment.