2007-02-03 22:20:13 +00:00
< ? php
/* SVN FILE: $Id$ */
/**
* Short description for file .
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP ( tm ) Tests < https :// trac . cakephp . org / wiki / Developement / TestSuite >
2008-01-01 22:18:17 +00:00
* Copyright 2005 - 2008 , Cake Software Foundation , Inc .
2007-02-03 22:20:13 +00:00
* 1785 E . Sahara Avenue , Suite 490 - 204
* Las Vegas , Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice .
*
* @ filesource
2008-01-01 22:18:17 +00:00
* @ copyright Copyright 2005 - 2008 , Cake Software Foundation , Inc .
2007-02-03 22:20:13 +00:00
* @ link https :// trac . cakephp . org / wiki / Developement / TestSuite CakePHP ( tm ) Tests
* @ package cake . tests
* @ subpackage cake . tests . cases
* @ since CakePHP ( tm ) v 1.2 . 0.4206
* @ version $Revision $
* @ modifiedby $LastChangedBy $
* @ lastmodified $Date $
* @ license http :// www . opensource . org / licenses / opengroup . php The Open Group Test Suite License
*/
2007-07-25 04:38:28 +00:00
require_once CAKE . 'dispatcher.php' ;
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
Closes #2213, Support multiple plugin paths.
Closes #2234, filepaths to behavior classes should be cached in class.paths.php also
Closes #2345, ability to group components into subfolders
Closes #2645, Improvement to basic.php for class loading.
Fixes #3526, Cache::write, when using just the config name, it fails.
Fixes #3559, loading plugin model as assoc don't work.
Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique)
Fixes #3579, email.php component: Parse error with php 4.
Adding new class and file importer.
Updated most of the core to use the importer.
Added ClassRegsitry::init() that will create and instance of an object and store it in the registry.
Deprecated most of the load functions in basics.php
Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model.
var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models
var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set:
var $uses = array('SomeModel'); will look for some_model.php in the app/models
var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
All of the above will work between plugins and main app
These changes also allow placing model and controllers is sub directories
Removed old class.paths.php file generation
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-16 09:35:19 +00:00
App :: import ( 'Core' , 'AppController' );
2007-07-25 04:38:28 +00:00
class TestDispatcher extends Dispatcher {
function _invoke ( & $controller , $params , $missingAction ) {
2007-10-20 23:59:46 +00:00
$controller -> params =& $params ;
2007-07-25 04:38:28 +00:00
$classVars = get_object_vars ( $controller );
if ( $missingAction && in_array ( 'scaffold' , array_keys ( $classVars ))) {
uses ( 'controller' . DS . 'scaffold' );
return new Scaffold ( $controller , $params );
} elseif ( $missingAction && ! in_array ( 'scaffold' , array_keys ( $classVars ))) {
return $this -> cakeError ( 'missingAction' , array (
array (
'className' => Inflector :: camelize ( $params [ 'controller' ] . " Controller " ),
'action' => $params [ 'action' ],
'webroot' => $this -> webroot ,
'url' => $this -> here ,
'base' => $this -> base
)
));
}
return $controller ;
}
function cakeError ( $filename ) {
return $filename ;
}
}
2007-09-26 09:49:01 +00:00
class MyPluginAppController extends AppController {
2007-07-25 04:38:28 +00:00
}
2007-07-25 19:42:58 +00:00
class MyPluginController extends MyPluginAppController {
var $name = 'MyPlugin' ;
var $uses = array ();
function index () {
return true ;
}
function add () {
return true ;
}
2007-11-18 22:52:15 +00:00
function admin_add ( $id = null ) {
return $id ;
}
2007-07-25 19:42:58 +00:00
}
2007-07-25 21:08:12 +00:00
class SomePagesController extends AppController {
2007-07-25 04:38:28 +00:00
var $name = 'SomePages' ;
var $uses = array ();
function display ( $page = null ) {
return $page ;
}
2007-07-25 19:42:58 +00:00
function index () {
return true ;
}
2007-07-25 04:38:28 +00:00
}
2007-07-25 21:08:12 +00:00
class OtherPagesController extends MyPluginAppController {
var $name = 'OtherPages' ;
var $uses = array ();
function display ( $page = null ) {
return $page ;
}
function index () {
return true ;
}
}
class TestDispatchPagesController extends AppController {
2007-07-25 04:38:28 +00:00
var $name = 'TestDispatchPages' ;
var $uses = array ();
function admin_index () {
return true ;
}
}
2007-10-14 16:53:36 +00:00
class ArticlesTestAppController extends AppController {
}
class ArticlesTestController extends ArticlesTestAppController {
var $name = 'ArticlesTest' ;
var $uses = array ();
function admin_index () {
return true ;
}
}
2007-10-20 23:59:46 +00:00
class SomePostsController extends AppController {
var $name = 'SomePosts' ;
var $uses = array ();
var $autoRender = false ;
function beforeFilter () {
$this -> params [ 'action' ] = 'view' ;
$this -> params [ 'pass' ] = array ( 'changed' );
}
function index () {
return true ;
}
}
2007-11-05 14:56:21 +00:00
class TestCachedPagesController extends AppController {
var $name = 'TestCachedPages' ;
var $uses = array ();
var $helpers = array ( 'Cache' );
2007-12-22 01:37:46 +00:00
var $cacheAction = array ( 'index' => '+2 sec' , 'test_nocache_tags' => '+2 sec' );
var $viewPath = 'posts' ;
2007-11-05 14:56:21 +00:00
function index () {
2007-12-22 01:37:46 +00:00
$this -> render ();
2007-11-05 14:56:21 +00:00
}
2007-12-22 01:37:46 +00:00
function test_nocache_tags () {
2007-11-05 14:56:21 +00:00
//$this->cacheAction = '+2 sec';
2007-12-22 01:37:46 +00:00
$this -> render ();
2007-11-05 14:56:21 +00:00
}
}
2008-01-11 01:23:21 +00:00
class TimesheetsController extends AppController {
var $name = 'Timesheets' ;
var $uses = array ();
function index () {
return true ;
}
}
2007-02-03 22:20:13 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases
*/
class DispatcherTest extends UnitTestCase {
2007-07-25 04:38:28 +00:00
function setUp () {
$this -> _get = $_GET ;
$_GET = array ();
2007-11-03 16:39:29 +00:00
Configure :: write ( 'App.base' , false );
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.baseUrl' , false );
Configure :: write ( 'App.dir' , 'app' );
Configure :: write ( 'App.webroot' , 'webroot' );
2007-12-29 19:05:22 +00:00
Configure :: write ( 'Cache.disable' , true );
2007-07-25 04:38:28 +00:00
}
2007-02-03 22:20:13 +00:00
function testParseParamsWithoutZerosAndEmptyPost () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
$test = $Dispatcher -> parseParams ( " /testcontroller/testaction/params1/params2/params3 " );
2007-02-04 09:06:44 +00:00
$this -> assertIdentical ( $test [ 'controller' ], 'testcontroller' );
$this -> assertIdentical ( $test [ 'action' ], 'testaction' );
$this -> assertIdentical ( $test [ 'pass' ][ 0 ], 'params1' );
$this -> assertIdentical ( $test [ 'pass' ][ 1 ], 'params2' );
$this -> assertIdentical ( $test [ 'pass' ][ 2 ], 'params3' );
$this -> assertFalse ( ! empty ( $test [ 'form' ]));
2007-02-03 22:20:13 +00:00
}
function testParseParamsReturnsPostedData () {
$_POST [ 'testdata' ] = " My Posted Content " ;
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
$test = $Dispatcher -> parseParams ( " / " );
2007-02-03 22:20:13 +00:00
$this -> assertTrue ( $test [ 'form' ], " Parsed URL not returning post data " );
2007-02-04 09:06:44 +00:00
$this -> assertIdentical ( $test [ 'form' ][ 'testdata' ], " My Posted Content " );
2007-02-03 22:20:13 +00:00
}
function testParseParamsWithSingleZero () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
$test = $Dispatcher -> parseParams ( " /testcontroller/testaction/1/0/23 " );
2007-02-04 09:06:44 +00:00
$this -> assertIdentical ( $test [ 'controller' ], 'testcontroller' );
$this -> assertIdentical ( $test [ 'action' ], 'testaction' );
$this -> assertIdentical ( $test [ 'pass' ][ 0 ], '1' );
$this -> assertPattern ( '/\\A(?:0)\\z/' , $test [ 'pass' ][ 1 ]);
$this -> assertIdentical ( $test [ 'pass' ][ 2 ], '23' );
2007-02-03 22:20:13 +00:00
}
function testParseParamsWithManySingleZeros () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
$test = $Dispatcher -> parseParams ( " /testcontroller/testaction/0/0/0/0/0/0 " );
2007-02-04 09:06:44 +00:00
$this -> assertPattern ( '/\\A(?:0)\\z/' , $test [ 'pass' ][ 0 ]);
$this -> assertPattern ( '/\\A(?:0)\\z/' , $test [ 'pass' ][ 1 ]);
$this -> assertPattern ( '/\\A(?:0)\\z/' , $test [ 'pass' ][ 2 ]);
$this -> assertPattern ( '/\\A(?:0)\\z/' , $test [ 'pass' ][ 3 ]);
$this -> assertPattern ( '/\\A(?:0)\\z/' , $test [ 'pass' ][ 4 ]);
$this -> assertPattern ( '/\\A(?:0)\\z/' , $test [ 'pass' ][ 5 ]);
2007-02-03 22:20:13 +00:00
}
function testParseParamsWithManyZerosInEachSectionOfUrl () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
$test = $Dispatcher -> parseParams ( " /testcontroller/testaction/000/0000/00000/000000/000000/0000000 " );
2007-02-04 09:06:44 +00:00
$this -> assertPattern ( '/\\A(?:000)\\z/' , $test [ 'pass' ][ 0 ]);
$this -> assertPattern ( '/\\A(?:0000)\\z/' , $test [ 'pass' ][ 1 ]);
$this -> assertPattern ( '/\\A(?:00000)\\z/' , $test [ 'pass' ][ 2 ]);
$this -> assertPattern ( '/\\A(?:000000)\\z/' , $test [ 'pass' ][ 3 ]);
$this -> assertPattern ( '/\\A(?:000000)\\z/' , $test [ 'pass' ][ 4 ]);
$this -> assertPattern ( '/\\A(?:0000000)\\z/' , $test [ 'pass' ][ 5 ]);
2007-02-03 22:20:13 +00:00
}
function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
$test = $Dispatcher -> parseParams ( " /testcontroller/testaction/01/0403/04010/000002/000030/0000400 " );
2007-02-04 09:06:44 +00:00
$this -> assertPattern ( '/\\A(?:01)\\z/' , $test [ 'pass' ][ 0 ]);
$this -> assertPattern ( '/\\A(?:0403)\\z/' , $test [ 'pass' ][ 1 ]);
$this -> assertPattern ( '/\\A(?:04010)\\z/' , $test [ 'pass' ][ 2 ]);
$this -> assertPattern ( '/\\A(?:000002)\\z/' , $test [ 'pass' ][ 3 ]);
$this -> assertPattern ( '/\\A(?:000030)\\z/' , $test [ 'pass' ][ 4 ]);
$this -> assertPattern ( '/\\A(?:0000400)\\z/' , $test [ 'pass' ][ 5 ]);
2007-02-03 22:20:13 +00:00
}
2008-05-17 03:52:08 +00:00
function testQueryStringOnRoot () {
$_GET = array ( 'coffee' => 'life' ,
'sleep' => 'sissies' );
$Dispatcher =& new Dispatcher ();
$uri = 'posts/home/?coffee=life&sleep=sissies' ;
$result = $Dispatcher -> parseParams ( $uri );
$this -> assertPattern ( '/posts/' , $result [ 'controller' ]);
$this -> assertPattern ( '/home/' , $result [ 'action' ]);
$this -> assertTrue ( isset ( $result [ 'url' ][ 'sleep' ]));
$this -> assertTrue ( isset ( $result [ 'url' ][ 'coffee' ]));
$Dispatcher =& new Dispatcher ();
$uri = '/?coffee=life&sleep=sissy' ;
$result = $Dispatcher -> parseParams ( $uri );
$this -> assertPattern ( '/pages/' , $result [ 'controller' ]);
$this -> assertPattern ( '/display/' , $result [ 'action' ]);
$this -> assertTrue ( isset ( $result [ 'url' ][ 'sleep' ]));
$this -> assertTrue ( isset ( $result [ 'url' ][ 'coffee' ]));
$this -> assertEqual ( $result [ 'url' ][ 'coffee' ], 'life' );
$_GET = $this -> _get ;
}
2007-07-25 04:38:28 +00:00
2008-01-15 07:37:29 +00:00
function testFileUploadArrayStructure () {
$_FILES = array ( 'data' => array ( 'name' => array (
'File' => array (
array ( 'data' => 'cake_mssql_patch.patch' ),
array ( 'data' => 'controller.diff' ),
array ( 'data' => '' ),
array ( 'data' => '' ),
),
'Post' => array ( 'attachment' => 'jquery-1.2.1.js' ),
),
'type' => array (
'File' => array (
array ( 'data' => '' ),
array ( 'data' => '' ),
array ( 'data' => '' ),
array ( 'data' => '' ),
),
'Post' => array ( 'attachment' => 'application/x-javascript' ),
),
'tmp_name' => array (
'File' => array (
array ( 'data' => '/private/var/tmp/phpy05Ywj' ),
array ( 'data' => '/private/var/tmp/php7MBztY' ),
array ( 'data' => '' ),
array ( 'data' => '' ),
),
'Post' => array ( 'attachment' => '/private/var/tmp/phpEwlrIo' ),
),
'error' => array (
'File' => array (
array ( 'data' => 0 ),
array ( 'data' => 0 ),
array ( 'data' => 4 ),
array ( 'data' => 4 )
),
'Post' => array ( 'attachment' => 0 )
),
'size' => array (
'File' => array (
array ( 'data' => 6271 ),
array ( 'data' => 350 ),
array ( 'data' => 0 ),
array ( 'data' => 0 ),
),
'Post' => array ( 'attachment' => 80469 )
),
));
$Dispatcher =& new Dispatcher ();
$result = $Dispatcher -> parseParams ( '/' );
$expected = array (
'File' => array (
array ( 'data' => array (
'name' => 'cake_mssql_patch.patch' ,
'type' => '' ,
'tmp_name' => '/private/var/tmp/phpy05Ywj' ,
'error' => 0 ,
'size' => 6271 ,
),
),
array ( 'data' => array (
'name' => 'controller.diff' ,
'type' => '' ,
'tmp_name' => '/private/var/tmp/php7MBztY' ,
'error' => 0 ,
'size' => 350 ,
)),
array ( 'data' => array (
'name' => '' ,
'type' => '' ,
'tmp_name' => '' ,
'error' => 4 ,
'size' => 0 ,
)),
array ( 'data' => array (
'name' => '' ,
'type' => '' ,
'tmp_name' => '' ,
'error' => 4 ,
'size' => 0 ,
)),
),
'Post' => array ( 'attachment' => array (
'name' => 'jquery-1.2.1.js' ,
'type' => 'application/x-javascript' ,
'tmp_name' => '/private/var/tmp/phpEwlrIo' ,
'error' => 0 ,
'size' => 80469 ,
)));
$this -> assertEqual ( $result [ 'data' ], $expected );
$_FILES = array ();
}
2007-08-05 02:03:18 +00:00
function testGetUrl () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
$Dispatcher -> base = '/app/webroot/index.php' ;
2007-07-25 04:38:28 +00:00
$uri = '/app/webroot/index.php/posts/add' ;
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> getUrl ( $uri );
2007-07-25 04:38:28 +00:00
$expected = 'posts/add' ;
$this -> assertEqual ( $expected , $result );
2007-08-05 02:03:18 +00:00
Configure :: write ( 'App.baseUrl' , '/app/webroot/index.php' );
2007-07-25 04:38:28 +00:00
$uri = '/posts/add' ;
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> getUrl ( $uri );
2007-07-25 04:38:28 +00:00
$expected = 'posts/add' ;
$this -> assertEqual ( $expected , $result );
2007-08-05 02:03:18 +00:00
$_GET [ 'url' ] = array ();
Configure :: write ( 'App.base' , '/control' );
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
2007-08-05 02:03:18 +00:00
$uri = '/control/students/browse' ;
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> getUrl ( $uri );
2007-08-05 02:03:18 +00:00
$expected = 'students/browse' ;
$this -> assertEqual ( $expected , $result );
2008-01-24 21:19:13 +00:00
$_GET [ 'url' ] = array ();
$Dispatcher =& new Dispatcher ();
$Dispatcher -> base = '' ;
$uri = '/?/home' ;
$result = $Dispatcher -> getUrl ( $uri );
$expected = '?/home' ;
$this -> assertEqual ( $expected , $result );
2008-05-17 03:52:08 +00:00
2007-07-25 04:38:28 +00:00
}
function testBaseUrlAndWebrootWithModRewrite () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
2007-11-05 14:56:21 +00:00
2007-11-03 16:39:29 +00:00
$Dispatcher -> base = false ;
2007-07-25 04:38:28 +00:00
$_SERVER [ 'DOCUMENT_ROOT' ] = '/cake/repo/branches' ;
$_SERVER [ 'SCRIPT_FILENAME' ] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php' ;
2007-08-06 15:09:51 +00:00
$_SERVER [ 'PHP_SELF' ] = '/1.2.x.x/app/webroot/index.php' ;
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-07-25 04:38:28 +00:00
$expected = '/1.2.x.x' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/1.2.x.x/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-11-05 14:56:21 +00:00
2007-11-03 16:39:29 +00:00
$Dispatcher -> base = false ;
2007-07-25 04:38:28 +00:00
$_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' ;
2007-08-06 15:09:51 +00:00
$_SERVER [ 'PHP_SELF' ] = '/index.php' ;
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-07-25 04:38:28 +00:00
$expected = '' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-11-05 14:56:21 +00:00
$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 );
2007-11-03 16:39:29 +00:00
$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 );
2007-11-05 14:56:21 +00:00
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.dir' , 'auth' );
2007-07-25 04:38:28 +00:00
2007-11-03 16:39:29 +00:00
$Dispatcher -> base = false ;;
2007-07-25 04:38:28 +00:00
$_SERVER [ 'DOCUMENT_ROOT' ] = '/cake/repo/branches' ;
$_SERVER [ 'SCRIPT_FILENAME' ] = '/cake/repo/branches/demos/auth/webroot/index.php' ;
2007-08-06 15:09:51 +00:00
$_SERVER [ 'PHP_SELF' ] = '/demos/auth/webroot/index.php' ;
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-07-25 04:38:28 +00:00
$expected = '/demos/auth' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/demos/auth/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.dir' , 'code' );
2007-07-25 04:38:28 +00:00
2007-11-03 16:39:29 +00:00
$Dispatcher -> base = false ;;
2007-07-25 04:38:28 +00:00
$_SERVER [ 'DOCUMENT_ROOT' ] = '/Library/WebServer/Documents' ;
$_SERVER [ 'SCRIPT_FILENAME' ] = '/Library/WebServer/Documents/clients/PewterReport/code/webroot/index.php' ;
2007-08-06 15:09:51 +00:00
$_SERVER [ 'PHP_SELF' ] = '/clients/PewterReport/code/webroot/index.php' ;
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-07-25 04:38:28 +00:00
$expected = '/clients/PewterReport/code' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/clients/PewterReport/code/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
}
2007-08-02 00:16:28 +00:00
function testBaseUrlwithModRewriteAlias () {
$_SERVER [ 'DOCUMENT_ROOT' ] = '/home/aplusnur/public_html' ;
$_SERVER [ 'SCRIPT_FILENAME' ] = '/home/aplusnur/cake2/app/webroot/index.php' ;
2007-08-06 15:09:51 +00:00
$_SERVER [ 'PHP_SELF' ] = '/control/index.php' ;
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.base' , '/control' );
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
$result = $Dispatcher -> baseUrl ();
2007-08-02 00:16:28 +00:00
$expected = '/control' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/control/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.base' , false );
2007-08-02 19:12:19 +00:00
Configure :: write ( 'App.dir' , 'affiliate' );
Configure :: write ( 'App.webroot' , 'newaffiliate' );
$_SERVER [ 'DOCUMENT_ROOT' ] = '/var/www/abtravaff/html' ;
$_SERVER [ 'SCRIPT_FILENAME' ] = '/var/www/abtravaff/html/newaffiliate/index.php' ;
2007-08-06 15:09:51 +00:00
$_SERVER [ 'PHP_SELF' ] = '/newaffiliate/index.php' ;
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
$result = $Dispatcher -> baseUrl ();
2007-08-02 19:12:19 +00:00
$expected = '/newaffiliate' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/newaffiliate/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-08-02 00:16:28 +00:00
}
2007-07-25 04:38:28 +00:00
function testBaseUrlAndWebrootWithBaseUrl () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.dir' , 'app' );
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.baseUrl' , '/app/webroot/index.php' );
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-08-05 02:03:18 +00:00
$expected = '/app/webroot/index.php' ;
2007-07-25 04:38:28 +00:00
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/app/webroot/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.baseUrl' , '/app/webroot/test.php' );
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-08-05 02:03:18 +00:00
$expected = '/app/webroot/test.php' ;
2007-07-25 04:38:28 +00:00
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/app/webroot/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.baseUrl' , '/app/index.php' );
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-07-25 04:38:28 +00:00
$expected = '/app/index.php' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/app/webroot/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.baseUrl' , '/index.php' );
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-07-25 04:38:28 +00:00
$expected = '/index.php' ;
$this -> assertEqual ( $expected , $result );
2007-08-05 02:03:18 +00:00
$expectedWebroot = '/app/webroot/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.baseUrl' , '/CakeBB/app/webroot/index.php' );
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-08-05 02:03:18 +00:00
$expected = '/CakeBB/app/webroot/index.php' ;
2007-07-25 04:38:28 +00:00
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/CakeBB/app/webroot/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.baseUrl' , '/CakeBB/app/index.php' );
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-07-25 04:38:28 +00:00
$expected = '/CakeBB/app/index.php' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/CakeBB/app/webroot/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.baseUrl' , '/CakeBB/index.php' );
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-07-25 04:38:28 +00:00
$expected = '/CakeBB/index.php' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/CakeBB/app/webroot/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
2007-10-20 23:59:46 +00:00
Configure :: write ( 'App.baseUrl' , '/dbhauser/index.php' );
$_SERVER [ 'DOCUMENT_ROOT' ] = '/kunden/homepages/4/d181710652/htdocs/joomla' ;
$_SERVER [ 'SCRIPT_FILENAME' ] = '/kunden/homepages/4/d181710652/htdocs/joomla/dbhauser/index.php' ;
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> baseUrl ();
2007-10-20 23:59:46 +00:00
$expected = '/dbhauser/index.php' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/dbhauser/app/webroot/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
}
function testBaseUrlAndWebrootWithBase () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new Dispatcher ();
$Dispatcher -> base = '/app' ;
$result = $Dispatcher -> baseUrl ();
2007-07-25 04:38:28 +00:00
$expected = '/app' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/app/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
2007-11-03 16:39:29 +00:00
$Dispatcher -> base = '' ;
$result = $Dispatcher -> baseUrl ();
2007-07-25 04:38:28 +00:00
$expected = '' ;
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
2007-08-02 00:16:28 +00:00
Configure :: write ( 'App.dir' , 'testbed' );
2007-11-03 16:39:29 +00:00
$Dispatcher -> base = '/cake/testbed/webroot' ;
$result = $Dispatcher -> baseUrl ();
2007-08-02 00:16:28 +00:00
$expected = '/cake/testbed/webroot' ;
2007-07-25 04:38:28 +00:00
$this -> assertEqual ( $expected , $result );
$expectedWebroot = '/cake/testbed/webroot/' ;
2007-11-03 16:39:29 +00:00
$this -> assertEqual ( $expectedWebroot , $Dispatcher -> webroot );
2007-07-25 04:38:28 +00:00
}
function testMissingController () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
2007-08-05 02:03:18 +00:00
Configure :: write ( 'App.baseUrl' , '/index.php' );
$url = 'some_controller/home/param:value/param2:value2' ;
2007-11-03 16:39:29 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-07-25 04:38:28 +00:00
$expected = 'missingController' ;
$this -> assertEqual ( $expected , $controller );
}
function testPrivate () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
2007-08-05 02:03:18 +00:00
Configure :: write ( 'App.baseUrl' , '/index.php' );
$url = 'some_pages/redirect/param:value/param2:value2' ;
2007-11-03 16:39:29 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-07-25 04:38:28 +00:00
$expected = 'privateAction' ;
$this -> assertEqual ( $expected , $controller );
}
function testMissingAction () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
2007-08-05 02:03:18 +00:00
Configure :: write ( 'App.baseUrl' , '/index.php' );
$url = 'some_pages/home/param:value/param2:value2' ;
2007-07-25 04:38:28 +00:00
2007-11-03 16:39:29 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-07-25 04:38:28 +00:00
$expected = 'missingAction' ;
$this -> assertEqual ( $expected , $controller );
}
function testDispatch () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
2007-08-05 02:03:18 +00:00
Configure :: write ( 'App.baseUrl' , '/index.php' );
$url = 'pages/home/param:value/param2:value2' ;
2007-07-25 04:38:28 +00:00
2007-11-03 16:39:29 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-07-25 04:38:28 +00:00
$expected = 'Pages' ;
$this -> assertEqual ( $expected , $controller -> name );
2007-10-20 23:59:46 +00:00
$expected = array ( '0' => 'home' , 'param' => 'value' , 'param2' => 'value2' );
$this -> assertIdentical ( $expected , $controller -> passedArgs );
2008-01-11 01:23:21 +00:00
Configure :: write ( 'App.baseUrl' , '/pages/index.php' );
$url = 'pages/home' ;
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
$expected = 'Pages' ;
$this -> assertEqual ( $expected , $controller -> name );
$url = 'pages/home/' ;
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
$expected = 'Pages' ;
$this -> assertEqual ( $expected , $controller -> name );
2008-01-13 05:18:51 +00:00
unset ( $Dispatcher );
$Dispatcher =& new TestDispatcher ();
2008-01-11 01:23:21 +00:00
Configure :: write ( 'App.baseUrl' , '/timesheets/index.php' );
$url = 'timesheets' ;
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
$expected = 'Timesheets' ;
$this -> assertEqual ( $expected , $controller -> name );
$url = 'timesheets/' ;
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2008-01-13 05:18:51 +00:00
$this -> assertEqual ( 'Timesheets' , $controller -> name );
2008-01-11 01:23:21 +00:00
$this -> assertEqual ( '/timesheets/index.php' , $Dispatcher -> base );
2007-07-25 04:38:28 +00:00
}
function testAdminDispatch () {
$_POST = array ();
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
2007-08-16 05:44:06 +00:00
Configure :: write ( 'Routing.admin' , 'admin' );
2007-08-05 02:03:18 +00:00
Configure :: write ( 'App.baseUrl' , '/cake/repo/branches/1.2.x.x/index.php' );
$url = 'admin/test_dispatch_pages/index/param:value/param2:value2' ;
2007-08-16 05:44:06 +00:00
2007-07-25 04:38:28 +00:00
Router :: reload ();
$Router =& Router :: getInstance ();
2007-11-03 16:39:29 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-07-25 04:38:28 +00:00
$expected = 'TestDispatchPages' ;
$this -> assertEqual ( $expected , $controller -> name );
2007-08-16 05:44:06 +00:00
$expected = array ( 'param' => 'value' , 'param2' => 'value2' );
2007-10-20 23:59:46 +00:00
$this -> assertIdentical ( $expected , $controller -> passedArgs );
2007-08-16 05:44:06 +00:00
$this -> assertTrue ( $controller -> params [ 'admin' ]);
2007-07-25 04:38:28 +00:00
2007-08-05 02:03:18 +00:00
$expected = '/cake/repo/branches/1.2.x.x/index.php/admin/test_dispatch_pages/index/param:value/param2:value2' ;
2007-07-25 04:38:28 +00:00
$this -> assertIdentical ( $expected , $controller -> here );
2007-08-05 02:03:18 +00:00
$expected = '/cake/repo/branches/1.2.x.x/index.php' ;
2007-07-25 04:38:28 +00:00
$this -> assertIdentical ( $expected , $controller -> base );
}
function testPluginDispatch () {
$_POST = array ();
2007-08-06 15:09:51 +00:00
$_SERVER [ 'PHP_SELF' ] = '/cake/repo/branches/1.2.x.x/index.php' ;
2007-07-25 04:38:28 +00:00
Router :: reload ();
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
2007-07-25 04:38:28 +00:00
Router :: connect ( '/my_plugin/:controller/*' , array ( 'plugin' => 'my_plugin' , 'controller' => 'pages' , 'action' => 'display' ));
2007-11-03 16:39:29 +00:00
$Dispatcher -> base = false ;
2007-08-05 02:03:18 +00:00
$url = 'my_plugin/some_pages/home/param:value/param2:value2' ;
2007-11-03 16:39:29 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-07-25 04:38:28 +00:00
2007-11-03 16:39:29 +00:00
$result = $Dispatcher -> parseParams ( $url );
2008-02-11 06:18:41 +00:00
$expected = array (
'pass' => array ( 'home' ),
'named' => array ( 'param' => 'value' , 'param2' => 'value2' ), 'plugin' => 'my_plugin' ,
'controller' => 'some_pages' , 'action' => 'display' , 'form' => null ,
'url' => array ( 'url' => 'my_plugin/some_pages/home/param:value/param2:value2' ),
);
2007-07-25 19:42:58 +00:00
ksort ( $expected );
ksort ( $result );
2007-07-25 04:38:28 +00:00
$this -> assertEqual ( $expected , $result );
$expected = 'my_plugin' ;
$this -> assertIdentical ( $expected , $controller -> plugin );
$expected = 'SomePages' ;
$this -> assertIdentical ( $expected , $controller -> name );
2007-10-20 23:59:46 +00:00
$expected = array ( '0' => 'home' , 'param' => 'value' , 'param2' => 'value2' );
$this -> assertIdentical ( $expected , $controller -> passedArgs );
2007-07-25 04:38:28 +00:00
$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 );
}
2007-07-25 19:42:58 +00:00
function testAutomaticPluginDispatch () {
$_POST = array ();
2007-08-06 15:09:51 +00:00
$_SERVER [ 'PHP_SELF' ] = '/cake/repo/branches/1.2.x.x/index.php' ;
2007-07-25 19:42:58 +00:00
Router :: reload ();
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
2008-01-11 01:23:21 +00:00
Router :: connect ( '/my_plugin/:controller/:action/*' , array ( 'plugin' => 'my_plugin' , 'controller' => 'pages' , 'action' => 'display' ));
2007-11-03 16:39:29 +00:00
$Dispatcher -> base = false ;
2007-07-25 19:42:58 +00:00
2007-08-05 02:03:18 +00:00
$url = 'my_plugin/other_pages/index/param:value/param2:value2' ;
2008-04-19 13:43:07 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-07-25 19:42:58 +00:00
$expected = 'my_plugin' ;
$this -> assertIdentical ( $expected , $controller -> plugin );
2007-07-25 21:08:12 +00:00
$expected = 'OtherPages' ;
2007-07-25 19:42:58 +00:00
$this -> assertIdentical ( $expected , $controller -> name );
$expected = 'index' ;
$this -> assertIdentical ( $expected , $controller -> action );
2008-04-19 13:43:07 +00:00
$expected = array ( 'param' => 'value' , 'param2' => 'value2' );
2007-10-20 23:59:46 +00:00
$this -> assertIdentical ( $expected , $controller -> passedArgs );
2007-07-25 19:42:58 +00:00
2007-07-25 21:08:12 +00:00
$expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2' ;
2007-07-25 19:42:58 +00:00
$this -> assertIdentical ( $expected , $controller -> here );
$expected = '/cake/repo/branches/1.2.x.x' ;
$this -> assertIdentical ( $expected , $controller -> base );
}
function testAutomaticPluginControllerDispatch () {
$_POST = array ();
2007-08-06 15:09:51 +00:00
$_SERVER [ 'PHP_SELF' ] = '/cake/repo/branches/1.2.x.x/index.php' ;
2007-07-25 19:42:58 +00:00
Router :: reload ();
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
$Dispatcher -> base = false ;
2007-10-31 03:53:41 +00:00
2007-08-05 02:03:18 +00:00
$url = 'my_plugin/add/param:value/param2:value2' ;
2007-07-25 19:42:58 +00:00
2007-11-03 16:39:29 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-07-25 19:42:58 +00:00
$expected = 'my_plugin' ;
2007-08-16 16:31:50 +00:00
$this -> assertIdentical ( $controller -> plugin , $expected );
2007-07-25 19:42:58 +00:00
$expected = 'MyPlugin' ;
2007-08-16 16:31:50 +00:00
$this -> assertIdentical ( $controller -> name , $expected );
2007-07-25 19:42:58 +00:00
$expected = 'add' ;
2007-08-16 16:31:50 +00:00
$this -> assertIdentical ( $controller -> action , $expected );
2007-12-13 07:03:59 +00:00
$expected = array ( 'param' => 'value' , 'param2' => 'value2' );
2007-10-31 03:53:41 +00:00
$this -> assertEqual ( $controller -> params [ 'named' ], $expected );
2007-10-14 16:53:36 +00:00
2007-11-18 22:52:15 +00:00
Configure :: write ( 'Routing.admin' , 'admin' );
Router :: reload ();
$Dispatcher =& new TestDispatcher ();
$Dispatcher -> base = false ;
$url = 'admin/my_plugin/add/5/param:value/param2:value2' ;
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
$expected = 'my_plugin' ;
$this -> assertIdentical ( $controller -> plugin , $expected );
$expected = 'MyPlugin' ;
$this -> assertIdentical ( $controller -> name , $expected );
$expected = 'admin_add' ;
$this -> assertIdentical ( $controller -> action , $expected );
$expected = array ( 0 => 5 , 'param' => 'value' , 'param2' => 'value2' );
$this -> assertEqual ( $controller -> passedArgs , $expected );
2007-10-14 16:53:36 +00:00
Router :: reload ();
2007-10-20 23:59:46 +00:00
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
$Dispatcher -> base = false ;
2007-10-31 03:53:41 +00:00
2008-04-19 13:43:07 +00:00
$controller = $Dispatcher -> dispatch ( 'admin/articles_test' , array ( 'return' => 1 ));
2007-10-14 16:53:36 +00:00
$expected = 'articles_test' ;
$this -> assertIdentical ( $controller -> plugin , $expected );
$expected = 'ArticlesTest' ;
$this -> assertIdentical ( $controller -> name , $expected );
$expected = 'admin_index' ;
$this -> assertIdentical ( $controller -> action , $expected );
2007-12-29 19:05:22 +00:00
2008-02-11 06:18:41 +00:00
$expected = array (
'pass' => array (), 'named' => array (), 'controller' => 'articles_test' , 'plugin' => 'articles_test' , 'action' => 'admin_index' ,
'prefix' => 'admin' , 'admin' => true , 'form' => array (), 'url' => array ( 'url' => 'admin/articles_test' ), 'return' => 1
);
2007-10-20 23:59:46 +00:00
$this -> assertEqual ( $controller -> params , $expected );
2007-07-25 19:42:58 +00:00
}
2007-07-25 21:08:12 +00:00
function testAutomaticPluginControllerMissingActionDispatch () {
2007-07-25 19:42:58 +00:00
$_POST = array ();
2007-08-06 15:09:51 +00:00
$_SERVER [ 'PHP_SELF' ] = '/cake/repo/branches/1.2.x.x/index.php' ;
2007-07-25 19:42:58 +00:00
Router :: reload ();
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
$Dispatcher -> base = false ;
2007-07-25 19:42:58 +00:00
2007-08-05 02:03:18 +00:00
$url = 'my_plugin/param:value/param2:value2' ;
2007-11-03 16:39:29 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-07-25 19:42:58 +00:00
2007-07-25 21:08:12 +00:00
$expected = 'missingAction' ;
2007-07-25 19:42:58 +00:00
$this -> assertIdentical ( $expected , $controller );
}
2007-08-16 05:44:06 +00:00
function testPrefixProtection () {
$_POST = array ();
$_SERVER [ 'PHP_SELF' ] = '/cake/repo/branches/1.2.x.x/index.php' ;
Router :: reload ();
Router :: connect ( '/admin/:controller/:action/*' , array ( 'prefix' => 'admin' ), array ( 'controller' , 'action' ));
2007-09-20 07:24:57 +00:00
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
$Dispatcher -> base = false ;
2007-08-16 05:44:06 +00:00
$url = 'test_dispatch_pages/admin_index/param:value/param2:value2' ;
2007-11-03 16:39:29 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-09-20 07:24:57 +00:00
2007-08-16 05:44:06 +00:00
$expected = 'privateAction' ;
2007-09-20 07:24:57 +00:00
$this -> assertIdentical ( $expected , $controller );
2007-08-16 05:44:06 +00:00
}
2007-10-20 23:59:46 +00:00
function testChangingParamsFromBeforeFilter () {
2007-11-03 16:39:29 +00:00
$Dispatcher =& new TestDispatcher ();
2007-10-20 23:59:46 +00:00
$url = 'some_posts/index/param:value/param2:value2' ;
2007-11-03 16:39:29 +00:00
$controller = $Dispatcher -> dispatch ( $url , array ( 'return' => 1 ));
2007-10-20 23:59:46 +00:00
$expected = 'SomePosts' ;
$this -> assertEqual ( $expected , $controller -> name );
$expected = 'view' ;
$this -> assertEqual ( $expected , $controller -> action );
$expected = array ( 'changed' );
$this -> assertIdentical ( $expected , $controller -> params [ 'pass' ]);
}
2007-12-22 01:37:46 +00:00
function testStaticAssets () {
2007-12-29 19:05:22 +00:00
Router :: reload ();
$Configure = Configure :: getInstance ();
$Configure -> __objects = null ;
2007-12-22 01:37:46 +00:00
Configure :: write ( 'pluginPaths' , array ( TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS ));
Configure :: write ( 'vendorPaths' , array ( TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS ));
2007-12-29 19:05:22 +00:00
$Dispatcher =& new TestDispatcher ();
2007-12-22 01:37:46 +00:00
Configure :: write ( 'debug' , 0 );
2007-12-29 19:05:22 +00:00
$Dispatcher -> params = $Dispatcher -> parseParams ( 'css/test_asset.css' );
2007-12-22 01:37:46 +00:00
ob_start ();
$Dispatcher -> cached ( 'css/test_asset.css' );
$result = ob_get_clean ();
$this -> assertEqual ( 'this is the test asset css file' , $result );
2008-05-17 03:52:08 +00:00
2007-12-22 01:37:46 +00:00
Configure :: write ( 'debug' , 0 );
2007-12-29 19:05:22 +00:00
$Dispatcher -> params = $Dispatcher -> parseParams ( 'test_plugin/css/test_plugin_asset.css' );
2007-12-22 01:37:46 +00:00
ob_start ();
2007-12-29 19:05:22 +00:00
$Dispatcher -> cached ( 'test_plugin/css/test_plugin_asset.css' );
2007-12-22 01:37:46 +00:00
$result = ob_get_clean ();
$this -> assertEqual ( 'this is the test plugin asset css file' , $result );
2008-05-17 03:52:08 +00:00
header ( 'Content-type: text/html' ); //reset the header content-type without page can render as plain text.
2007-12-22 01:37:46 +00:00
}
function testFullPageCachingDispatch () {
2007-12-29 19:05:22 +00:00
Configure :: write ( 'Cache.disable' , false );
2007-12-22 01:37:46 +00:00
Configure :: write ( 'Cache.check' , true );
Configure :: write ( 'debug' , 2 );
2007-12-29 19:05:22 +00:00
2007-12-22 01:37:46 +00:00
$_POST = array ();
2008-01-01 22:52:25 +00:00
$_SERVER [ 'PHP_SELF' ] = '/' ;
2007-12-22 01:37:46 +00:00
Router :: reload ();
2008-01-01 22:52:25 +00:00
Router :: connect ( '/' , array ( 'controller' => 'test_cached_pages' , 'action' => 'index' ));
2007-12-22 01:37:46 +00:00
Configure :: write ( 'viewPaths' , array ( TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS ));
$dispatcher =& new Dispatcher ();
$dispatcher -> base = false ;
2008-01-01 22:52:25 +00:00
$url = '/' ;
ob_start ();
$dispatcher -> dispatch ( $url );
$out = ob_get_clean ();
ob_start ();
$dispatcher -> cached ( $url );
$cached = ob_get_clean ();
$result = str_replace ( array ( " \t " , " \r \n " , " \n " ), " " , $out );
$cached = preg_replace ( '/<!--+[^<>]+-->/' , '' , $cached );
$expected = str_replace ( array ( " \t " , " \r \n " , " \n " ), " " , $cached );
$this -> assertEqual ( $result , $expected );
$filename = CACHE . 'views' . DS . Inflector :: slug ( $dispatcher -> here ) . '.php' ;
unlink ( $filename );
$dispatcher -> base = false ;
2007-12-22 01:37:46 +00:00
$url = 'test_cached_pages/index' ;
ob_start ();
2007-12-29 19:05:22 +00:00
$dispatcher -> dispatch ( $url );
2007-12-22 01:37:46 +00:00
$out = ob_get_clean ();
ob_start ();
2007-12-29 19:05:22 +00:00
$dispatcher -> cached ( $url );
2007-12-22 01:37:46 +00:00
$cached = ob_get_clean ();
$result = str_replace ( array ( " \t " , " \r \n " , " \n " ), " " , $out );
$cached = preg_replace ( '/<!--+[^<>]+-->/' , '' , $cached );
$expected = str_replace ( array ( " \t " , " \r \n " , " \n " ), " " , $cached );
$this -> assertEqual ( $result , $expected );
2007-12-29 19:05:22 +00:00
$filename = CACHE . 'views' . DS . Inflector :: slug ( $dispatcher -> here ) . '.php' ;
2007-12-22 01:37:46 +00:00
unlink ( $filename );
2008-03-16 07:18:42 +00:00
2008-03-09 22:39:29 +00:00
$url = 'TestCachedPages/index' ;
ob_start ();
$dispatcher -> dispatch ( $url );
$out = ob_get_clean ();
ob_start ();
$dispatcher -> cached ( $url );
$cached = ob_get_clean ();
$result = str_replace ( array ( " \t " , " \r \n " , " \n " ), " " , $out );
$cached = preg_replace ( '/<!--+[^<>]+-->/' , '' , $cached );
2008-05-01 05:55:48 +00:00
$expected = str_replace ( array ( " \t " , " \r \n " , " \n " ), " " , $cached );
$this -> assertEqual ( $result , $expected );
$filename = CACHE . 'views' . DS . Inflector :: slug ( $dispatcher -> here ) . '.php' ;
unlink ( $filename );
$url = 'TestCachedPages/test_nocache_tags' ;
ob_start ();
$dispatcher -> dispatch ( $url );
$out = ob_get_clean ();
ob_start ();
$dispatcher -> cached ( $url );
$cached = ob_get_clean ();
$result = str_replace ( array ( " \t " , " \r \n " , " \n " ), " " , $out );
$cached = preg_replace ( '/<!--+[^<>]+-->/' , '' , $cached );
2008-03-09 22:39:29 +00:00
$expected = str_replace ( array ( " \t " , " \r \n " , " \n " ), " " , $cached );
$this -> assertEqual ( $result , $expected );
$filename = CACHE . 'views' . DS . Inflector :: slug ( $dispatcher -> here ) . '.php' ;
unlink ( $filename );
2007-12-22 01:37:46 +00:00
}
2008-01-26 08:50:06 +00:00
function testHttpMethodOverrides () {
Router :: reload ();
Router :: mapResources ( 'Posts' );
$_SERVER [ 'REQUEST_METHOD' ] = 'POST' ;
$dispatcher =& new Dispatcher ();
$dispatcher -> base = false ;
$result = $dispatcher -> parseParams ( '/posts' );
2008-02-11 06:18:41 +00:00
$expected = array ( 'pass' => array (), 'named' => array (), 'plugin' => null , 'controller' => 'posts' , 'action' => 'add' , '[method]' => 'POST' , 'form' => array (), 'url' => array ());
2008-01-26 08:50:06 +00:00
$this -> assertEqual ( $result , $expected );
$_SERVER [ 'REQUEST_METHOD' ] = 'GET' ;
$_SERVER [ 'HTTP_X_HTTP_METHOD_OVERRIDE' ] = 'PUT' ;
$result = $dispatcher -> parseParams ( '/posts/5' );
2008-03-01 03:13:19 +00:00
$expected = array ( 'pass' => array ( '5' ), 'named' => array (), 'id' => '5' , 'plugin' => null , 'controller' => 'posts' , 'action' => 'edit' , '[method]' => 'PUT' , 'form' => array (), 'url' => array ());
2008-01-26 08:50:06 +00:00
$this -> assertEqual ( $result , $expected );
unset ( $_SERVER [ 'HTTP_X_HTTP_METHOD_OVERRIDE' ]);
$_SERVER [ 'REQUEST_METHOD' ] = 'GET' ;
$result = $dispatcher -> parseParams ( '/posts/5' );
2008-03-01 03:13:19 +00:00
$expected = array ( 'pass' => array ( '5' ), 'named' => array (), 'id' => '5' , 'plugin' => null , 'controller' => 'posts' , 'action' => 'view' , '[method]' => 'GET' , 'form' => array (), 'url' => array ());
2008-01-26 08:50:06 +00:00
$this -> assertEqual ( $result , $expected );
$_POST [ '_method' ] = 'PUT' ;
$result = $dispatcher -> parseParams ( '/posts/5' );
2008-03-01 03:13:19 +00:00
$expected = array ( 'pass' => array ( '5' ), 'named' => array (), 'id' => '5' , 'plugin' => null , 'controller' => 'posts' , 'action' => 'edit' , '[method]' => 'PUT' , 'form' => array (), 'url' => array ());
2008-01-26 08:50:06 +00:00
$this -> assertEqual ( $result , $expected );
2008-04-26 11:43:26 +00:00
$_POST [ '_method' ] = 'POST' ;
$_POST [ 'data' ] = array ( 'Post' => array ( 'title' => 'New Post' ));
$_POST [ 'extra' ] = 'data' ;
$_SERVER = array ();
$result = $dispatcher -> parseParams ( '/posts' );
$expected = array (
'pass' => array (), 'named' => array (), 'plugin' => null , 'controller' => 'posts' , 'action' => 'add' ,
'[method]' => 'POST' , 'form' => array ( 'extra' => 'data' ), 'data' => array ( 'Post' => array ( 'title' => 'New Post' )),
'url' => array ()
);
$this -> assertEqual ( $result , $expected );
2008-01-26 08:50:06 +00:00
unset ( $_POST [ '_method' ]);
}
2007-12-30 22:33:48 +00:00
function testEnvironmentDetection () {
$dispatcher =& new Dispatcher ();
$environments = array (
'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 ),
'reload' => true ,
'path' => ''
),
'No rewrite with path' => array (
'SERVER' => array ( 'QUERY_STRING' => '/posts/add' , 'REQUEST_URI' => '/index.php?/posts/add' , 'URL' => '/index.php?/posts/add' , 'argv' => array ( '/posts/add' ), 'argc' => 1 ),
'reload' => false ,
'path' => '/posts/add'
),
'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 ,
'path' => ''
),
'No rewrite sub dir 1 with path' => array (
'GET' => array ( '/posts/add' => '' ),
2008-01-15 07:37:29 +00:00
'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 ),
2007-12-30 22:33:48 +00:00
'reload' => false ,
'path' => '/posts/add'
),
'No rewrite sub dir 2' => array (
'App' => array ( 'base' => false , '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' , 'QUERY_STRING' => '' , 'REQUEST_URI' => '/site/index.php' , 'URL' => '/site/index.php' , 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\site\\index.php' , 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot' , 'PHP_SELF' => '/site/index.php' , 'argv' => array (), 'argc' => 0 ),
'reload' => false ,
'path' => ''
),
'No rewrite sub dir 2 with path' => array (
'GET' => array ( '/posts/add' => '' ),
2008-01-15 07:37:29 +00:00
'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' , 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\site\\index.php' , 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot' , 'PHP_SELF' => '/site/index.php' , 'argv' => array ( '/posts/add' ), 'argc' => 1 ),
2007-12-30 22:33:48 +00:00
'reload' => false ,
'path' => '/posts/add'
)
),
'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 ),
'reload' => true ,
'path' => ''
),
'No rewrite with path' => array (
2008-01-15 07:37:29 +00:00
'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 ),
2007-12-30 22:33:48 +00:00
'reload' => false ,
'path' => '/posts/add'
2008-02-06 17:22:39 +00:00
),
'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' ),
'GET' => array ( 'a' => 'b' ),
'POST' => array (),
'reload' => true ,
'path' => '' ,
'urlParams' => array ( 'a' => 'b' )
2007-12-30 22:33:48 +00:00
)
)
);
$backup = $this -> __backupEnvironment ();
foreach ( $environments as $name => $env ) {
foreach ( $env as $descrip => $settings ) {
if ( $settings [ 'reload' ]) {
$this -> __reloadEnvironment ();
}
$this -> __loadEnvironment ( $settings );
$this -> assertEqual ( $dispatcher -> uri (), $settings [ 'path' ], " %s on environment: { $name } , on setting: { $descrip } " );
2008-02-06 17:22:39 +00:00
if ( isset ( $setting [ 'urlParams' ])) {
$this -> assertEqual ( $_GET , $settings [ 'urlParams' ], " %s on environment: { $name } , on setting: { $descrip } " );
}
2007-12-30 22:33:48 +00:00
}
}
$this -> __loadEnvironment ( array_merge ( array ( 'reload' => true ), $backup ));
}
function __backupEnvironment () {
return array (
'App' => Configure :: read ( 'App' ),
'GET' => $_GET ,
'POST' => $_POST ,
'SERVER' => $_SERVER
);
}
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 ());
}
function __loadEnvironment ( $env ) {
if ( $env [ 'reload' ]) {
$this -> __reloadEnvironment ();
}
if ( isset ( $env [ 'App' ])) {
Configure :: write ( 'App' , $env [ 'App' ]);
}
if ( isset ( $env [ 'GET' ])) {
foreach ( $env [ 'GET' ] as $key => $val ) {
$_GET [ $key ] = $val ;
}
}
if ( isset ( $env [ 'POST' ])) {
foreach ( $env [ 'POST' ] as $key => $val ) {
$_POST [ $key ] = $val ;
}
}
if ( isset ( $env [ 'SERVER' ])) {
foreach ( $env [ 'SERVER' ] as $key => $val ) {
$_SERVER [ $key ] = $val ;
}
}
}
2007-07-25 04:38:28 +00:00
function tearDown () {
$_GET = $this -> _get ;
}
2007-02-03 22:20:13 +00:00
}
2007-10-28 04:18:18 +00:00
?>