Merge branch 'clean-get' into 2.0

This commit is contained in:
mark_story 2011-02-21 12:47:41 -05:00
commit 6338299e77
16 changed files with 242 additions and 387 deletions

View file

@ -2,5 +2,5 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

View file

@ -70,10 +70,11 @@
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/favicon.ico') {
return;
} else {
require LIBS . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest(isset($_GET['url']) ? $_GET['url'] : null));
}
require LIBS . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest());

View file

@ -2,5 +2,5 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

View file

@ -70,10 +70,11 @@
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/favicon.ico') {
return;
} else {
require LIBS . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest(isset($_GET['url']) ? $_GET['url'] : null));
}
require LIBS . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest());

View file

@ -112,7 +112,7 @@ class CakeRequest implements ArrayAccess {
* @return void
*/
public function __construct($url = null, $parseEnvironment = true) {
$this->base = $this->_base();
$this->_base();
if (empty($url)) {
$url = $this->_url();
}
@ -167,98 +167,50 @@ class CakeRequest implements ArrayAccess {
} else {
$query = $_GET;
}
if (strpos($this->url, '?') !== false) {
list(, $querystr) = explode('?', $this->url);
parse_str($querystr, $queryArgs);
$query += $queryArgs;
$query += $queryArgs;
}
if (isset($this->params['url'])) {
$query = array_merge($this->params['url'], $query);
}
$query['url'] = $this->url;
$this->query = $query;
}
/**
* Returns the REQUEST_URI from the server environment, or, failing that,
* constructs a new one, using the PHP_SELF constant and other variables.
* Get the request uri. Looks in PATH_INFO first, as this is the exact value we need prepared
* by PHP. Following that, REQUEST_URI, PHP_SELF, HTTP_X_REWRITE_URL and argv are checked in that order.
* Each of these server variables have the base path, and query strings stripped off
*
* @return string URI
* @return string URI The CakePHP request path that is being accessed.
*/
protected function _uri() {
foreach (array('HTTP_X_REWRITE_URL', 'REQUEST_URI', 'argv') as $var) {
protected function _url() {
$pathInfo = env('PATH_INFO');
if (!empty($pathInfo)) {
return $pathInfo;
}
foreach (array('PHP_SELF', 'REQUEST_URI', 'HTTP_X_REWRITE_URL', 'argv') as $var) {
if ($uri = env($var)) {
if ($var == 'argv') {
$uri = $uri[0];
$uri = $url[0];
}
break;
}
}
$base = $this->base;
$base = trim(Configure::read('App.baseUrl'), '/');
if ($base) {
$uri = preg_replace('/^(?:\/)?(?:' . preg_quote($base, '/') . ')?(?:url=)?/', '', $uri);
if (strpos($uri, $base) === 0) {
$uri = substr($uri, strlen($base));
}
if (PHP_SAPI == 'isapi') {
$uri = preg_replace('/^(?:\/)?(?:\/)?(?:\?)?(?:url=)?/', '', $uri);
}
if (!empty($uri)) {
if (key($_GET) && strpos(key($_GET), '?') !== false) {
unset($_GET[key($_GET)]);
}
$uri = explode('?', $uri, 2);
if (isset($uri[1])) {
parse_str($uri[1], $_GET);
}
$uri = $uri[0];
} else {
$uri = env('QUERY_STRING');
}
if (is_string($uri) && strpos($uri, 'index.php') !== false) {
list(, $uri) = explode('index.php', $uri, 2);
if (strpos($uri, '?') !== false) {
$uri = parse_url($uri, PHP_URL_PATH);
}
if (empty($uri) || $uri == '/' || $uri == '//') {
return '';
return '/';
}
return str_replace('//', '/', '/' . $uri);
}
/**
* Returns and sets the $_GET[url] derived from the REQUEST_URI
*
* @return string URL
*/
protected function _url() {
if (empty($_GET['url'])) {
$uri = $this->_uri();
$base = $this->base;
$url = null;
$tmpUri = preg_replace('/^(?:\?)?(?:\/)?/', '', $uri);
$baseDir = trim(dirname($base) . '/', '/');
if ($tmpUri === '/' || $tmpUri == $baseDir || $tmpUri == $base) {
$url = '/';
} else {
$elements = array();
if ($base && strpos($uri, $base) !== false) {
$elements = explode($base, $uri);
} elseif (preg_match('/^[\/\?\/|\/\?|\?\/]/', $uri)) {
$elements = array(1 => preg_replace('/^[\/\?\/|\/\?|\?\/]/', '', $uri));
}
if (!empty($elements[1])) {
$url = $elements[1];
} else {
$url = '/';
}
}
} else {
$url = $_GET['url'];
}
return $url;
return $uri;
}
/**
@ -279,8 +231,7 @@ class CakeRequest implements ArrayAccess {
return $this->base = $base;
}
if (!$baseUrl) {
$replace = array('<', '>', '*', '\'', '"');
$base = str_replace($replace, '', dirname(env('PHP_SELF')));
$base = dirname(env('SCRIPT_NAME'));
if ($webroot === 'webroot' && $webroot === basename($base)) {
$base = dirname($base);
@ -294,7 +245,7 @@ class CakeRequest implements ArrayAccess {
}
$this->webroot = $base .'/';
return $base;
return $this->base = $base;
}
$file = '/' . basename($baseUrl);
@ -306,7 +257,6 @@ class CakeRequest implements ArrayAccess {
$this->webroot = $base . '/';
$docRoot = env('DOCUMENT_ROOT');
$script = realpath(env('SCRIPT_FILENAME'));
$docRootContainsWebroot = strpos($docRoot, $dir . '/' . $webroot);
if (!empty($base) || !$docRootContainsWebroot) {
@ -317,7 +267,7 @@ class CakeRequest implements ArrayAccess {
$this->webroot .= $webroot . '/';
}
}
return $base . $file;
return $this->base = $base . $file;
}
/**

View file

@ -289,8 +289,8 @@ class AuthComponent extends Component {
$url = '';
if (isset($request->query['url'])) {
$url = $request->query['url'];
if (isset($request->url)) {
$url = $request->url;
}
$url = Router::normalize($url);
$loginAction = Router::normalize($this->loginAction);

View file

@ -66,20 +66,19 @@ class ApiShellTest extends CakeTestCase {
'8. getResponse()',
'9. header($status)',
'10. httpCodes($code = NULL)',
'11. isAuthorized()',
'12. loadModel($modelClass = NULL, $id = NULL)',
'13. paginate($object = NULL, $scope = array (), $whitelist = array ())',
'14. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)',
'15. redirect($url, $status = NULL, $exit = true)',
'16. referer($default = NULL, $local = false)',
'17. render($action = NULL, $layout = NULL, $file = NULL)',
'18. set($one, $two = NULL)',
'19. setAction($action)',
'20. setRequest($request)',
'21. shutdownProcess()',
'22. startupProcess()',
'23. validate()',
'24. validateErrors()'
'11. loadModel($modelClass = NULL, $id = NULL)',
'12. paginate($object = NULL, $scope = array (), $whitelist = array ())',
'13. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)',
'14. redirect($url, $status = NULL, $exit = true)',
'15. referer($default = NULL, $local = false)',
'16. render($view = NULL, $layout = NULL)',
'17. set($one, $two = NULL)',
'18. setAction($action)',
'19. setRequest($request)',
'20. shutdownProcess()',
'21. startupProcess()',
'22. validate()',
'23. validateErrors()'
);
$this->Shell->expects($this->at(2))->method('out')->with($expected);

View file

@ -31,6 +31,9 @@ class CakeRequestTestCase extends CakeTestCase {
$this->_get = $_GET;
$this->_post = $_POST;
$this->_files = $_FILES;
$this->_app = Configure::read('App');
Configure::write('App.baseUrl', false);
}
/**
@ -44,6 +47,7 @@ class CakeRequestTestCase extends CakeTestCase {
$_GET = $this->_get;
$_POST = $this->_post;
$_FILES = $this->_files;
Configure::write('App', $this->_app);
}
/**
@ -70,12 +74,11 @@ class CakeRequestTestCase extends CakeTestCase {
'two' => 'banana'
);
$request = new CakeRequest('some/path');
$this->assertEqual($request->query, $_GET + array('url' => 'some/path'));
$this->assertEqual($request->query, $_GET);
$_GET = array(
'one' => 'param',
'two' => 'banana',
'url' => 'some/path'
);
$request = new CakeRequest('some/path');
$this->assertEqual($request->query, $_GET);
@ -90,8 +93,10 @@ class CakeRequestTestCase extends CakeTestCase {
function testQueryStringParsingFromInputUrl() {
$_GET = array();
$request = new CakeRequest('some/path?one=something&two=else');
$expected = array('one' => 'something', 'two' => 'else', 'url' => 'some/path?one=something&two=else');
$expected = array('one' => 'something', 'two' => 'else');
$this->assertEqual($request->query, $expected);
$this->assertEquals('some/path?one=something&two=else', $request->url);
}
/**
@ -790,9 +795,8 @@ class CakeRequestTestCase extends CakeTestCase {
Configure::write('App.baseUrl', false);
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
$_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';
$_GET['url'] = 'posts/view/1';
$_SERVER['SCRIPT_NAME'] = '/1.2.x.x/app/webroot/index.php';
$_SERVER['PATH_INFO'] = '/posts/view/1';
$request = new CakeRequest();
$this->assertEqual($request->base, '/1.2.x.x');
@ -801,9 +805,8 @@ class CakeRequestTestCase extends CakeTestCase {
$_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['PHP_SELF'] = '/index.php';
$_GET['url'] = 'posts/add';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['PATH_INFO'] = '/posts/add';
$request = new CakeRequest();
$this->assertEqual($request->base, '');
@ -811,8 +814,7 @@ class CakeRequestTestCase extends CakeTestCase {
$this->assertEqual($request->url, 'posts/add');
$_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';
$_SERVER['SCRIPT_NAME'] = '/webroot/index.php';
$request = new CakeRequest();
$this->assertEqual('', $request->base);
@ -820,18 +822,16 @@ class CakeRequestTestCase extends CakeTestCase {
$_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';
$_SERVER['SCRIPT_NAME'] = '/app/webroot/index.php';
$request = new CakeRequest();
$this->assertEqual($request->base, '/some/apps/where');
$this->assertEqual($request->webroot, '/some/apps/where/');
$this->assertEqual($request->base, '');
$this->assertEqual($request->webroot, '/');
Configure::write('App.dir', 'auth');
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/demos/auth/webroot/index.php';
$_SERVER['PHP_SELF'] = '/demos/auth/webroot/index.php';
$_SERVER['SCRIPT_NAME'] = '/demos/auth/webroot/index.php';
$request = new CakeRequest();
@ -841,8 +841,7 @@ class CakeRequestTestCase extends CakeTestCase {
Configure::write('App.dir', 'code');
$_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents';
$_SERVER['SCRIPT_FILENAME'] = '/Library/WebServer/Documents/clients/PewterReport/code/webroot/index.php';
$_SERVER['PHP_SELF'] = '/clients/PewterReport/code/webroot/index.php';
$_SERVER['SCRIPT_NAME'] = '/clients/PewterReport/code/webroot/index.php';
$request = new CakeRequest();
$this->assertEqual($request->base, '/clients/PewterReport/code');
@ -856,8 +855,7 @@ class CakeRequestTestCase extends CakeTestCase {
*/
public function testBaseUrlwithModRewriteAlias() {
$_SERVER['DOCUMENT_ROOT'] = '/home/aplusnur/public_html';
$_SERVER['SCRIPT_FILENAME'] = '/home/aplusnur/cake2/app/webroot/index.php';
$_SERVER['PHP_SELF'] = '/control/index.php';
$_SERVER['SCRIPT_NAME'] = '/control/index.php';
Configure::write('App.base', '/control');
@ -871,8 +869,7 @@ class CakeRequestTestCase extends CakeTestCase {
Configure::write('App.webroot', 'newaffiliate');
$_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php';
$_SERVER['PHP_SELF'] = '/newaffiliate/index.php';
$_SERVER['SCRIPT_NAME'] = '/newaffiliate/index.php';
$request = new CakeRequest();
$this->assertEqual($request->base, '/newaffiliate');
@ -983,34 +980,25 @@ class CakeRequestTestCase extends CakeTestCase {
}
/**
* testEnvironmentDetection method
* generator for environment configurations
*
* @return void
*/
public function testEnvironmentDetection() {
$environments = array(
'IIS' => array(
'No rewrite base path' => array(
public static function environmentGenerator() {
return array(
array(
'IIS - No rewrite base path',
array(
'App' => array(
'base' => false,
'baseUrl' => '/index.php?',
'server' => 'IIS',
'baseUrl' => '/index.php',
'dir' => 'app',
'webroot' => 'webroot'
),
'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',
@ -1019,73 +1007,47 @@ class CakeRequestTestCase extends CakeTestCase {
'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,
'base' => '/index.php?',
),
array(
'base' => '/index.php',
'webroot' => '/app/webroot/',
'url' => ''
),
'No rewrite with path' => array(
),
array(
'IIS - No rewrite with path, no PHP_SELF',
array(
'App' => array(
'base' => false,
'baseUrl' => '/index.php?',
'dir' => 'app',
'webroot' => 'webroot'
),
'SERVER' => array(
'QUERY_STRING' => '/posts/add',
'REQUEST_URI' => '/index.php?/posts/add',
'PHP_SELF' => '',
'URL' => '/index.php?/posts/add',
'argv' => array('/posts/add'),
'argc' => 1
),
'reload' => false,
),
array(
'url' => 'posts/add',
'base' => '/index.php?',
'webroot' => '/app/webroot/'
),
'No rewrite sub dir 1' => array(
'GET' => array(),
'SERVER' => array(
'QUERY_STRING' => '',
'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',
'argv' => array(),
'argc' => 0
),
'reload' => false,
'url' => '',
'base' => '/index.php?',
'webroot' => '/app/webroot/'
),
'No rewrite sub dir 1 with path' => array(
'GET' => array('/posts/add' => ''),
'SERVER' => array(
'QUERY_STRING' => '/posts/add',
'REQUEST_URI' => '/index.php?/posts/add',
'URL' => '/index.php?/posts/add',
'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php',
'argv' => array('/posts/add'),
'argc' => 1
),
'reload' => false,
'url' => 'posts/add',
'base' => '/index.php?',
'webroot' => '/app/webroot/'
),
'No rewrite sub dir 2' => array(
)
),
array(
'IIS - No rewrite sub dir 2',
array(
'App' => array(
'base' => false,
'baseUrl' => '/site/index.php?',
'baseUrl' => '/site/index.php',
'dir' => 'app',
'webroot' => 'webroot',
'server' => 'IIS'
),
'GET' => array(),
'POST' => array(),
'SERVER' => array(
'SCRIPT_NAME' => '/site/index.php',
'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot',
@ -1098,33 +1060,45 @@ class CakeRequestTestCase extends CakeTestCase {
'argv' => array(),
'argc' => 0
),
'reload' => false,
),
array(
'url' => '',
'base' => '/site/index.php?',
'base' => '/site/index.php',
'webroot' => '/site/app/webroot/'
),
'No rewrite sub dir 2 with path' => array(
),
array(
'IIS - No rewrite sub dir 2 with path',
array(
'App' => array(
'base' => false,
'baseUrl' => '/site/index.php',
'dir' => 'app',
'webroot' => 'webroot'
),
'GET' => array('/posts/add' => ''),
'SERVER' => array(
'SCRIPT_NAME' => '/site/index.php',
'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot',
'QUERY_STRING' => '/posts/add',
'REQUEST_URI' => '/site/index.php?/posts/add',
'URL' => '/site/index.php?/posts/add',
'REQUEST_URI' => '/site/index.php/posts/add',
'URL' => '/site/index.php/posts/add',
'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\site\\index.php',
'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot',
'PHP_SELF' => '/site/index.php',
'PHP_SELF' => '/site/index.php/posts/add',
'argv' => array('/posts/add'),
'argc' => 1
),
'reload' => false,
),
array(
'url' => 'posts/add',
'base' => '/site/index.php?',
'base' => '/site/index.php',
'webroot' => '/site/app/webroot/'
)
),
'Apache' => array(
'No rewrite base path' => array(
array(
'Apache - No rewrite, document root set to webroot, requesting path',
array(
'App' => array(
'base' => false,
'baseUrl' => '/index.php',
@ -1132,153 +1106,143 @@ class CakeRequestTestCase extends CakeTestCase {
'webroot' => 'webroot'
),
'SERVER' => array(
'SERVER_NAME' => 'localhost',
'SERVER_ADDR' => '::1',
'SERVER_PORT' => '80',
'REMOTE_ADDR' => '::1',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents/site/app/webroot',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
'REQUEST_METHOD' => 'GET',
'QUERY_STRING' => '',
'REQUEST_URI' => '/',
'REQUEST_URI' => '/index.php/posts/index',
'SCRIPT_NAME' => '/index.php',
'PATH_INFO' => '/posts/index',
'PHP_SELF' => '/index.php/posts/index',
),
),
array(
'url' => 'posts/index',
'base' => '/index.php',
'webroot' => '/'
),
),
array(
'Apache - No rewrite, document root set to webroot, requesting root',
array(
'App' => array(
'base' => false,
'baseUrl' => '/index.php',
'dir' => 'app',
'webroot' => 'webroot'
),
'SERVER' => array(
'DOCUMENT_ROOT' => '/Library/WebServer/Documents/site/app/webroot',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
'QUERY_STRING' => '',
'REQUEST_URI' => '/index.php',
'SCRIPT_NAME' => '/index.php',
'PATH_INFO' => '',
'PHP_SELF' => '/index.php',
'argv' => array(),
'argc' => 0
),
'reload' => true,
),
array(
'url' => '',
'base' => '/index.php',
'webroot' => '/'
),
'No rewrite with path' => array(
'SERVER' => array(
'HTTP_HOST' => 'localhost',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents/site/app/webroot',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/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,
'url' => 'posts/add',
'base' => '/index.php',
'webroot' => '/'
),
'GET Request at base domain' => array(
),
array(
'Apache - No rewrite, document root set above top level cake dir, requesting path',
array(
'App' => array(
'base' => false,
'baseUrl' => null,
'baseUrl' => '/site/index.php',
'dir' => 'app',
'webroot' => 'webroot'
),
'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',
'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_NAME' => 'localhost',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
'REQUEST_URI' => '/site/index.php/posts/index',
'SCRIPT_NAME' => '/site/index.php',
'PATH_INFO' => '/posts/index',
'PHP_SELF' => '/site/index.php/posts/index',
),
'GET' => array('a' => 'b'),
'POST' => array(),
'reload' => true,
),
array(
'url' => 'posts/index',
'base' => '/site/index.php',
'webroot' => '/site/app/webroot/',
),
),
array(
'Apache - No rewrite, document root set above top level cake dir, requesting root',
array(
'App' => array(
'base' => false,
'baseUrl' => '/site/index.php',
'dir' => 'app',
'webroot' => 'webroot'
),
'SERVER' => array(
'SERVER_NAME' => 'localhost',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
'REQUEST_URI' => '/site/index.php/',
'SCRIPT_NAME' => '/site/index.php',
'PATH_INFO' => '',
'PHP_SELF' => '/site/index.php/',
),
),
array(
'url' => '',
'base' => '',
'webroot' => '/',
'urlParams' => array('a' => 'b'),
'environment' => array('CGI_MODE' => false)
'base' => '/site/index.php',
'webroot' => '/site/app/webroot/',
),
'New CGI no mod_rewrite' => array(
),
array(
'Apache - No rewrite, document root set above top level cake dir, request path, with GET',
array(
'App' => array(
'base' => false,
'baseUrl' => '/limesurvey20/index.php',
'baseUrl' => '/site/index.php',
'dir' => 'app',
'webroot' => 'webroot'
),
'GET' => array('a' => 'b', 'c' => 'd'),
'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_NAME' => 'localhost',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
'REQUEST_URI' => '/site/index.php/posts/index?a=b&c=d',
'SCRIPT_NAME' => '/site/index.php',
'PATH_INFO' => '/posts/index',
'PHP_SELF' => '/site/index.php/posts/index',
'QUERY_STRING' => 'a=b&c=d'
),
'GET' => array(),
'POST' => array(),
'reload' => true,
'webroot' => '/limesurvey20/app/webroot/',
'base' => '/limesurvey20/index.php',
'url' => 'installations',
'urlParams' => array(),
'environment' => array('CGI_MODE' => true)
)
),
array(
'urlParams' => array('a' => 'b', 'c' => 'd'),
'url' => 'posts/index',
'base' => '/site/index.php',
'webroot' => '/site/app/webroot/',
),
)
);
$backup = $this->__backupEnvironment();
foreach ($environments as $name => $env) {
foreach ($env as $descrip => $settings) {
if ($settings['reload']) {
$this->__reloadEnvironment();
}
$this->__loadEnvironment($settings);
$request = new CakeRequest();
$this->assertEqual($request->url, $settings['url'], "%s url on env: {$name} on setting {$descrip}");
$this->assertEqual($request->base, $settings['base'], "%s base on env: {$name} on setting {$descrip}");
$this->assertEqual($request->webroot, $settings['webroot'], "%s webroot on env: {$name} on setting {$descrip}");
if (isset($settings['urlParams'])) {
$this->assertEqual($_GET, $settings['urlParams'], "%s on environment: {$name}, on setting: {$descrip}");
}
if (isset($settings['environment'])) {
foreach ($settings['environment'] as $key => $val) {
$this->assertEqual(env($key), $val, "%s on key {$key} on environment: {$name}, on setting: {$descrip}");
}
}
}
}
$this->__loadEnvironment(array_merge(array('reload' => true), $backup));
}
/**
* test that XSS can't be performed against the base path.
* testEnvironmentDetection method
*
* @dataProvider environmentGenerator
* @return void
*/
function testBasePathInjection() {
$self = $_SERVER['PHP_SELF'];
$_SERVER['PHP_SELF'] = urldecode(
"/index.php/%22%3E%3Ch1%20onclick=%22alert('xss');%22%3Eheya%3C/h1%3E"
);
public function testEnvironmentDetection($name, $env, $expected) {
$this->__loadEnvironment($env);
$request = new CakeRequest();
$expected = '/index.php/h1 onclick=alert(xss);heya';
$this->assertEqual($request->base, $expected);
$this->assertEquals($expected['url'], $request->url, "url error");
$this->assertEquals($expected['base'], $request->base, "base error");
$this->assertEquals($expected['webroot'],$request->webroot, "webroot error");
if (isset($expected['urlParams'])) {
$this->assertEqual($_GET, $expected['urlParams'], "GET param mismatch");
}
}
/**
@ -1364,40 +1328,6 @@ class CakeRequestTestCase extends CakeTestCase {
$this->assertFalse($result);
}
/**
* backupEnvironment method
*
* @return void
* @access private
*/
function __backupEnvironment() {
return array(
'App' => Configure::read('App'),
'GET' => $_GET,
'POST' => $_POST,
'SERVER' => $_SERVER
);
}
/**
* reloadEnvironment method
*
* @return void
* @access private
*/
function __reloadEnvironment() {
foreach ($_GET as $key => $val) {
unset($_GET[$key]);
}
foreach ($_POST as $key => $val) {
unset($_POST[$key]);
}
foreach ($_SERVER as $key => $val) {
unset($_SERVER[$key]);
}
Configure::write('App', array());
}
/**
* loadEnvironment method
*
@ -1406,10 +1336,6 @@ class CakeRequestTestCase extends CakeTestCase {
* @access private
*/
function __loadEnvironment($env) {
if ($env['reload']) {
$this->__reloadEnvironment();
}
if (isset($env['App'])) {
Configure::write('App', $env['App']);
}

View file

@ -108,7 +108,7 @@ class CakeSocketTest extends CakeTestCase {
*/
public static function invalidConnections() {
return array(
array(array('host' => 'invalid.host', 'timeout' => 1)),
array(array('host' => 'invalid.host', 'port' => 9999, 'timeout' => 1)),
array(array('host' => '127.0.0.1', 'port' => '70000', 'timeout' => 1))
);
}

View file

@ -443,7 +443,7 @@ class AuthTest extends CakeTestCase {
$this->Controller->data = array();
$this->Controller->request->addParams(Router::parse('auth_test/login'));
$this->Controller->request->query['url'] = 'auth_test/login';
$this->Controller->request->url = 'auth_test/login';
$this->Auth->Session->delete('Auth');
$this->Auth->loginRedirect = '/users/dashboard';
@ -730,7 +730,7 @@ class AuthTest extends CakeTestCase {
));
$this->Auth->request->addParams(Router::parse('users/login'));
$this->Auth->request->query['url'] = 'users/login';
$this->Auth->request->url = 'users/login';
$this->Auth->initialize($this->Controller);
$this->Auth->loginRedirect = array(
@ -771,7 +771,7 @@ class AuthTest extends CakeTestCase {
'AuthUser' => array('id'=>'1', 'username' => 'nate')
));
$this->Auth->request->params['action'] = 'login';
$this->Auth->request->query['url'] = 'auth_test/login';
$this->Auth->request->url = 'auth_test/login';
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = 'auth_test/login';
$this->Auth->loginRedirect = false;
@ -784,7 +784,7 @@ class AuthTest extends CakeTestCase {
$this->Auth->Session->delete('Auth');
$url = '/posts/index/year:2008/month:feb';
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->query['url'] = Router::normalize($url);
$this->Auth->request->url = Router::normalize($url);
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->startup($this->Controller);
@ -795,7 +795,7 @@ class AuthTest extends CakeTestCase {
$this->Auth->Session->delete('Auth');
$url = '/posts/view/1';
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->query['url'] = Router::normalize($url);
$this->Auth->request->url = Router::normalize($url);
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->startup($this->Controller);
@ -843,7 +843,7 @@ class AuthTest extends CakeTestCase {
$url = '/posts/edit/1';
$this->Auth->request = $this->Controller->request = new CakeRequest($url);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->query = array('url' => Router::normalize($url));
$this->Auth->request->url = Router::normalize($url);
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->startup($this->Controller);
@ -856,7 +856,7 @@ class AuthTest extends CakeTestCase {
$url = '/AuthTest/login';
$this->Auth->request = $this->Controller->request = new CakeRequest($url);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->query['url'] = Router::normalize($url);
$this->Auth->request->url = Router::normalize($url);
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->startup($this->Controller);
@ -965,11 +965,11 @@ class AuthTest extends CakeTestCase {
$url = '/admin/auth_test/login';
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->query['url'] = ltrim($url, '/');
$this->Auth->request->url = ltrim($url, '/');
Router::setRequestInfo(array(
array(
'pass' => array(), 'action' => 'admin_login', 'plugin' => null, 'controller' => 'auth_test',
'admin' => true, 'url' => array('url' => $this->Auth->request->query['url']),
'admin' => true,
),
array(
'base' => null, 'here' => $url,

View file

@ -27,6 +27,8 @@ class CrudAuthorizeTest extends CakeTestCase {
* @return void
*/
function setUp() {
Configure::write('Routing.prefixes', array());
parent::setUp();
$this->Acl = $this->getMock('AclComponent', array(), array(), '', false);

View file

@ -1020,20 +1020,6 @@ class ControllerTest extends CakeTestCase {
$this->assertidentical($TestController->data, $expected);
}
/**
* testUnimplementedIsAuthorized method
*
* @expectedException PHPUnit_Framework_Error
* @access public
* @return void
*/
function testUnimplementedIsAuthorized() {
$request = new CakeRequest('controller_posts/index');
$TestController = new TestController($request);
$TestController->isAuthorized();
}
/**
* testValidateErrors method
*

View file

@ -771,11 +771,11 @@ class ScaffoldTest extends CakeTestCase {
function testScaffoldChangingViewProperty() {
$this->Controller->action = 'edit';
$this->Controller->theme = 'test_theme';
$this->Controller->view = 'Theme';
$this->Controller->viewClass = 'Theme';
$this->Controller->constructClasses();
$Scaffold = new TestScaffoldMock($this->Controller, $this->Controller->request);
$this->assertEqual($this->Controller->view, 'Scaffold');
$this->assertEqual($this->Controller->viewClass, 'Scaffold');
}
/**

View file

@ -388,7 +388,6 @@ class ControllerTestCaseTest extends CakeTestCase {
'return' => 'vars',
'method' => 'get',
));
$this->assertTrue(isset($result['params']['url']['url']));
$this->assertEqual(array_keys($result['params']['named']), array('var1', 'var2'));
$result = $this->Case->testAction('/tests_apps_posts/url_var/gogo/val2', array(
@ -407,7 +406,6 @@ class ControllerTestCaseTest extends CakeTestCase {
));
$this->assertTrue(isset($result['params']['url']['red']));
$this->assertTrue(isset($result['params']['url']['blue']));
$this->assertTrue(isset($result['params']['url']['url']));
}
/**

View file

@ -227,6 +227,7 @@ class DebuggerTest extends CakeTestCase {
View::$helpers = array
View::$viewPath = ""
View::$viewVars = array
View::$view = NULL
View::$layout = "default"
View::$layoutPath = NULL
View::$autoLayout = true

View file

@ -862,7 +862,6 @@ class DispatcherTest extends CakeTestCase {
*/
public function testPluginDispatch() {
$_POST = array();
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
Router::reload();
$Dispatcher = new TestDispatcher();
@ -879,7 +878,6 @@ class DispatcherTest extends CakeTestCase {
'pass' => array('home'),
'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
'controller'=> 'some_pages', 'action'=> 'display', 'form'=> array(),
'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'),
);
foreach ($expected as $key => $value) {
$this->assertEqual($result[$key], $value, 'Value mismatch ' . $key . ' %');
@ -889,12 +887,6 @@ class DispatcherTest extends CakeTestCase {
$this->assertIdentical($controller->name, 'SomePages');
$this->assertIdentical($controller->params['controller'], 'some_pages');
$this->assertIdentical($controller->passedArgs, array('0' => 'home', 'param'=>'value', 'param2'=>'value2'));
$expected = '/cake/repo/branches/1.2.x.x/my_plugin/some_pages/home/param:value/param2:value2';
$this->assertIdentical($expected, $controller->here);
$expected = '/cake/repo/branches/1.2.x.x';
$this->assertIdentical($expected, $controller->base);
}
/**
@ -904,7 +896,7 @@ class DispatcherTest extends CakeTestCase {
*/
public function testAutomaticPluginDispatch() {
$_POST = array();
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
$_SERVER['SCRIPT_NAME'] = '/cake/repo/branches/1.2.x.x/index.php';
Router::reload();
$Dispatcher = new TestDispatcher();
@ -1018,11 +1010,10 @@ class DispatcherTest extends CakeTestCase {
'prefix' => 'admin',
'admin' => true,
'form' => array(),
'url' => array('url' => 'admin/articles_test'),
'return' => 1
);
foreach ($expected as $key => $value) {
$this->assertEqual($controller->params[$key], $expected[$key], 'Value mismatch ' . $key . ' %s');
$this->assertEqual($controller->request[$key], $expected[$key], 'Value mismatch ' . $key . ' %s');
}
}