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>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* 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
|
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @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';
|
2007-07-25 21:08:12 +00:00
|
|
|
require_once CAKE.'app_controller.php';
|
2007-07-25 04:38:28 +00:00
|
|
|
|
|
|
|
class TestDispatcher extends Dispatcher {
|
|
|
|
|
|
|
|
function _invoke(&$controller, $params, $missingAction) {
|
|
|
|
$this->start($controller);
|
|
|
|
$classVars = get_object_vars($controller);
|
|
|
|
if ($missingAction && in_array('scaffold', array_keys($classVars))) {
|
|
|
|
uses('controller'. DS . 'scaffold');
|
2007-08-06 15:09:51 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
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 start(&$controller) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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-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-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.baseUrl', false);
|
|
|
|
Configure::write('App.dir', 'app');
|
|
|
|
Configure::write('App.webroot', 'webroot');
|
2007-07-25 04:38:28 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-02-03 22:20:13 +00:00
|
|
|
function testParseParamsWithoutZerosAndEmptyPost() {
|
|
|
|
$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";
|
|
|
|
$dispatcher =& new Dispatcher();
|
|
|
|
$test = $dispatcher->parseParams("/");
|
|
|
|
$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() {
|
|
|
|
$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() {
|
|
|
|
$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() {
|
|
|
|
$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() {
|
|
|
|
$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
|
|
|
}
|
2007-07-25 04:38:28 +00:00
|
|
|
|
2007-08-05 02:03:18 +00:00
|
|
|
function testGetUrl() {
|
|
|
|
$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-08-05 02:03:18 +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-08-05 02:03:18 +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');
|
|
|
|
$dispatcher =& new Dispatcher();
|
|
|
|
$uri = '/control/students/browse';
|
|
|
|
$result = $dispatcher->getUrl($uri);
|
|
|
|
$expected = 'students/browse';
|
|
|
|
$this->assertEqual($expected, $result);
|
2007-07-25 04:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testBaseUrlAndWebrootWithModRewrite() {
|
|
|
|
$dispatcher =& new Dispatcher();
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.baseUrl', false);
|
2007-07-25 04:38:28 +00:00
|
|
|
|
|
|
|
$dispatcher->base = false;
|
|
|
|
$_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-07-25 04:38:28 +00:00
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/1.2.x.x';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/1.2.x.x/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
|
|
|
$dispatcher->base = false;
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/app/webroot';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
|
2007-08-06 15:09:51 +00:00
|
|
|
$_SERVER['PHP_SELF'] = '/index.php';
|
2007-07-25 04:38:28 +00:00
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.dir', 'auth');
|
2007-07-25 04:38:28 +00:00
|
|
|
|
|
|
|
$dispatcher->base = false;;
|
|
|
|
$_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-07-25 04:38:28 +00:00
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/demos/auth';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/demos/auth/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.dir', 'code');
|
2007-07-25 04:38:28 +00:00
|
|
|
|
|
|
|
$dispatcher->base = false;;
|
|
|
|
$_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-07-25 04:38:28 +00:00
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/clients/PewterReport/code';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/clients/PewterReport/code/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
$dispatcher =& new Dispatcher();
|
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/control';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/control/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
|
|
|
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-08-02 19:12:19 +00:00
|
|
|
$dispatcher =& new Dispatcher();
|
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/newaffiliate';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/newaffiliate/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
2007-08-02 00:16:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
function testBaseUrlAndWebrootWithBaseUrl() {
|
|
|
|
$dispatcher =& new Dispatcher();
|
|
|
|
|
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-07-25 04:38:28 +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/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.baseUrl', '/app/webroot/test.php');
|
2007-07-25 04:38:28 +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/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.baseUrl', '/app/index.php');
|
2007-07-25 04:38:28 +00:00
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/app/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/app/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.baseUrl', '/index.php');
|
2007-07-25 04:38:28 +00:00
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
2007-08-05 02:03:18 +00:00
|
|
|
$expectedWebroot = '/app/webroot/';
|
2007-07-25 04:38:28 +00:00
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
|
2007-07-25 04:38:28 +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/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.baseUrl', '/CakeBB/app/index.php');
|
2007-07-25 04:38:28 +00:00
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/CakeBB/app/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/CakeBB/app/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.baseUrl', '/CakeBB/index.php');
|
2007-07-25 04:38:28 +00:00
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/CakeBB/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/CakeBB/app/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBaseUrlAndWebrootWithBase() {
|
|
|
|
$dispatcher =& new Dispatcher();
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.baseUrl',false);
|
|
|
|
$dispatcher->base = '/app';
|
2007-07-25 04:38:28 +00:00
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/app';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/app/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
$dispatcher->base = '';
|
2007-07-25 04:38:28 +00:00
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
Configure::write('App.dir', 'testbed');
|
|
|
|
$dispatcher->base = '/cake/testbed/webroot';
|
2007-07-25 04:38:28 +00:00
|
|
|
$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/';
|
|
|
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testMissingController() {
|
|
|
|
$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-07-25 04:38:28 +00:00
|
|
|
restore_error_handler();
|
2007-08-16 05:44:06 +00:00
|
|
|
$controller = $dispatcher->dispatch($url, array('return' => 1));
|
2007-07-25 04:38:28 +00:00
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
|
|
|
|
$expected = 'missingController';
|
|
|
|
$this->assertEqual($expected, $controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPrivate() {
|
|
|
|
$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-07-25 04:38:28 +00:00
|
|
|
|
|
|
|
restore_error_handler();
|
2007-08-16 05:44:06 +00:00
|
|
|
@$controller = $dispatcher->dispatch($url, array('return' => 1));
|
2007-07-25 04:38:28 +00:00
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
|
|
|
|
$expected = 'privateAction';
|
|
|
|
$this->assertEqual($expected, $controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testMissingAction() {
|
|
|
|
$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
|
|
|
|
|
|
|
restore_error_handler();
|
|
|
|
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
$expected = 'missingAction';
|
|
|
|
$this->assertEqual($expected, $controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDispatch() {
|
|
|
|
$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
|
|
|
|
|
|
|
restore_error_handler();
|
2007-08-16 16:31:50 +00:00
|
|
|
@$controller = $dispatcher->dispatch($url, array('return' => 1));
|
2007-07-25 04:38:28 +00:00
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
|
|
|
|
$expected = 'Pages';
|
|
|
|
$this->assertEqual($expected, $controller->name);
|
|
|
|
|
2007-08-16 16:31:50 +00:00
|
|
|
$expected = array('param' => 'value', 'param2' => 'value2');
|
2007-07-25 04:38:28 +00:00
|
|
|
$this->assertIdentical($expected, $controller->namedArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testAdminDispatch() {
|
|
|
|
$_POST = array();
|
|
|
|
$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();
|
|
|
|
|
|
|
|
restore_error_handler();
|
2007-08-16 05:44:06 +00:00
|
|
|
@$controller = $dispatcher->dispatch($url, array('return' => 1));
|
2007-07-25 04:38:28 +00:00
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
|
|
|
|
$expected = 'TestDispatchPages';
|
|
|
|
$this->assertEqual($expected, $controller->name);
|
|
|
|
|
2007-08-16 05:44:06 +00:00
|
|
|
$expected = array('param' => 'value', 'param2' => 'value2');
|
2007-07-25 04:38:28 +00:00
|
|
|
$this->assertIdentical($expected, $controller->namedArgs);
|
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();
|
|
|
|
$dispatcher =& new TestDispatcher();
|
|
|
|
Router::connect('/my_plugin/:controller/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display'));
|
|
|
|
|
|
|
|
$dispatcher->base = false;
|
2007-08-05 02:03:18 +00:00
|
|
|
$url = 'my_plugin/some_pages/home/param:value/param2:value2';
|
2007-07-25 04:38:28 +00:00
|
|
|
|
|
|
|
restore_error_handler();
|
2007-08-16 16:31:50 +00:00
|
|
|
@$controller = $dispatcher->dispatch($url, array('return' => 1));
|
2007-07-25 04:38:28 +00:00
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
|
|
|
|
|
|
|
|
$result = $dispatcher->parseParams($url);
|
2007-09-26 09:49:01 +00:00
|
|
|
$expected = array('pass' => array('home', 'param'=> 'value', 'param2'=> 'value2'),
|
2007-07-25 04:38:28 +00:00
|
|
|
'plugin'=> 'my_plugin', 'controller'=> 'some_pages', 'action'=> 'display',
|
|
|
|
'form'=> null, //array('testdata'=> 'My Posted Data'),
|
|
|
|
'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'),
|
|
|
|
'bare'=> 0, 'webservices'=> '');
|
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);
|
|
|
|
|
|
|
|
$expected = array('param'=>'value', 'param2'=>'value2');
|
|
|
|
$this->assertIdentical($expected, $controller->namedArgs);
|
|
|
|
|
|
|
|
$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();
|
|
|
|
$dispatcher =& new TestDispatcher();
|
|
|
|
$dispatcher->base = false;
|
|
|
|
|
2007-08-05 02:03:18 +00:00
|
|
|
$url = 'my_plugin/other_pages/index/param:value/param2:value2';
|
2007-07-25 19:42:58 +00:00
|
|
|
|
|
|
|
restore_error_handler();
|
|
|
|
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$expected = array('param'=>'value', 'param2'=>'value2');
|
|
|
|
$this->assertIdentical($expected, $controller->namedArgs);
|
|
|
|
|
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();
|
|
|
|
$dispatcher =& new TestDispatcher();
|
|
|
|
$dispatcher->base = false;
|
2007-08-05 02:03:18 +00:00
|
|
|
$url = 'my_plugin/add/param:value/param2:value2';
|
2007-07-25 19:42:58 +00:00
|
|
|
|
|
|
|
restore_error_handler();
|
2007-08-16 16:31:50 +00:00
|
|
|
@$controller = $dispatcher->dispatch($url, array('return' => 1));
|
2007-07-25 19:42:58 +00:00
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
|
|
|
|
$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-09-27 10:58:06 +00:00
|
|
|
$expected = array('param'=>'value', 'param2'=>'value2');
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->assertEqual($controller->params['pass'], $expected);
|
2007-10-14 16:53:36 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
$dispatcher =& new TestDispatcher();
|
|
|
|
$dispatcher->base = false;
|
|
|
|
$url = 'admin/articles_test';
|
|
|
|
|
|
|
|
restore_error_handler();
|
|
|
|
@$controller = $dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
|
|
|
|
$expected = 'articles_test';
|
|
|
|
$this->assertIdentical($controller->plugin, $expected);
|
|
|
|
|
|
|
|
$expected = 'ArticlesTest';
|
|
|
|
$this->assertIdentical($controller->name, $expected);
|
|
|
|
|
|
|
|
$expected = 'admin_index';
|
|
|
|
$this->assertIdentical($controller->action, $expected);
|
|
|
|
$expected = array('pass'=> array(), 'controller' => 'articles_test', 'plugin' => 'articles_test', 'action' => 'admin_index',
|
|
|
|
'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/articles_test'),
|
|
|
|
'bare' => 0, 'webservices' => null, 'return' => 1
|
|
|
|
);
|
|
|
|
$this->assertIdentical($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();
|
|
|
|
$dispatcher =& new TestDispatcher();
|
|
|
|
$dispatcher->base = false;
|
|
|
|
|
2007-08-05 02:03:18 +00:00
|
|
|
$url = 'my_plugin/param:value/param2:value2';
|
2007-07-25 19:42:58 +00:00
|
|
|
restore_error_handler();
|
|
|
|
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
|
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-08-16 05:44:06 +00:00
|
|
|
$dispatcher =& new TestDispatcher();
|
|
|
|
$dispatcher->base = false;
|
|
|
|
|
|
|
|
$url = 'test_dispatch_pages/admin_index/param:value/param2:value2';
|
|
|
|
restore_error_handler();
|
|
|
|
@$controller = $dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
set_error_handler('simpleTestErrorHandler');
|
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-07-25 04:38:28 +00:00
|
|
|
function tearDown() {
|
|
|
|
$_GET = $this->_get;
|
|
|
|
}
|
2007-02-03 22:20:13 +00:00
|
|
|
}
|
2007-08-05 02:03:18 +00:00
|
|
|
?>
|