7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
10 * Licensed under The Open Group Test Suite License
11 * Redistributions of files must retain the above copyright notice.
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
14 * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
16 * @subpackage cake.tests.cases
17 * @since CakePHP(tm) v 1.2.0.4206
18 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
20 require_once CAKE
. 'dispatcher.php';
22 if (!class_exists('AppController')) {
23 require_once LIBS
. 'controller' . DS
. 'app_controller.php';
24 } elseif (!defined('APP_CONTROLLER_EXISTS')){
25 define('APP_CONTROLLER_EXISTS', true);
29 * TestDispatcher class
32 * @subpackage cake.tests.cases
34 class TestDispatcher
extends Dispatcher
{
39 * @param mixed $controller
40 * @param mixed $params
41 * @param mixed $missingAction
45 function _invoke(&$controller, $params) {
46 restore_error_handler();
47 if ($result = parent
::_invoke($controller, $params)) {
48 if ($result[0] === 'missingAction') {
52 set_error_handler('simpleTestErrorHandler');
60 * @param mixed $filename
64 function cakeError($filename, $params) {
65 return array($filename, $params);
75 $this->stopped
= true;
81 * MyPluginAppController class
84 * @subpackage cake.tests.cases
86 class MyPluginAppController
extends AppController
{
90 * MyPluginController class
93 * @subpackage cake.tests.cases
95 class MyPluginController
extends MyPluginAppController
{
100 * @var string 'MyPlugin'
103 var $name = 'MyPlugin';
140 function admin_add($id = null) {
146 * SomePagesController class
149 * @subpackage cake.tests.cases
151 class SomePagesController
extends AppController
{
156 * @var string 'SomePages'
159 var $name = 'SomePages';
176 function display($page = null) {
196 function _protected() {
201 * redirect method overriding
206 function redirect() {
207 echo 'this should not be accessible';
212 * OtherPagesController class
215 * @subpackage cake.tests.cases
217 class OtherPagesController
extends MyPluginAppController
{
222 * @var string 'OtherPages'
225 var $name = 'OtherPages';
242 function display($page = null) {
258 * TestDispatchPagesController class
261 * @subpackage cake.tests.cases
263 class TestDispatchPagesController
extends AppController
{
268 * @var string 'TestDispatchPages'
271 var $name = 'TestDispatchPages';
287 function admin_index() {
297 function camelCased() {
303 * ArticlesTestAppController class
306 * @subpackage cake.tests.cases
308 class ArticlesTestAppController
extends AppController
{
312 * ArticlesTestController class
315 * @subpackage cake.tests.cases
317 class ArticlesTestController
extends ArticlesTestAppController
{
322 * @var string 'ArticlesTest'
325 var $name = 'ArticlesTest';
341 function admin_index() {
355 * SomePostsController class
358 * @subpackage cake.tests.cases
360 class SomePostsController
extends AppController
{
365 * @var string 'SomePosts'
368 var $name = 'SomePosts';
379 * autoRender property
384 var $autoRender = false;
387 * beforeFilter method
392 function beforeFilter() {
393 if ($this->params
['action'] == 'index') {
394 $this->params
['action'] = 'view';
396 $this->params
['action'] = 'change';
398 $this->params
['pass'] = array('changed');
423 * TestCachedPagesController class
426 * @subpackage cake.tests.cases
428 class TestCachedPagesController
extends AppController
{
433 * @var string 'TestCachedPages'
436 var $name = 'TestCachedPages';
452 var $helpers = array('Cache');
455 * cacheAction property
460 var $cacheAction = array(
462 'test_nocache_tags' => '+2 sec',
469 * @var string 'posts'
472 var $viewPath = 'posts';
485 * test_nocache_tags method
490 function test_nocache_tags() {
500 function view($id = null) {
501 $this->render('index');
504 * test cached forms / tests view object being registered
508 function cache_form() {
509 $this->cacheAction
= 10;
510 $this->helpers
[] = 'Form';
515 * TimesheetsController class
518 * @subpackage cake.tests.cases
520 class TimesheetsController
extends AppController
{
525 * @var string 'Timesheets'
528 var $name = 'Timesheets';
550 * DispatcherTest class
553 * @subpackage cake.tests.cases
555 class DispatcherTest
extends CakeTestCase
{
563 function startTest() {
566 $this->_post
= $_POST;
567 $this->_files
= $_FILES;
568 $this->_server
= $_SERVER;
570 $this->_app
= Configure
::read('App');
571 Configure
::write('App.base', false);
572 Configure
::write('App.baseUrl', false);
573 Configure
::write('App.dir', 'app');
574 Configure
::write('App.webroot', 'webroot');
576 $this->_cache
= Configure
::read('Cache');
577 Configure
::write('Cache.disable', true);
579 $this->_debug
= Configure
::read('debug');
581 App
::build(App
::core());
592 $_POST = $this->_post
;
593 $_FILES = $this->_files
;
594 $_SERVER = $this->_server
;
596 Configure
::write('App', $this->_app
);
597 Configure
::write('Cache', $this->_cache
);
598 Configure
::write('debug', $this->_debug
);
602 * testParseParamsWithoutZerosAndEmptyPost method
607 function testParseParamsWithoutZerosAndEmptyPost() {
608 $Dispatcher =& new Dispatcher();
609 $test = $Dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3");
610 $this->assertIdentical($test['controller'], 'testcontroller');
611 $this->assertIdentical($test['action'], 'testaction');
612 $this->assertIdentical($test['pass'][0], 'params1');
613 $this->assertIdentical($test['pass'][1], 'params2');
614 $this->assertIdentical($test['pass'][2], 'params3');
615 $this->assertFalse(!empty($test['form']));
619 * testParseParamsReturnsPostedData method
624 function testParseParamsReturnsPostedData() {
625 $_POST['testdata'] = "My Posted Content";
626 $Dispatcher =& new Dispatcher();
627 $test = $Dispatcher->parseParams("/");
628 $this->assertTrue($test['form'], "Parsed URL not returning post data");
629 $this->assertIdentical($test['form']['testdata'], "My Posted Content");
633 * testParseParamsWithSingleZero method
638 function testParseParamsWithSingleZero() {
639 $Dispatcher =& new Dispatcher();
640 $test = $Dispatcher->parseParams("/testcontroller/testaction/1/0/23");
641 $this->assertIdentical($test['controller'], 'testcontroller');
642 $this->assertIdentical($test['action'], 'testaction');
643 $this->assertIdentical($test['pass'][0], '1');
644 $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
645 $this->assertIdentical($test['pass'][2], '23');
649 * testParseParamsWithManySingleZeros method
654 function testParseParamsWithManySingleZeros() {
655 $Dispatcher =& new Dispatcher();
656 $test = $Dispatcher->parseParams("/testcontroller/testaction/0/0/0/0/0/0");
657 $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][0]);
658 $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
659 $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][2]);
660 $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][3]);
661 $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][4]);
662 $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][5]);
666 * testParseParamsWithManyZerosInEachSectionOfUrl method
671 function testParseParamsWithManyZerosInEachSectionOfUrl() {
672 $Dispatcher =& new Dispatcher();
673 $test = $Dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
674 $this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0]);
675 $this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1]);
676 $this->assertPattern('/\\A(?:00000)\\z/', $test['pass'][2]);
677 $this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][3]);
678 $this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][4]);
679 $this->assertPattern('/\\A(?:0000000)\\z/', $test['pass'][5]);
683 * testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl method
688 function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
689 $Dispatcher =& new Dispatcher();
690 $test = $Dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
691 $this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]);
692 $this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1]);
693 $this->assertPattern('/\\A(?:04010)\\z/', $test['pass'][2]);
694 $this->assertPattern('/\\A(?:000002)\\z/', $test['pass'][3]);
695 $this->assertPattern('/\\A(?:000030)\\z/', $test['pass'][4]);
696 $this->assertPattern('/\\A(?:0000400)\\z/', $test['pass'][5]);
700 * testQueryStringOnRoot method
705 function testQueryStringOnRoot() {
707 Router
::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
708 Router
::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
710 $_GET = array('coffee' => 'life', 'sleep' => 'sissies');
711 $Dispatcher =& new Dispatcher();
712 $uri = 'posts/home/?coffee=life&sleep=sissies';
713 $result = $Dispatcher->parseParams($uri);
714 $this->assertPattern('/posts/', $result['controller']);
715 $this->assertPattern('/home/', $result['action']);
716 $this->assertTrue(isset($result['url']['sleep']));
717 $this->assertTrue(isset($result['url']['coffee']));
719 $Dispatcher =& new Dispatcher();
720 $uri = '/?coffee=life&sleep=sissy';
721 $result = $Dispatcher->parseParams($uri);
722 $this->assertPattern('/pages/', $result['controller']);
723 $this->assertPattern('/display/', $result['action']);
724 $this->assertTrue(isset($result['url']['sleep']));
725 $this->assertTrue(isset($result['url']['coffee']));
726 $this->assertEqual($result['url']['coffee'], 'life');
730 * testFileUploadArrayStructure method
735 function testFileUploadArrayStructure() {
736 $_FILES = array('data' => array('name' => array(
738 array('data' => 'cake_mssql_patch.patch'),
739 array('data' => 'controller.diff'),
743 'Post' => array('attachment' => 'jquery-1.2.1.js'),
752 'Post' => array('attachment' => 'application/x-javascript'),
756 array('data' => '/private/var/tmp/phpy05Ywj'),
757 array('data' => '/private/var/tmp/php7MBztY'),
761 'Post' => array('attachment' => '/private/var/tmp/phpEwlrIo'),
770 'Post' => array('attachment' => 0)
774 array('data' => 6271),
775 array('data' => 350),
779 'Post' => array('attachment' => 80469)
783 $Dispatcher =& new Dispatcher();
784 $result = $Dispatcher->parseParams('/');
788 array('data' => array(
789 'name' => 'cake_mssql_patch.patch',
791 'tmp_name' => '/private/var/tmp/phpy05Ywj',
796 array('data' => array(
797 'name' => 'controller.diff',
799 'tmp_name' => '/private/var/tmp/php7MBztY',
803 array('data' => array(
810 array('data' => array(
818 'Post' => array('attachment' => array(
819 'name' => 'jquery-1.2.1.js',
820 'type' => 'application/x-javascript',
821 'tmp_name' => '/private/var/tmp/phpEwlrIo',
825 $this->assertEqual($result['data'], $expected);
832 'birth_cert' => 'born on.txt',
833 'passport' => 'passport.txt',
834 'drivers_license' => 'ugly pic.jpg'
837 'birth_cert' => 'aunt betty.txt',
838 'passport' => 'betty-passport.txt',
839 'drivers_license' => 'betty-photo.jpg'
846 'birth_cert' => 'application/octet-stream',
847 'passport' => 'application/octet-stream',
848 'drivers_license' => 'application/octet-stream',
851 'birth_cert' => 'application/octet-stream',
852 'passport' => 'application/octet-stream',
853 'drivers_license' => 'application/octet-stream',
860 'birth_cert' => '/private/var/tmp/phpbsUWfH',
861 'passport' => '/private/var/tmp/php7f5zLt',
862 'drivers_license' => '/private/var/tmp/phpMXpZgT',
865 'birth_cert' => '/private/var/tmp/php5kHZt0',
866 'passport' => '/private/var/tmp/phpnYkOuM',
867 'drivers_license' => '/private/var/tmp/php9Rq0P3',
876 'drivers_license' => 0,
881 'drivers_license' => 0,
890 'drivers_license' => 875,
895 'drivers_license' => 9783,
901 $Dispatcher =& new Dispatcher();
902 $result = $Dispatcher->parseParams('/');
906 'birth_cert' => array(
907 'name' => 'born on.txt',
908 'tmp_name' => '/private/var/tmp/phpbsUWfH',
911 'type' => 'application/octet-stream',
914 'name' => 'passport.txt',
915 'tmp_name' => '/private/var/tmp/php7f5zLt',
918 'type' => 'application/octet-stream',
920 'drivers_license' => array(
921 'name' => 'ugly pic.jpg',
922 'tmp_name' => '/private/var/tmp/phpMXpZgT',
925 'type' => 'application/octet-stream',
929 'birth_cert' => array(
930 'name' => 'aunt betty.txt',
931 'tmp_name' => '/private/var/tmp/php5kHZt0',
934 'type' => 'application/octet-stream',
937 'name' => 'betty-passport.txt',
938 'tmp_name' => '/private/var/tmp/phpnYkOuM',
941 'type' => 'application/octet-stream',
943 'drivers_license' => array(
944 'name' => 'betty-photo.jpg',
945 'tmp_name' => '/private/var/tmp/php9Rq0P3',
948 'type' => 'application/octet-stream',
953 $this->assertEqual($result['data'], $expected);
958 'name' => array('birth_cert' => 'born on.txt'),
959 'type' => array('birth_cert' => 'application/octet-stream'),
960 'tmp_name' => array('birth_cert' => '/private/var/tmp/phpbsUWfH'),
961 'error' => array('birth_cert' => 0),
962 'size' => array('birth_cert' => 123)
966 $Dispatcher =& new Dispatcher();
967 $result = $Dispatcher->parseParams('/');
970 'birth_cert' => array(
971 'name' => 'born on.txt',
972 'type' => 'application/octet-stream',
973 'tmp_name' => '/private/var/tmp/phpbsUWfH',
979 $this->assertEqual($result['data'], $expected);
988 function testGetUrl() {
989 $Dispatcher =& new Dispatcher();
990 $Dispatcher->base
= '/app/webroot/index.php';
991 $uri = '/app/webroot/index.php/posts/add';
992 $result = $Dispatcher->getUrl($uri);
993 $expected = 'posts/add';
994 $this->assertEqual($expected, $result);
996 Configure
::write('App.baseUrl', '/app/webroot/index.php');
999 $result = $Dispatcher->getUrl($uri);
1000 $expected = 'posts/add';
1001 $this->assertEqual($expected, $result);
1003 $_GET['url'] = array();
1004 Configure
::write('App.base', '/control');
1005 $Dispatcher =& new Dispatcher();
1006 $Dispatcher->baseUrl();
1007 $uri = '/control/students/browse';
1008 $result = $Dispatcher->getUrl($uri);
1009 $expected = 'students/browse';
1010 $this->assertEqual($expected, $result);
1012 $_GET['url'] = array();
1013 $Dispatcher =& new Dispatcher();
1014 $Dispatcher->base
= '';
1016 $result = $Dispatcher->getUrl($uri);
1017 $expected = '?/home';
1018 $this->assertEqual($expected, $result);
1020 $_GET['url'] = array();
1021 $Dispatcher =& new Dispatcher();
1022 $Dispatcher->base
= '/shop';
1023 $uri = '/shop/fr/pages/shop';
1024 $result = $Dispatcher->getUrl($uri);
1025 $expected = 'fr/pages/shop';
1026 $this->assertEqual($expected, $result);
1030 * testBaseUrlAndWebrootWithModRewrite method
1035 function testBaseUrlAndWebrootWithModRewrite() {
1036 $Dispatcher =& new Dispatcher();
1038 $Dispatcher->base
= false;
1039 $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
1040 $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
1041 $_SERVER['PHP_SELF'] = '/1.2.x.x/app/webroot/index.php';
1042 $result = $Dispatcher->baseUrl();
1043 $expected = '/1.2.x.x';
1044 $this->assertEqual($expected, $result);
1045 $expectedWebroot = '/1.2.x.x/';
1046 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1048 $Dispatcher->base
= false;
1049 $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/app/webroot';
1050 $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
1051 $_SERVER['PHP_SELF'] = '/index.php';
1052 $result = $Dispatcher->baseUrl();
1054 $this->assertEqual($expected, $result);
1055 $expectedWebroot = '/';
1056 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1058 $Dispatcher->base
= false;
1059 $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/test/';
1060 $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/test/webroot/index.php';
1061 $_SERVER['PHP_SELF'] = '/webroot/index.php';
1062 $result = $Dispatcher->baseUrl();
1064 $this->assertEqual($expected, $result);
1065 $expectedWebroot = '/';
1066 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1068 $Dispatcher->base
= false;
1069 $_SERVER['DOCUMENT_ROOT'] = '/some/apps/where';
1070 $_SERVER['SCRIPT_FILENAME'] = '/some/apps/where/app/webroot/index.php';
1071 $_SERVER['PHP_SELF'] = '/some/apps/where/app/webroot/index.php';
1072 $result = $Dispatcher->baseUrl();
1073 $expected = '/some/apps/where';
1074 $this->assertEqual($expected, $result);
1075 $expectedWebroot = '/some/apps/where/';
1076 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1079 Configure
::write('App.dir', 'auth');
1081 $Dispatcher->base
= false;
1082 $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
1083 $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/demos/auth/webroot/index.php';
1084 $_SERVER['PHP_SELF'] = '/demos/auth/webroot/index.php';
1086 $result = $Dispatcher->baseUrl();
1087 $expected = '/demos/auth';
1088 $this->assertEqual($expected, $result);
1089 $expectedWebroot = '/demos/auth/';
1090 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1092 Configure
::write('App.dir', 'code');
1094 $Dispatcher->base
= false;
1095 $_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents';
1096 $_SERVER['SCRIPT_FILENAME'] = '/Library/WebServer/Documents/clients/PewterReport/code/webroot/index.php';
1097 $_SERVER['PHP_SELF'] = '/clients/PewterReport/code/webroot/index.php';
1098 $result = $Dispatcher->baseUrl();
1099 $expected = '/clients/PewterReport/code';
1100 $this->assertEqual($expected, $result);
1101 $expectedWebroot = '/clients/PewterReport/code/';
1102 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1106 * testBaseUrlwithModRewriteAlias method
1111 function testBaseUrlwithModRewriteAlias() {
1112 $_SERVER['DOCUMENT_ROOT'] = '/home/aplusnur/public_html';
1113 $_SERVER['SCRIPT_FILENAME'] = '/home/aplusnur/cake2/app/webroot/index.php';
1114 $_SERVER['PHP_SELF'] = '/control/index.php';
1116 Configure
::write('App.base', '/control');
1118 $Dispatcher =& new Dispatcher();
1119 $result = $Dispatcher->baseUrl();
1120 $expected = '/control';
1121 $this->assertEqual($expected, $result);
1122 $expectedWebroot = '/control/';
1123 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1125 Configure
::write('App.base', false);
1126 Configure
::write('App.dir', 'affiliate');
1127 Configure
::write('App.webroot', 'newaffiliate');
1129 $_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html';
1130 $_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php';
1131 $_SERVER['PHP_SELF'] = '/newaffiliate/index.php';
1132 $Dispatcher =& new Dispatcher();
1133 $result = $Dispatcher->baseUrl();
1134 $expected = '/newaffiliate';
1135 $this->assertEqual($expected, $result);
1136 $expectedWebroot = '/newaffiliate/';
1137 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1141 * testBaseUrlAndWebrootWithBaseUrl method
1146 function testBaseUrlAndWebrootWithBaseUrl() {
1147 $Dispatcher =& new Dispatcher();
1149 Configure
::write('App.dir', 'app');
1151 Configure
::write('App.baseUrl', '/app/webroot/index.php');
1152 $result = $Dispatcher->baseUrl();
1153 $expected = '/app/webroot/index.php';
1154 $this->assertEqual($expected, $result);
1155 $expectedWebroot = '/app/webroot/';
1156 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1158 Configure
::write('App.baseUrl', '/app/webroot/test.php');
1159 $result = $Dispatcher->baseUrl();
1160 $expected = '/app/webroot/test.php';
1161 $this->assertEqual($expected, $result);
1162 $expectedWebroot = '/app/webroot/';
1163 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1165 Configure
::write('App.baseUrl', '/app/index.php');
1166 $result = $Dispatcher->baseUrl();
1167 $expected = '/app/index.php';
1168 $this->assertEqual($expected, $result);
1169 $expectedWebroot = '/app/webroot/';
1170 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1172 Configure
::write('App.baseUrl', '/index.php');
1173 $result = $Dispatcher->baseUrl();
1174 $expected = '/index.php';
1175 $this->assertEqual($expected, $result);
1176 $expectedWebroot = '/app/webroot/';
1177 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1179 Configure
::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
1180 $result = $Dispatcher->baseUrl();
1181 $expected = '/CakeBB/app/webroot/index.php';
1182 $this->assertEqual($expected, $result);
1183 $expectedWebroot = '/CakeBB/app/webroot/';
1184 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1186 Configure
::write('App.baseUrl', '/CakeBB/app/index.php');
1187 $result = $Dispatcher->baseUrl();
1188 $expected = '/CakeBB/app/index.php';
1189 $this->assertEqual($expected, $result);
1190 $expectedWebroot = '/CakeBB/app/webroot/';
1191 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1193 Configure
::write('App.baseUrl', '/CakeBB/index.php');
1194 $result = $Dispatcher->baseUrl();
1195 $expected = '/CakeBB/index.php';
1196 $this->assertEqual($expected, $result);
1197 $expectedWebroot = '/CakeBB/app/webroot/';
1198 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1200 Configure
::write('App.baseUrl', '/dbhauser/index.php');
1201 $_SERVER['DOCUMENT_ROOT'] = '/kunden/homepages/4/d181710652/htdocs/joomla';
1202 $_SERVER['SCRIPT_FILENAME'] = '/kunden/homepages/4/d181710652/htdocs/joomla/dbhauser/index.php';
1203 $result = $Dispatcher->baseUrl();
1204 $expected = '/dbhauser/index.php';
1205 $this->assertEqual($expected, $result);
1206 $expectedWebroot = '/dbhauser/app/webroot/';
1207 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1211 * test baseUrl with no rewrite and using the top level index.php.
1215 function testBaseUrlNoRewriteTopLevelIndex() {
1216 $Dispatcher =& new Dispatcher();
1218 Configure
::write('App.baseUrl', '/index.php');
1219 $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev';
1220 $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/index.php';
1222 $result = $Dispatcher->baseUrl();
1223 $this->assertEqual('/index.php', $result);
1224 $this->assertEqual('/app/webroot/', $Dispatcher->webroot
);
1225 $this->assertEqual('', $Dispatcher->base
);
1229 * test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts.
1233 function testBaseUrlNoRewriteWebrootIndex() {
1234 $Dispatcher =& new Dispatcher();
1236 Configure
::write('App.baseUrl', '/index.php');
1237 $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev/app/webroot';
1238 $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/app/webroot/index.php';
1240 $result = $Dispatcher->baseUrl();
1241 $this->assertEqual('/index.php', $result);
1242 $this->assertEqual('/', $Dispatcher->webroot
);
1243 $this->assertEqual('', $Dispatcher->base
);
1247 * testBaseUrlAndWebrootWithBase method
1252 function testBaseUrlAndWebrootWithBase() {
1253 $Dispatcher =& new Dispatcher();
1254 $Dispatcher->base
= '/app';
1255 $result = $Dispatcher->baseUrl();
1257 $this->assertEqual($expected, $result);
1258 $expectedWebroot = '/app/';
1259 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1261 $Dispatcher->base
= '';
1262 $result = $Dispatcher->baseUrl();
1264 $this->assertEqual($expected, $result);
1265 $expectedWebroot = '/';
1266 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1268 Configure
::write('App.dir', 'testbed');
1269 $Dispatcher->base
= '/cake/testbed/webroot';
1270 $result = $Dispatcher->baseUrl();
1271 $expected = '/cake/testbed/webroot';
1272 $this->assertEqual($expected, $result);
1273 $expectedWebroot = '/cake/testbed/webroot/';
1274 $this->assertEqual($expectedWebroot, $Dispatcher->webroot
);
1278 * testMissingController method
1283 function testMissingController() {
1284 $Dispatcher =& new TestDispatcher();
1285 Configure
::write('App.baseUrl', '/index.php');
1286 $url = 'some_controller/home/param:value/param2:value2';
1287 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1288 $expected = array('missingController', array(array(
1289 'className' => 'SomeControllerController',
1290 'webroot' => '/app/webroot/',
1291 'url' => 'some_controller/home/param:value/param2:value2',
1292 'base' => '/index.php'
1294 $this->assertEqual($expected, $controller);
1298 * testPrivate method
1303 function testPrivate() {
1304 $Dispatcher =& new TestDispatcher();
1305 Configure
::write('App.baseUrl','/index.php');
1306 $url = 'some_pages/_protected/param:value/param2:value2';
1308 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1310 $expected = array('privateAction', array(array(
1311 'className' => 'SomePagesController',
1312 'action' => '_protected',
1313 'webroot' => '/app/webroot/',
1314 'url' => 'some_pages/_protected/param:value/param2:value2',
1315 'base' => '/index.php'
1317 $this->assertEqual($controller, $expected);
1321 * testMissingAction method
1326 function testMissingAction() {
1327 $Dispatcher =& new TestDispatcher();
1328 Configure
::write('App.baseUrl', '/index.php');
1329 $url = 'some_pages/home/param:value/param2:value2';
1331 $controller = $Dispatcher->dispatch($url, array('return'=> 1));
1333 $expected = array('missingAction', array(array(
1334 'className' => 'SomePagesController',
1336 'webroot' => '/app/webroot/',
1337 'url' => '/index.php/some_pages/home/param:value/param2:value2',
1338 'base' => '/index.php'
1340 $this->assertEqual($expected, $controller);
1342 $Dispatcher =& new TestDispatcher();
1343 Configure
::write('App.baseUrl','/index.php');
1344 $url = 'some_pages/redirect/param:value/param2:value2';
1346 $controller = $Dispatcher->dispatch($url, array('return'=> 1));
1348 $expected = array('missingAction', array(array(
1349 'className' => 'SomePagesController',
1350 'action' => 'redirect',
1351 'webroot' => '/app/webroot/',
1352 'url' => '/index.php/some_pages/redirect/param:value/param2:value2',
1353 'base' => '/index.php'
1355 $this->assertEqual($expected, $controller);
1359 * testDispatch method
1364 function testDispatch() {
1365 $Dispatcher =& new TestDispatcher();
1366 Configure
::write('App.baseUrl','/index.php');
1367 $url = 'pages/home/param:value/param2:value2';
1369 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1370 $expected = 'Pages';
1371 $this->assertEqual($expected, $controller->name
);
1373 $expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
1374 $this->assertIdentical($expected, $controller->passedArgs
);
1376 Configure
::write('App.baseUrl','/pages/index.php');
1378 $url = 'pages/home';
1379 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1381 $expected = 'Pages';
1382 $this->assertEqual($expected, $controller->name
);
1384 $url = 'pages/home/';
1385 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1386 $this->assertNull($controller->plugin
);
1387 $this->assertNull($Dispatcher->params
['plugin']);
1389 $expected = 'Pages';
1390 $this->assertEqual($expected, $controller->name
);
1394 $Dispatcher =& new TestDispatcher();
1395 Configure
::write('App.baseUrl','/timesheets/index.php');
1397 $url = 'timesheets';
1398 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1400 $expected = 'Timesheets';
1401 $this->assertEqual($expected, $controller->name
);
1403 $url = 'timesheets/';
1404 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1406 $this->assertEqual('Timesheets', $controller->name
);
1407 $this->assertEqual('/timesheets/index.php', $Dispatcher->base
);
1410 $url = 'test_dispatch_pages/camelCased';
1411 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1412 $this->assertEqual('TestDispatchPages', $controller->name
);
1414 $url = 'test_dispatch_pages/camelCased/something. .';
1415 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1416 $this->assertEqual($controller->params
['pass'][0], 'something. .', 'Period was chopped off. %s');
1421 * testDispatchWithArray method
1426 function testDispatchWithArray() {
1427 $Dispatcher =& new TestDispatcher();
1428 $url = 'pages/home/param:value/param2:value2';
1430 $url = array('controller' => 'pages', 'action' => 'display');
1431 $controller = $Dispatcher->dispatch($url, array(
1432 'pass' => array('home'),
1433 'named' => array('param' => 'value', 'param2' => 'value2'),
1436 $expected = 'Pages';
1437 $this->assertEqual($expected, $controller->name
);
1439 $expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
1440 $this->assertIdentical($expected, $controller->passedArgs
);
1442 $this->assertEqual($Dispatcher->base
. '/pages/display/home/param:value/param2:value2', $Dispatcher->here
);
1446 * test that a garbage url doesn't cause errors.
1450 function testDispatchWithGarbageUrl() {
1451 Configure
::write('App.baseUrl', '/index.php');
1453 $Dispatcher =& new TestDispatcher();
1454 $url = 'http://google.com';
1455 $result = $Dispatcher->dispatch($url);
1456 $expected = array('missingController', array(array(
1457 'className' => 'Controller',
1458 'webroot' => '/app/webroot/',
1459 'url' => 'http://google.com',
1460 'base' => '/index.php'
1462 $this->assertEqual($expected, $result);
1466 * testAdminDispatch method
1471 function testAdminDispatch() {
1473 $Dispatcher =& new TestDispatcher();
1474 Configure
::write('Routing.prefixes', array('admin'));
1475 Configure
::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php');
1476 $url = 'admin/test_dispatch_pages/index/param:value/param2:value2';
1479 $Router =& Router
::getInstance();
1480 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1482 $this->assertEqual($controller->name
, 'TestDispatchPages');
1484 $this->assertIdentical($controller->passedArgs
, array('param' => 'value', 'param2' => 'value2'));
1485 $this->assertTrue($controller->params
['admin']);
1487 $expected = '/cake/repo/branches/1.2.x.x/index.php/admin/test_dispatch_pages/index/param:value/param2:value2';
1488 $this->assertIdentical($expected, $controller->here
);
1490 $expected = '/cake/repo/branches/1.2.x.x/index.php';
1491 $this->assertIdentical($expected, $controller->base
);
1495 * testPluginDispatch method
1500 function testPluginDispatch() {
1502 $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
1505 $Dispatcher =& new TestDispatcher();
1507 '/my_plugin/:controller/*',
1508 array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
1511 $Dispatcher->base
= false;
1512 $url = 'my_plugin/some_pages/home/param:value/param2:value2';
1513 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1515 $result = $Dispatcher->parseParams($url);
1517 'pass' => array('home'),
1518 'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
1519 'controller'=> 'some_pages', 'action'=> 'display', 'form'=> null,
1520 'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'),
1525 $this->assertEqual($expected, $result);
1527 $this->assertIdentical($controller->plugin
, 'my_plugin');
1528 $this->assertIdentical($controller->name
, 'SomePages');
1529 $this->assertIdentical($controller->params
['controller'], 'some_pages');
1530 $this->assertIdentical($controller->passedArgs
, array('0' => 'home', 'param'=>'value', 'param2'=>'value2'));
1532 $expected = '/cake/repo/branches/1.2.x.x/my_plugin/some_pages/home/param:value/param2:value2';
1533 $this->assertIdentical($expected, $controller->here
);
1535 $expected = '/cake/repo/branches/1.2.x.x';
1536 $this->assertIdentical($expected, $controller->base
);
1540 * testAutomaticPluginDispatch method
1545 function testAutomaticPluginDispatch() {
1547 $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
1550 $Dispatcher =& new TestDispatcher();
1552 '/my_plugin/:controller/:action/*',
1553 array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
1556 $Dispatcher->base
= false;
1558 $url = 'my_plugin/other_pages/index/param:value/param2:value2';
1559 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1561 $this->assertIdentical($controller->plugin
, 'my_plugin');
1562 $this->assertIdentical($controller->name
, 'OtherPages');
1563 $this->assertIdentical($controller->action
, 'index');
1564 $this->assertIdentical($controller->passedArgs
, array('param' => 'value', 'param2' => 'value2'));
1566 $expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2';
1567 $this->assertIdentical($expected, $controller->here
);
1569 $expected = '/cake/repo/branches/1.2.x.x';
1570 $this->assertIdentical($expected, $controller->base
);
1574 * testAutomaticPluginControllerDispatch method
1579 function testAutomaticPluginControllerDispatch() {
1581 $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
1583 $plugins = App
::objects('plugin');
1584 $plugins[] = 'MyPlugin';
1585 $plugins[] = 'ArticlesTest';
1587 $app = App
::getInstance();
1588 $app->__objects
['plugin'] = $plugins;
1591 $Dispatcher =& new TestDispatcher();
1592 $Dispatcher->base
= false;
1594 $url = 'my_plugin/my_plugin/add/param:value/param2:value2';
1596 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1598 $this->assertIdentical($controller->plugin
, 'my_plugin');
1599 $this->assertIdentical($controller->name
, 'MyPlugin');
1600 $this->assertIdentical($controller->action
, 'add');
1601 $this->assertEqual($controller->params
['named'], array('param' => 'value', 'param2' => 'value2'));
1605 $Dispatcher =& new TestDispatcher();
1606 $Dispatcher->base
= false;
1608 // Simulates the Route for a real plugin, installed in APP/plugins
1609 Router
::connect('/my_plugin/:controller/:action/*', array('plugin' => 'my_plugin'));
1611 $plugin = 'MyPlugin';
1612 $pluginUrl = Inflector
::underscore($plugin);
1615 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1616 $this->assertIdentical($controller->plugin
, 'my_plugin');
1617 $this->assertIdentical($controller->name
, 'MyPlugin');
1618 $this->assertIdentical($controller->action
, 'index');
1620 $expected = $pluginUrl;
1621 $this->assertEqual($controller->params
['controller'], $expected);
1624 Configure
::write('Routing.prefixes', array('admin'));
1627 $Dispatcher =& new TestDispatcher();
1628 $Dispatcher->base
= false;
1630 $url = 'admin/my_plugin/my_plugin/add/5/param:value/param2:value2';
1631 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1633 $this->assertEqual($controller->params
['plugin'], 'my_plugin');
1634 $this->assertEqual($controller->params
['controller'], 'my_plugin');
1635 $this->assertEqual($controller->params
['action'], 'admin_add');
1636 $this->assertEqual($controller->params
['pass'], array(5));
1637 $this->assertEqual($controller->params
['named'], array('param' => 'value', 'param2' => 'value2'));
1638 $this->assertIdentical($controller->plugin
, 'my_plugin');
1639 $this->assertIdentical($controller->name
, 'MyPlugin');
1640 $this->assertIdentical($controller->action
, 'admin_add');
1642 $expected = array(0 => 5, 'param'=>'value', 'param2'=>'value2');
1643 $this->assertEqual($controller->passedArgs
, $expected);
1645 Configure
::write('Routing.prefixes', array('admin'));
1648 $Dispatcher =& new TestDispatcher();
1649 $Dispatcher->base
= false;
1651 $controller = $Dispatcher->dispatch('admin/articles_test', array('return' => 1));
1652 $this->assertIdentical($controller->plugin
, 'articles_test');
1653 $this->assertIdentical($controller->name
, 'ArticlesTest');
1654 $this->assertIdentical($controller->action
, 'admin_index');
1659 'controller' => 'articles_test',
1660 'plugin' => 'articles_test',
1661 'action' => 'admin_index',
1662 'prefix' => 'admin',
1665 'url' => array('url' => 'admin/articles_test'),
1668 $this->assertEqual($controller->params
, $expected);
1672 * test Plugin dispatching without controller name and using
1673 * plugin short form instead.
1678 function testAutomaticPluginDispatchWithShortAccess() {
1680 $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
1681 $plugins = App
::objects('plugin');
1682 $plugins[] = 'MyPlugin';
1684 $app = App
::getInstance();
1685 $app->__objects
['plugin'] = $plugins;
1689 $Dispatcher =& new TestDispatcher();
1690 $Dispatcher->base
= false;
1692 $url = 'my_plugin/';
1693 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1694 $this->assertEqual($controller->params
['controller'], 'my_plugin');
1695 $this->assertEqual($controller->params
['plugin'], 'my_plugin');
1696 $this->assertEqual($controller->params
['action'], 'index');
1697 $this->assertFalse(isset($controller->params
['pass'][0]));
1701 * test plugin shortcut urls with controllers that need to be loaded,
1702 * the above test uses a controller that has already been included.
1706 function testPluginShortCutUrlsWithControllerThatNeedsToBeLoaded() {
1707 $loaded = class_exists('TestPluginController', false);
1708 if ($this->skipIf($loaded, 'TestPluginController already loaded, this test will always pass, skipping %s')) {
1713 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'plugins' . DS
)
1715 App
::objects('plugin', null, false);
1717 $Dispatcher =& new TestDispatcher();
1718 $Dispatcher->base
= false;
1720 $url = 'test_plugin/';
1721 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1722 $this->assertEqual($controller->params
['controller'], 'test_plugin');
1723 $this->assertEqual($controller->params
['plugin'], 'test_plugin');
1724 $this->assertEqual($controller->params
['action'], 'index');
1725 $this->assertFalse(isset($controller->params
['pass'][0]));
1727 $url = '/test_plugin/tests/index';
1728 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1729 $this->assertEqual($controller->params
['controller'], 'tests');
1730 $this->assertEqual($controller->params
['plugin'], 'test_plugin');
1731 $this->assertEqual($controller->params
['action'], 'index');
1732 $this->assertFalse(isset($controller->params
['pass'][0]));
1734 $url = '/test_plugin/tests/index/some_param';
1735 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1736 $this->assertEqual($controller->params
['controller'], 'tests');
1737 $this->assertEqual($controller->params
['plugin'], 'test_plugin');
1738 $this->assertEqual($controller->params
['action'], 'index');
1739 $this->assertEqual($controller->params
['pass'][0], 'some_param');
1745 * testAutomaticPluginControllerMissingActionDispatch method
1750 function testAutomaticPluginControllerMissingActionDispatch() {
1752 $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
1755 $Dispatcher =& new TestDispatcher();
1756 $Dispatcher->base
= false;
1758 $url = 'my_plugin/not_here/param:value/param2:value2';
1759 $controller = $Dispatcher->dispatch($url, array('return'=> 1));
1761 $expected = array('missingAction', array(array(
1762 'className' => 'MyPluginController',
1763 'action' => 'not_here',
1764 'webroot' => '/cake/repo/branches/1.2.x.x/',
1765 'url' => '/cake/repo/branches/1.2.x.x/my_plugin/not_here/param:value/param2:value2',
1766 'base' => '/cake/repo/branches/1.2.x.x'
1768 $this->assertIdentical($expected, $controller);
1771 $Dispatcher =& new TestDispatcher();
1772 $Dispatcher->base
= false;
1774 $url = 'my_plugin/param:value/param2:value2';
1775 $controller = $Dispatcher->dispatch($url, array('return'=> 1));
1777 $expected = array('missingAction', array(array(
1778 'className' => 'MyPluginController',
1779 'action' => 'param:value',
1780 'webroot' => '/cake/repo/branches/1.2.x.x/',
1781 'url' => '/cake/repo/branches/1.2.x.x/my_plugin/param:value/param2:value2',
1782 'base' => '/cake/repo/branches/1.2.x.x'
1784 $this->assertIdentical($expected, $controller);
1788 * testPrefixProtection method
1793 function testPrefixProtection() {
1795 $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
1798 Router
::connect('/admin/:controller/:action/*', array('prefix'=>'admin'), array('controller', 'action'));
1800 $Dispatcher =& new TestDispatcher();
1801 $Dispatcher->base
= false;
1803 $url = 'test_dispatch_pages/admin_index/param:value/param2:value2';
1804 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1806 $expected = array('privateAction', array(array(
1807 'className' => 'TestDispatchPagesController',
1808 'action' => 'admin_index',
1809 'webroot' => '/cake/repo/branches/1.2.x.x/',
1810 'url' => 'test_dispatch_pages/admin_index/param:value/param2:value2',
1811 'base' => '/cake/repo/branches/1.2.x.x'
1813 $this->assertIdentical($expected, $controller);
1817 * Test dispatching into the TestPlugin in the test_app
1822 function testTestPluginDispatch() {
1823 $Dispatcher =& new TestDispatcher();
1825 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'plugins' . DS
)
1827 App
::objects('plugin', null, false);
1831 $url = '/test_plugin/tests/index';
1832 $result = $Dispatcher->dispatch($url, array('return' => 1));
1833 $this->assertTrue(class_exists('TestsController'));
1834 $this->assertTrue(class_exists('TestPluginAppController'));
1835 $this->assertTrue(class_exists('OtherComponentComponent'));
1836 $this->assertTrue(class_exists('PluginsComponentComponent'));
1838 $this->assertEqual($result->params
['controller'], 'tests');
1839 $this->assertEqual($result->params
['plugin'], 'test_plugin');
1840 $this->assertEqual($result->params
['action'], 'index');
1846 * testChangingParamsFromBeforeFilter method
1851 function testChangingParamsFromBeforeFilter() {
1852 $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
1853 $Dispatcher =& new TestDispatcher();
1854 $url = 'some_posts/index/param:value/param2:value2';
1855 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1857 $expected = array('missingAction', array(array(
1858 'className' => 'SomePostsController',
1860 'webroot' => '/cake/repo/branches/1.2.x.x/',
1861 'url' => '/cake/repo/branches/1.2.x.x/some_posts/index/param:value/param2:value2',
1862 'base' => '/cake/repo/branches/1.2.x.x'
1864 $this->assertEqual($expected, $controller);
1866 $url = 'some_posts/something_else/param:value/param2:value2';
1867 $controller = $Dispatcher->dispatch($url, array('return' => 1));
1869 $expected = 'SomePosts';
1870 $this->assertEqual($expected, $controller->name
);
1872 $expected = 'change';
1873 $this->assertEqual($expected, $controller->action
);
1875 $expected = array('changed');
1876 $this->assertIdentical($expected, $controller->params
['pass']);
1880 * testStaticAssets method
1885 function testAssets() {
1887 $Configure =& Configure
::getInstance();
1888 $Configure->__objects
= null;
1891 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'plugins' . DS
),
1892 'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'vendors'. DS
),
1893 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'views'. DS
)
1896 $Dispatcher =& new TestDispatcher();
1897 $debug = Configure
::read('debug');
1898 Configure
::write('debug', 0);
1901 $Dispatcher->dispatch('theme/test_theme/../webroot/css/test_asset.css');
1902 $result = ob_get_clean();
1903 $this->assertFalse($result);
1906 $Dispatcher->dispatch('theme/test_theme/pdfs');
1907 $result = ob_get_clean();
1908 $this->assertFalse($result);
1911 $Dispatcher->dispatch('theme/test_theme/flash/theme_test.swf');
1912 $result = ob_get_clean();
1913 $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'views' . DS
. 'themed' . DS
. 'test_theme' . DS
. 'webroot' . DS
. 'flash' . DS
. 'theme_test.swf');
1914 $this->assertEqual($file, $result);
1915 $this->assertEqual('this is just a test to load swf file from the theme.', $result);
1918 $Dispatcher->dispatch('theme/test_theme/pdfs/theme_test.pdf');
1919 $result = ob_get_clean();
1920 $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'views' . DS
. 'themed' . DS
. 'test_theme' . DS
. 'webroot' . DS
. 'pdfs' . DS
. 'theme_test.pdf');
1921 $this->assertEqual($file, $result);
1922 $this->assertEqual('this is just a test to load pdf file from the theme.', $result);
1925 $Dispatcher->dispatch('theme/test_theme/img/test.jpg');
1926 $result = ob_get_clean();
1927 $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'views' . DS
. 'themed' . DS
. 'test_theme' . DS
. 'webroot' . DS
. 'img' . DS
. 'test.jpg');
1928 $this->assertEqual($file, $result);
1930 $Dispatcher->params
= $Dispatcher->parseParams('theme/test_theme/css/test_asset.css');
1932 $Dispatcher->asset('theme/test_theme/css/test_asset.css');
1933 $result = ob_get_clean();
1934 $this->assertEqual('this is the test asset css file', $result);
1936 $Dispatcher->params
= $Dispatcher->parseParams('theme/test_theme/js/theme.js');
1938 $Dispatcher->asset('theme/test_theme/js/theme.js');
1939 $result = ob_get_clean();
1940 $this->assertEqual('root theme js file', $result);
1942 $Dispatcher->params
= $Dispatcher->parseParams('theme/test_theme/js/one/theme_one.js');
1944 $Dispatcher->asset('theme/test_theme/js/one/theme_one.js');
1945 $result = ob_get_clean();
1946 $this->assertEqual('nested theme js file', $result);
1949 $Dispatcher->asset('test_plugin/root.js');
1950 $result = ob_get_clean();
1951 $expected = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'plugins' . DS
. 'test_plugin' . DS
. 'webroot' . DS
. 'root.js');
1952 $this->assertEqual($result, $expected);
1955 $Dispatcher->dispatch('test_plugin/flash/plugin_test.swf');
1956 $result = ob_get_clean();
1957 $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'plugins' . DS
. 'test_plugin' . DS
. 'webroot' . DS
. 'flash' . DS
. 'plugin_test.swf');
1958 $this->assertEqual($file, $result);
1959 $this->assertEqual('this is just a test to load swf file from the plugin.', $result);
1962 $Dispatcher->dispatch('test_plugin/pdfs/plugin_test.pdf');
1963 $result = ob_get_clean();
1964 $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'plugins' . DS
. 'test_plugin' . DS
. 'webroot' . DS
. 'pdfs' . DS
. 'plugin_test.pdf');
1965 $this->assertEqual($file, $result);
1966 $this->assertEqual('this is just a test to load pdf file from the plugin.', $result);
1969 $Dispatcher->asset('test_plugin/js/test_plugin/test.js');
1970 $result = ob_get_clean();
1971 $this->assertEqual('alert("Test App");', $result);
1973 $Dispatcher->params
= $Dispatcher->parseParams('test_plugin/js/test_plugin/test.js');
1975 $Dispatcher->asset('test_plugin/js/test_plugin/test.js');
1976 $result = ob_get_clean();
1977 $this->assertEqual('alert("Test App");', $result);
1979 $Dispatcher->params
= $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css');
1981 $Dispatcher->asset('test_plugin/css/test_plugin_asset.css');
1982 $result = ob_get_clean();
1983 $this->assertEqual('this is the test plugin asset css file', $result);
1985 $Dispatcher->params
= $Dispatcher->parseParams('test_plugin/img/cake.icon.gif');
1987 $Dispatcher->asset('test_plugin/img/cake.icon.gif');
1988 $result = ob_get_clean();
1989 $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'plugins' . DS
. 'test_plugin' .DS
. 'webroot' . DS
. 'img' . DS
. 'cake.icon.gif');
1990 $this->assertEqual($file, $result);
1992 $Dispatcher->params
= $Dispatcher->parseParams('plugin_js/js/plugin_js.js');
1994 $Dispatcher->asset('plugin_js/js/plugin_js.js');
1995 $result = ob_get_clean();
1996 $expected = "alert('win sauce');";
1997 $this->assertEqual($result, $expected);
1999 $Dispatcher->params
= $Dispatcher->parseParams('plugin_js/js/one/plugin_one.js');
2001 $Dispatcher->asset('plugin_js/js/one/plugin_one.js');
2002 $result = ob_get_clean();
2003 $expected = "alert('plugin one nested js file');";
2004 $this->assertEqual($result, $expected);
2005 Configure
::write('debug', $debug);
2006 //reset the header content-type without page can render as plain text.
2007 header('Content-type: text/html');
2009 $Dispatcher->params
= $Dispatcher->parseParams('test_plugin/css/theme_one.htc');
2011 $Dispatcher->asset('test_plugin/css/unknown.extension');
2012 $result = ob_get_clean();
2013 $this->assertEqual('Testing a file with unknown extension to mime mapping.', $result);
2014 header('Content-type: text/html');
2016 $Dispatcher->params
= $Dispatcher->parseParams('test_plugin/css/theme_one.htc');
2018 $Dispatcher->asset('test_plugin/css/theme_one.htc');
2019 $result = ob_get_clean();
2020 $this->assertEqual('htc file', $result);
2021 header('Content-type: text/html');
2025 * test that missing asset processors trigger a 404 with no response body.
2029 function testMissingAssetProcessor404() {
2030 $Dispatcher =& new TestDispatcher();
2031 Configure
::write('Asset.filter', array(
2035 $this->assertNoErrors();
2038 $Dispatcher->asset('ccss/cake.generic.css');
2039 $result = ob_get_clean();
2040 $this->assertTrue($Dispatcher->stopped
);
2042 header('HTTP/1.1 200 Ok');
2046 * test that asset filters work for theme and plugin assets
2050 function testAssetFilterForThemeAndPlugins() {
2051 $Dispatcher =& new TestDispatcher();
2052 Configure
::write('Asset.filter', array(
2056 $Dispatcher->asset('theme/test_theme/ccss/cake.generic.css');
2057 $this->assertTrue($Dispatcher->stopped
);
2059 $Dispatcher->stopped
= false;
2060 $Dispatcher->asset('theme/test_theme/cjs/debug_kit.js');
2061 $this->assertTrue($Dispatcher->stopped
);
2063 $Dispatcher->stopped
= false;
2064 $Dispatcher->asset('test_plugin/ccss/cake.generic.css');
2065 $this->assertTrue($Dispatcher->stopped
);
2067 $Dispatcher->stopped
= false;
2068 $Dispatcher->asset('test_plugin/cjs/debug_kit.js');
2069 $this->assertTrue($Dispatcher->stopped
);
2071 $Dispatcher->stopped
= false;
2072 $Dispatcher->asset('css/ccss/debug_kit.css');
2073 $this->assertFalse($Dispatcher->stopped
);
2075 $Dispatcher->stopped
= false;
2076 $Dispatcher->asset('js/cjs/debug_kit.js');
2077 $this->assertFalse($Dispatcher->stopped
);
2080 * testFullPageCachingDispatch method
2085 function testFullPageCachingDispatch() {
2086 Configure
::write('Cache.disable', false);
2087 Configure
::write('Cache.check', true);
2088 Configure
::write('debug', 2);
2091 $_SERVER['PHP_SELF'] = '/';
2094 Router
::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index'));
2097 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'views' . DS
),
2100 $dispatcher =& new TestDispatcher();
2101 $dispatcher->base
= false;
2106 $dispatcher->dispatch($url);
2107 $out = ob_get_clean();
2110 $dispatcher->cached($url);
2111 $cached = ob_get_clean();
2113 $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
2114 $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
2115 $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
2117 $this->assertEqual($result, $expected);
2119 $filename = $this->__cachePath($dispatcher->here
);
2122 $dispatcher->base
= false;
2123 $url = 'test_cached_pages/index';
2126 $dispatcher->dispatch($url);
2127 $out = ob_get_clean();
2130 $dispatcher->cached($url);
2131 $cached = ob_get_clean();
2133 $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
2134 $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
2135 $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
2137 $this->assertEqual($result, $expected);
2138 $filename = $this->__cachePath($dispatcher->here
);
2141 $url = 'TestCachedPages/index';
2144 $dispatcher->dispatch($url);
2145 $out = ob_get_clean();
2148 $dispatcher->cached($url);
2149 $cached = ob_get_clean();
2151 $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
2152 $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
2153 $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
2155 $this->assertEqual($result, $expected);
2156 $filename = $this->__cachePath($dispatcher->here
);
2159 $url = 'TestCachedPages/test_nocache_tags';
2162 $dispatcher->dispatch($url);
2163 $out = ob_get_clean();
2166 $dispatcher->cached($url);
2167 $cached = ob_get_clean();
2169 $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
2170 $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
2171 $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
2173 $this->assertEqual($result, $expected);
2174 $filename = $this->__cachePath($dispatcher->here
);
2177 $url = 'test_cached_pages/view/param/param';
2180 $dispatcher->dispatch($url);
2181 $out = ob_get_clean();
2184 $dispatcher->cached($url);
2185 $cached = ob_get_clean();
2187 $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
2188 $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
2189 $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
2191 $this->assertEqual($result, $expected);
2192 $filename = $this->__cachePath($dispatcher->here
);
2195 $url = 'test_cached_pages/view/foo:bar/value:goo';
2198 $dispatcher->dispatch($url);
2199 $out = ob_get_clean();
2202 $dispatcher->cached($url);
2203 $cached = ob_get_clean();
2205 $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
2206 $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
2207 $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
2209 $this->assertEqual($result, $expected);
2210 $filename = $this->__cachePath($dispatcher->here
);
2211 $this->assertTrue(file_exists($filename));
2216 * test that cached() registers a view and un-registers it. Tests
2217 * that helpers using ClassRegistry::getObject('view'); don't fail
2221 function testCachedRegisteringViewObject() {
2222 Configure
::write('Cache.disable', false);
2223 Configure
::write('Cache.check', true);
2224 Configure
::write('debug', 2);
2227 $_SERVER['PHP_SELF'] = '/';
2231 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH
. 'tests' . DS
. 'test_app' . DS
. 'views'. DS
)
2234 $dispatcher =& new TestDispatcher();
2235 $dispatcher->base
= false;
2237 $url = 'test_cached_pages/cache_form';
2239 $dispatcher->dispatch($url);
2240 $out = ob_get_clean();
2242 ClassRegistry
::flush();
2245 $dispatcher->cached($url);
2246 $cached = ob_get_clean();
2248 $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
2249 $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
2250 $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
2252 $this->assertEqual($result, $expected);
2253 $filename = $this->__cachePath($dispatcher->here
);
2255 ClassRegistry
::flush();
2259 * testHttpMethodOverrides method
2264 function testHttpMethodOverrides() {
2266 Router
::mapResources('Posts');
2268 $_SERVER['REQUEST_METHOD'] = 'POST';
2269 $dispatcher =& new Dispatcher();
2270 $dispatcher->base
= false;
2272 $result = $dispatcher->parseParams('/posts');
2273 $expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'form' => array(), 'url' => array());
2274 $this->assertEqual($result, $expected);
2276 $_SERVER['REQUEST_METHOD'] = 'GET';
2277 $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
2279 $result = $dispatcher->parseParams('/posts/5');
2280 $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
2281 $this->assertEqual($result, $expected);
2283 unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
2284 $_SERVER['REQUEST_METHOD'] = 'GET';
2286 $result = $dispatcher->parseParams('/posts/5');
2287 $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'form' => array(), 'url' => array());
2288 $this->assertEqual($result, $expected);
2290 $_POST['_method'] = 'PUT';
2292 $result = $dispatcher->parseParams('/posts/5');
2293 $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
2294 $this->assertEqual($result, $expected);
2296 $_POST['_method'] = 'POST';
2297 $_POST['data'] = array('Post' => array('title' => 'New Post'));
2298 $_POST['extra'] = 'data';
2301 $result = $dispatcher->parseParams('/posts');
2303 'pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add',
2304 '[method]' => 'POST', 'form' => array('extra' => 'data'), 'data' => array('Post' => array('title' => 'New Post')),
2307 $this->assertEqual($result, $expected);
2309 unset($_POST['_method']);
2313 * Tests that invalid characters cannot be injected into the application base path.
2318 function testBasePathInjection() {
2319 $self = $_SERVER['PHP_SELF'];
2320 $_SERVER['PHP_SELF'] = urldecode(
2321 "/index.php/%22%3E%3Ch1%20onclick=%22alert('xss');%22%3Eheya%3C/h1%3E"
2324 $dispatcher =& new Dispatcher();
2325 $result = $dispatcher->baseUrl();
2326 $expected = '/index.php/h1 onclick=alert(xss);heya';
2327 $this->assertEqual($result, $expected);
2331 * testEnvironmentDetection method
2336 function testEnvironmentDetection() {
2337 $dispatcher =& new Dispatcher();
2339 $environments = array(
2341 'No rewrite base path' => array(
2342 'App' => array('base' => false, 'baseUrl' => '/index.php?', 'server' => 'IIS'),
2343 '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),
2347 'No rewrite with path' => array(
2348 'SERVER' => array('QUERY_STRING' => '/posts/add', 'REQUEST_URI' => '/index.php?/posts/add', 'URL' => '/index.php?/posts/add', 'argv' => array('/posts/add'), 'argc' => 1),
2350 'path' => '/posts/add'
2352 'No rewrite sub dir 1' => array(
2354 '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),
2358 'No rewrite sub dir 1 with path' => array(
2359 'GET' => array('/posts/add' => ''),
2360 '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),
2362 'path' => '/posts/add'
2364 'No rewrite sub dir 2' => array(
2365 'App' => array('base' => false, 'baseUrl' => '/site/index.php?', 'dir' => 'app', 'webroot' => 'webroot', 'server' => 'IIS'),
2368 '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),
2372 'No rewrite sub dir 2 with path' => array(
2373 'GET' => array('/posts/add' => ''),
2374 '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),
2376 'path' => '/posts/add'
2380 'No rewrite base path' => array(
2381 'App' => array('base' => false, 'baseUrl' => '/index.php', 'dir' => 'app', 'webroot' => 'webroot'),
2383 'SERVER_NAME' => 'localhost',
2384 'SERVER_ADDR' => '::1',
2385 'SERVER_PORT' => '80',
2386 'REMOTE_ADDR' => '::1',
2387 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot',
2388 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
2389 'QUERY_STRING' => '',
2390 'REQUEST_URI' => '/',
2391 'SCRIPT_NAME' => '/index.php',
2392 'PHP_SELF' => '/index.php',
2399 'No rewrite with path' => array(
2401 'HTTP_HOST' => 'localhost',
2402 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot',
2403 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/officespace/app/webroot/index.php',
2404 'QUERY_STRING' => '',
2405 'REQUEST_URI' => '/index.php/posts/add',
2406 'SCRIPT_NAME' => '/index.php',
2407 'PATH_INFO' => '/posts/add',
2408 'PHP_SELF' => '/index.php/posts/add',
2412 'path' => '/posts/add'
2414 'GET Request at base domain' => array(
2415 'App' => array('base' => false, 'baseUrl' => null, 'dir' => 'app', 'webroot' => 'webroot'),
2417 'HTTP_HOST' => 'cake.1.2',
2418 'SERVER_NAME' => 'cake.1.2',
2419 'SERVER_ADDR' => '127.0.0.1',
2420 'SERVER_PORT' => '80',
2421 'REMOTE_ADDR' => '127.0.0.1',
2422 'DOCUMENT_ROOT' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot',
2423 'SCRIPT_FILENAME' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot/index.php',
2424 'REMOTE_PORT' => '53550',
2425 'QUERY_STRING' => 'a=b',
2426 'REQUEST_URI' => '/?a=b',
2427 'SCRIPT_NAME' => '/index.php',
2428 'PHP_SELF' => '/index.php'
2430 'GET' => array('a' => 'b'),
2434 'urlParams' => array('a' => 'b'),
2435 'environment' => array('CGI_MODE' => false)
2437 'New CGI no mod_rewrite' => array(
2438 'App' => array('base' => false, 'baseUrl' => '/limesurvey20/index.php', 'dir' => 'app', 'webroot' => 'webroot'),
2440 'DOCUMENT_ROOT' => '/home/.sites/110/site313/web',
2441 'PATH_INFO' => '/installations',
2442 'PATH_TRANSLATED' => '/home/.sites/110/site313/web/limesurvey20/index.php',
2443 'PHPRC' => '/home/.sites/110/site313',
2444 'QUERY_STRING' => '',
2445 'REQUEST_URI' => '/limesurvey20/index.php/installations',
2446 'SCRIPT_FILENAME' => '/home/.sites/110/site313/web/limesurvey20/index.php',
2447 'SCRIPT_NAME' => '/limesurvey20/index.php',
2448 'SCRIPT_URI' => 'http://www.gisdat-umfragen.at/limesurvey20/index.php/installations',
2449 'PHP_SELF' => '/limesurvey20/index.php/installations',
2455 'path' => '/installations',
2456 'urlParams' => array(),
2457 'environment' => array('CGI_MODE' => true)
2461 $backup = $this->__backupEnvironment();
2463 foreach ($environments as $name => $env) {
2464 foreach ($env as $descrip => $settings) {
2465 if ($settings['reload']) {
2466 $this->__reloadEnvironment();
2468 $this->__loadEnvironment($settings);
2469 $this->assertEqual($dispatcher->uri(), $settings['path'], "%s on environment: {$name}, on setting: {$descrip}");
2471 if (isset($settings['urlParams'])) {
2472 $this->assertEqual($_GET, $settings['urlParams'], "%s on environment: {$name}, on setting: {$descrip}");
2474 if (isset($settings['environment'])) {
2475 foreach ($settings['environment'] as $key => $val) {
2476 $this->assertEqual(env($key), $val, "%s on key {$key} on environment: {$name}, on setting: {$descrip}");
2481 $this->__loadEnvironment(array_merge(array('reload' => true), $backup));
2485 * Tests that the Dispatcher does not return an empty action
2490 function testTrailingSlash() {
2492 $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
2495 $Dispatcher =& new TestDispatcher();
2496 Router
::connect('/myalias/:action/*', array('controller' => 'my_controller', 'action' => null));
2498 $Dispatcher->base
= false;
2499 $url = 'myalias/'; //Fails
2500 $controller = $Dispatcher->dispatch($url, array('return' => 1));
2501 $result = $Dispatcher->parseParams($url);
2502 $this->assertEqual('index', $result['action']);
2504 $url = 'myalias'; //Passes
2505 $controller = $Dispatcher->dispatch($url, array('return' => 1));
2506 $result = $Dispatcher->parseParams($url);
2507 $this->assertEqual('index', $result['action']);
2511 * backupEnvironment method
2516 function __backupEnvironment() {
2518 'App' => Configure
::read('App'),
2526 * reloadEnvironment method
2531 function __reloadEnvironment() {
2532 foreach ($_GET as $key => $val) {
2535 foreach ($_POST as $key => $val) {
2536 unset($_POST[$key]);
2538 foreach ($_SERVER as $key => $val) {
2539 unset($_SERVER[$key]);
2541 Configure
::write('App', array());
2545 * loadEnvironment method
2551 function __loadEnvironment($env) {
2552 if ($env['reload']) {
2553 $this->__reloadEnvironment();
2556 if (isset($env['App'])) {
2557 Configure
::write('App', $env['App']);
2560 if (isset($env['GET'])) {
2561 foreach ($env['GET'] as $key => $val) {
2566 if (isset($env['POST'])) {
2567 foreach ($env['POST'] as $key => $val) {
2568 $_POST[$key] = $val;
2572 if (isset($env['SERVER'])) {
2573 foreach ($env['SERVER'] as $key => $val) {
2574 $_SERVER[$key] = $val;
2586 function __cachePath($here) {
2591 $path = strtolower(Inflector
::slug($path));
2593 $filename = CACHE
. 'views' . DS
. $path . '.php';
2595 if (!file_exists($filename)) {
2596 $filename = CACHE
. 'views' . DS
. $path . '_index.php';