PageRenderTime 32ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/tests/cases/dispatcher.test.php

http://github.com/Datawalke/Coordino
PHP | 2625 lines | 1642 code | 343 blank | 640 comment | 18 complexity | 96eacdb30f0822786585913b5cd11ec8 MD5 | raw file
  1. <?php
  2. /**
  3. * DispatcherTest file
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The Open Group Test Suite License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package cake
  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
  19. */
  20. require_once CAKE . 'dispatcher.php';
  21. if (!class_exists('AppController')) {
  22. require_once LIBS . 'controller' . DS . 'app_controller.php';
  23. } elseif (!defined('APP_CONTROLLER_EXISTS')){
  24. define('APP_CONTROLLER_EXISTS', true);
  25. }
  26. /**
  27. * TestDispatcher class
  28. *
  29. * @package cake
  30. * @subpackage cake.tests.cases
  31. */
  32. class TestDispatcher extends Dispatcher {
  33. /**
  34. * invoke method
  35. *
  36. * @param mixed $controller
  37. * @param mixed $params
  38. * @param mixed $missingAction
  39. * @return void
  40. * @access protected
  41. */
  42. function _invoke(&$controller, $params) {
  43. restore_error_handler();
  44. if ($result = parent::_invoke($controller, $params)) {
  45. if ($result[0] === 'missingAction') {
  46. return $result;
  47. }
  48. }
  49. set_error_handler('simpleTestErrorHandler');
  50. return $controller;
  51. }
  52. /**
  53. * cakeError method
  54. *
  55. * @param mixed $filename
  56. * @return void
  57. * @access public
  58. */
  59. function cakeError($filename, $params) {
  60. return array($filename, $params);
  61. }
  62. /**
  63. * _stop method
  64. *
  65. * @return void
  66. * @access protected
  67. */
  68. function _stop() {
  69. $this->stopped = true;
  70. return true;
  71. }
  72. }
  73. /**
  74. * MyPluginAppController class
  75. *
  76. * @package cake
  77. * @subpackage cake.tests.cases
  78. */
  79. class MyPluginAppController extends AppController {
  80. }
  81. /**
  82. * MyPluginController class
  83. *
  84. * @package cake
  85. * @subpackage cake.tests.cases
  86. */
  87. class MyPluginController extends MyPluginAppController {
  88. /**
  89. * name property
  90. *
  91. * @var string 'MyPlugin'
  92. * @access public
  93. */
  94. var $name = 'MyPlugin';
  95. /**
  96. * uses property
  97. *
  98. * @var array
  99. * @access public
  100. */
  101. var $uses = array();
  102. /**
  103. * index method
  104. *
  105. * @return void
  106. * @access public
  107. */
  108. function index() {
  109. return true;
  110. }
  111. /**
  112. * add method
  113. *
  114. * @return void
  115. * @access public
  116. */
  117. function add() {
  118. return true;
  119. }
  120. /**
  121. * admin_add method
  122. *
  123. * @param mixed $id
  124. * @return void
  125. * @access public
  126. */
  127. function admin_add($id = null) {
  128. return $id;
  129. }
  130. }
  131. /**
  132. * SomePagesController class
  133. *
  134. * @package cake
  135. * @subpackage cake.tests.cases
  136. */
  137. class SomePagesController extends AppController {
  138. /**
  139. * name property
  140. *
  141. * @var string 'SomePages'
  142. * @access public
  143. */
  144. var $name = 'SomePages';
  145. /**
  146. * uses property
  147. *
  148. * @var array
  149. * @access public
  150. */
  151. var $uses = array();
  152. /**
  153. * display method
  154. *
  155. * @param mixed $page
  156. * @return void
  157. * @access public
  158. */
  159. function display($page = null) {
  160. return $page;
  161. }
  162. /**
  163. * index method
  164. *
  165. * @return void
  166. * @access public
  167. */
  168. function index() {
  169. return true;
  170. }
  171. /**
  172. * protected method
  173. *
  174. * @return void
  175. * @access protected
  176. */
  177. function _protected() {
  178. return true;
  179. }
  180. /**
  181. * redirect method overriding
  182. *
  183. * @return void
  184. * @access public
  185. */
  186. function redirect() {
  187. echo 'this should not be accessible';
  188. }
  189. }
  190. /**
  191. * OtherPagesController class
  192. *
  193. * @package cake
  194. * @subpackage cake.tests.cases
  195. */
  196. class OtherPagesController extends MyPluginAppController {
  197. /**
  198. * name property
  199. *
  200. * @var string 'OtherPages'
  201. * @access public
  202. */
  203. var $name = 'OtherPages';
  204. /**
  205. * uses property
  206. *
  207. * @var array
  208. * @access public
  209. */
  210. var $uses = array();
  211. /**
  212. * display method
  213. *
  214. * @param mixed $page
  215. * @return void
  216. * @access public
  217. */
  218. function display($page = null) {
  219. return $page;
  220. }
  221. /**
  222. * index method
  223. *
  224. * @return void
  225. * @access public
  226. */
  227. function index() {
  228. return true;
  229. }
  230. }
  231. /**
  232. * TestDispatchPagesController class
  233. *
  234. * @package cake
  235. * @subpackage cake.tests.cases
  236. */
  237. class TestDispatchPagesController extends AppController {
  238. /**
  239. * name property
  240. *
  241. * @var string 'TestDispatchPages'
  242. * @access public
  243. */
  244. var $name = 'TestDispatchPages';
  245. /**
  246. * uses property
  247. *
  248. * @var array
  249. * @access public
  250. */
  251. var $uses = array();
  252. /**
  253. * admin_index method
  254. *
  255. * @return void
  256. * @access public
  257. */
  258. function admin_index() {
  259. return true;
  260. }
  261. /**
  262. * camelCased method
  263. *
  264. * @return void
  265. * @access public
  266. */
  267. function camelCased() {
  268. return true;
  269. }
  270. }
  271. /**
  272. * ArticlesTestAppController class
  273. *
  274. * @package cake
  275. * @subpackage cake.tests.cases
  276. */
  277. class ArticlesTestAppController extends AppController {
  278. }
  279. /**
  280. * ArticlesTestController class
  281. *
  282. * @package cake
  283. * @subpackage cake.tests.cases
  284. */
  285. class ArticlesTestController extends ArticlesTestAppController {
  286. /**
  287. * name property
  288. *
  289. * @var string 'ArticlesTest'
  290. * @access public
  291. */
  292. var $name = 'ArticlesTest';
  293. /**
  294. * uses property
  295. *
  296. * @var array
  297. * @access public
  298. */
  299. var $uses = array();
  300. /**
  301. * admin_index method
  302. *
  303. * @return void
  304. * @access public
  305. */
  306. function admin_index() {
  307. return true;
  308. }
  309. /**
  310. * fake index method.
  311. *
  312. * @return void
  313. */
  314. function index() {
  315. return true;
  316. }
  317. }
  318. /**
  319. * SomePostsController class
  320. *
  321. * @package cake
  322. * @subpackage cake.tests.cases
  323. */
  324. class SomePostsController extends AppController {
  325. /**
  326. * name property
  327. *
  328. * @var string 'SomePosts'
  329. * @access public
  330. */
  331. var $name = 'SomePosts';
  332. /**
  333. * uses property
  334. *
  335. * @var array
  336. * @access public
  337. */
  338. var $uses = array();
  339. /**
  340. * autoRender property
  341. *
  342. * @var bool false
  343. * @access public
  344. */
  345. var $autoRender = false;
  346. /**
  347. * beforeFilter method
  348. *
  349. * @return void
  350. * @access public
  351. */
  352. function beforeFilter() {
  353. if ($this->params['action'] == 'index') {
  354. $this->params['action'] = 'view';
  355. } else {
  356. $this->params['action'] = 'change';
  357. }
  358. $this->params['pass'] = array('changed');
  359. }
  360. /**
  361. * index method
  362. *
  363. * @return void
  364. * @access public
  365. */
  366. function index() {
  367. return true;
  368. }
  369. /**
  370. * change method
  371. *
  372. * @return void
  373. * @access public
  374. */
  375. function change() {
  376. return true;
  377. }
  378. }
  379. /**
  380. * TestCachedPagesController class
  381. *
  382. * @package cake
  383. * @subpackage cake.tests.cases
  384. */
  385. class TestCachedPagesController extends AppController {
  386. /**
  387. * name property
  388. *
  389. * @var string 'TestCachedPages'
  390. * @access public
  391. */
  392. var $name = 'TestCachedPages';
  393. /**
  394. * uses property
  395. *
  396. * @var array
  397. * @access public
  398. */
  399. var $uses = array();
  400. /**
  401. * helpers property
  402. *
  403. * @var array
  404. * @access public
  405. */
  406. var $helpers = array('Cache');
  407. /**
  408. * cacheAction property
  409. *
  410. * @var array
  411. * @access public
  412. */
  413. var $cacheAction = array(
  414. 'index' => '+2 sec',
  415. 'test_nocache_tags' => '+2 sec',
  416. 'view' => '+2 sec'
  417. );
  418. /**
  419. * viewPath property
  420. *
  421. * @var string 'posts'
  422. * @access public
  423. */
  424. var $viewPath = 'posts';
  425. /**
  426. * index method
  427. *
  428. * @return void
  429. * @access public
  430. */
  431. function index() {
  432. $this->render();
  433. }
  434. /**
  435. * test_nocache_tags method
  436. *
  437. * @return void
  438. * @access public
  439. */
  440. function test_nocache_tags() {
  441. $this->render();
  442. }
  443. /**
  444. * view method
  445. *
  446. * @return void
  447. * @access public
  448. */
  449. function view($id = null) {
  450. $this->render('index');
  451. }
  452. /**
  453. * test cached forms / tests view object being registered
  454. *
  455. * @return void
  456. */
  457. function cache_form() {
  458. $this->cacheAction = 10;
  459. $this->helpers[] = 'Form';
  460. }
  461. }
  462. /**
  463. * TimesheetsController class
  464. *
  465. * @package cake
  466. * @subpackage cake.tests.cases
  467. */
  468. class TimesheetsController extends AppController {
  469. /**
  470. * name property
  471. *
  472. * @var string 'Timesheets'
  473. * @access public
  474. */
  475. var $name = 'Timesheets';
  476. /**
  477. * uses property
  478. *
  479. * @var array
  480. * @access public
  481. */
  482. var $uses = array();
  483. /**
  484. * index method
  485. *
  486. * @return void
  487. * @access public
  488. */
  489. function index() {
  490. return true;
  491. }
  492. }
  493. /**
  494. * DispatcherTest class
  495. *
  496. * @package cake
  497. * @subpackage cake.tests.cases
  498. */
  499. class DispatcherTest extends CakeTestCase {
  500. /**
  501. * setUp method
  502. *
  503. * @return void
  504. * @access public
  505. */
  506. function startTest() {
  507. $this->_get = $_GET;
  508. $_GET = array();
  509. $this->_post = $_POST;
  510. $this->_files = $_FILES;
  511. $this->_server = $_SERVER;
  512. $this->_app = Configure::read('App');
  513. Configure::write('App.base', false);
  514. Configure::write('App.baseUrl', false);
  515. Configure::write('App.dir', 'app');
  516. Configure::write('App.webroot', 'webroot');
  517. $this->_cache = Configure::read('Cache');
  518. Configure::write('Cache.disable', true);
  519. $this->_debug = Configure::read('debug');
  520. App::build(App::core());
  521. }
  522. /**
  523. * tearDown method
  524. *
  525. * @return void
  526. * @access public
  527. */
  528. function endTest() {
  529. $_GET = $this->_get;
  530. $_POST = $this->_post;
  531. $_FILES = $this->_files;
  532. $_SERVER = $this->_server;
  533. App::build();
  534. Configure::write('App', $this->_app);
  535. Configure::write('Cache', $this->_cache);
  536. Configure::write('debug', $this->_debug);
  537. }
  538. /**
  539. * testParseParamsWithoutZerosAndEmptyPost method
  540. *
  541. * @return void
  542. * @access public
  543. */
  544. function testParseParamsWithoutZerosAndEmptyPost() {
  545. $Dispatcher =& new Dispatcher();
  546. $test = $Dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3");
  547. $this->assertIdentical($test['controller'], 'testcontroller');
  548. $this->assertIdentical($test['action'], 'testaction');
  549. $this->assertIdentical($test['pass'][0], 'params1');
  550. $this->assertIdentical($test['pass'][1], 'params2');
  551. $this->assertIdentical($test['pass'][2], 'params3');
  552. $this->assertFalse(!empty($test['form']));
  553. }
  554. /**
  555. * testParseParamsReturnsPostedData method
  556. *
  557. * @return void
  558. * @access public
  559. */
  560. function testParseParamsReturnsPostedData() {
  561. $_POST['testdata'] = "My Posted Content";
  562. $Dispatcher =& new Dispatcher();
  563. $test = $Dispatcher->parseParams("/");
  564. $this->assertTrue($test['form'], "Parsed URL not returning post data");
  565. $this->assertIdentical($test['form']['testdata'], "My Posted Content");
  566. }
  567. /**
  568. * testParseParamsWithSingleZero method
  569. *
  570. * @return void
  571. * @access public
  572. */
  573. function testParseParamsWithSingleZero() {
  574. $Dispatcher =& new Dispatcher();
  575. $test = $Dispatcher->parseParams("/testcontroller/testaction/1/0/23");
  576. $this->assertIdentical($test['controller'], 'testcontroller');
  577. $this->assertIdentical($test['action'], 'testaction');
  578. $this->assertIdentical($test['pass'][0], '1');
  579. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
  580. $this->assertIdentical($test['pass'][2], '23');
  581. }
  582. /**
  583. * testParseParamsWithManySingleZeros method
  584. *
  585. * @return void
  586. * @access public
  587. */
  588. function testParseParamsWithManySingleZeros() {
  589. $Dispatcher =& new Dispatcher();
  590. $test = $Dispatcher->parseParams("/testcontroller/testaction/0/0/0/0/0/0");
  591. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][0]);
  592. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
  593. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][2]);
  594. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][3]);
  595. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][4]);
  596. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][5]);
  597. }
  598. /**
  599. * testParseParamsWithManyZerosInEachSectionOfUrl method
  600. *
  601. * @return void
  602. * @access public
  603. */
  604. function testParseParamsWithManyZerosInEachSectionOfUrl() {
  605. $Dispatcher =& new Dispatcher();
  606. $test = $Dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
  607. $this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0]);
  608. $this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1]);
  609. $this->assertPattern('/\\A(?:00000)\\z/', $test['pass'][2]);
  610. $this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][3]);
  611. $this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][4]);
  612. $this->assertPattern('/\\A(?:0000000)\\z/', $test['pass'][5]);
  613. }
  614. /**
  615. * testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl method
  616. *
  617. * @return void
  618. * @access public
  619. */
  620. function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
  621. $Dispatcher =& new Dispatcher();
  622. $test = $Dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
  623. $this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]);
  624. $this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1]);
  625. $this->assertPattern('/\\A(?:04010)\\z/', $test['pass'][2]);
  626. $this->assertPattern('/\\A(?:000002)\\z/', $test['pass'][3]);
  627. $this->assertPattern('/\\A(?:000030)\\z/', $test['pass'][4]);
  628. $this->assertPattern('/\\A(?:0000400)\\z/', $test['pass'][5]);
  629. }
  630. /**
  631. * testQueryStringOnRoot method
  632. *
  633. * @return void
  634. * @access public
  635. */
  636. function testQueryStringOnRoot() {
  637. Router::reload();
  638. Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
  639. Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
  640. $_GET = array('coffee' => 'life', 'sleep' => 'sissies');
  641. $Dispatcher =& new Dispatcher();
  642. $uri = 'posts/home/?coffee=life&sleep=sissies';
  643. $result = $Dispatcher->parseParams($uri);
  644. $this->assertPattern('/posts/', $result['controller']);
  645. $this->assertPattern('/home/', $result['action']);
  646. $this->assertTrue(isset($result['url']['sleep']));
  647. $this->assertTrue(isset($result['url']['coffee']));
  648. $Dispatcher =& new Dispatcher();
  649. $uri = '/?coffee=life&sleep=sissy';
  650. $result = $Dispatcher->parseParams($uri);
  651. $this->assertPattern('/pages/', $result['controller']);
  652. $this->assertPattern('/display/', $result['action']);
  653. $this->assertTrue(isset($result['url']['sleep']));
  654. $this->assertTrue(isset($result['url']['coffee']));
  655. $this->assertEqual($result['url']['coffee'], 'life');
  656. }
  657. /**
  658. * testFileUploadArrayStructure method
  659. *
  660. * @return void
  661. * @access public
  662. */
  663. function testFileUploadArrayStructure() {
  664. $_FILES = array('data' => array('name' => array(
  665. 'File' => array(
  666. array('data' => 'cake_mssql_patch.patch'),
  667. array('data' => 'controller.diff'),
  668. array('data' => ''),
  669. array('data' => ''),
  670. ),
  671. 'Post' => array('attachment' => 'jquery-1.2.1.js'),
  672. ),
  673. 'type' => array(
  674. 'File' => array(
  675. array('data' => ''),
  676. array('data' => ''),
  677. array('data' => ''),
  678. array('data' => ''),
  679. ),
  680. 'Post' => array('attachment' => 'application/x-javascript'),
  681. ),
  682. 'tmp_name' => array(
  683. 'File' => array(
  684. array('data' => '/private/var/tmp/phpy05Ywj'),
  685. array('data' => '/private/var/tmp/php7MBztY'),
  686. array('data' => ''),
  687. array('data' => ''),
  688. ),
  689. 'Post' => array('attachment' => '/private/var/tmp/phpEwlrIo'),
  690. ),
  691. 'error' => array(
  692. 'File' => array(
  693. array('data' => 0),
  694. array('data' => 0),
  695. array('data' => 4),
  696. array('data' => 4)
  697. ),
  698. 'Post' => array('attachment' => 0)
  699. ),
  700. 'size' => array(
  701. 'File' => array(
  702. array('data' => 6271),
  703. array('data' => 350),
  704. array('data' => 0),
  705. array('data' => 0),
  706. ),
  707. 'Post' => array('attachment' => 80469)
  708. ),
  709. ));
  710. $Dispatcher =& new Dispatcher();
  711. $result = $Dispatcher->parseParams('/');
  712. $expected = array(
  713. 'File' => array(
  714. array('data' => array(
  715. 'name' => 'cake_mssql_patch.patch',
  716. 'type' => '',
  717. 'tmp_name' => '/private/var/tmp/phpy05Ywj',
  718. 'error' => 0,
  719. 'size' => 6271,
  720. ),
  721. ),
  722. array('data' => array(
  723. 'name' => 'controller.diff',
  724. 'type' => '',
  725. 'tmp_name' => '/private/var/tmp/php7MBztY',
  726. 'error' => 0,
  727. 'size' => 350,
  728. )),
  729. array('data' => array(
  730. 'name' => '',
  731. 'type' => '',
  732. 'tmp_name' => '',
  733. 'error' => 4,
  734. 'size' => 0,
  735. )),
  736. array('data' => array(
  737. 'name' => '',
  738. 'type' => '',
  739. 'tmp_name' => '',
  740. 'error' => 4,
  741. 'size' => 0,
  742. )),
  743. ),
  744. 'Post' => array('attachment' => array(
  745. 'name' => 'jquery-1.2.1.js',
  746. 'type' => 'application/x-javascript',
  747. 'tmp_name' => '/private/var/tmp/phpEwlrIo',
  748. 'error' => 0,
  749. 'size' => 80469,
  750. )));
  751. $this->assertEqual($result['data'], $expected);
  752. $_FILES = array(
  753. 'data' => array(
  754. 'name' => array(
  755. 'Document' => array(
  756. 1 => array(
  757. 'birth_cert' => 'born on.txt',
  758. 'passport' => 'passport.txt',
  759. 'drivers_license' => 'ugly pic.jpg'
  760. ),
  761. 2 => array(
  762. 'birth_cert' => 'aunt betty.txt',
  763. 'passport' => 'betty-passport.txt',
  764. 'drivers_license' => 'betty-photo.jpg'
  765. ),
  766. ),
  767. ),
  768. 'type' => array(
  769. 'Document' => array(
  770. 1 => array(
  771. 'birth_cert' => 'application/octet-stream',
  772. 'passport' => 'application/octet-stream',
  773. 'drivers_license' => 'application/octet-stream',
  774. ),
  775. 2 => array(
  776. 'birth_cert' => 'application/octet-stream',
  777. 'passport' => 'application/octet-stream',
  778. 'drivers_license' => 'application/octet-stream',
  779. )
  780. )
  781. ),
  782. 'tmp_name' => array(
  783. 'Document' => array(
  784. 1 => array(
  785. 'birth_cert' => '/private/var/tmp/phpbsUWfH',
  786. 'passport' => '/private/var/tmp/php7f5zLt',
  787. 'drivers_license' => '/private/var/tmp/phpMXpZgT',
  788. ),
  789. 2 => array(
  790. 'birth_cert' => '/private/var/tmp/php5kHZt0',
  791. 'passport' => '/private/var/tmp/phpnYkOuM',
  792. 'drivers_license' => '/private/var/tmp/php9Rq0P3',
  793. )
  794. )
  795. ),
  796. 'error' => array(
  797. 'Document' => array(
  798. 1 => array(
  799. 'birth_cert' => 0,
  800. 'passport' => 0,
  801. 'drivers_license' => 0,
  802. ),
  803. 2 => array(
  804. 'birth_cert' => 0,
  805. 'passport' => 0,
  806. 'drivers_license' => 0,
  807. )
  808. )
  809. ),
  810. 'size' => array(
  811. 'Document' => array(
  812. 1 => array(
  813. 'birth_cert' => 123,
  814. 'passport' => 458,
  815. 'drivers_license' => 875,
  816. ),
  817. 2 => array(
  818. 'birth_cert' => 876,
  819. 'passport' => 976,
  820. 'drivers_license' => 9783,
  821. )
  822. )
  823. )
  824. )
  825. );
  826. $Dispatcher =& new Dispatcher();
  827. $result = $Dispatcher->parseParams('/');
  828. $expected = array(
  829. 'Document' => array(
  830. 1 => array(
  831. 'birth_cert' => array(
  832. 'name' => 'born on.txt',
  833. 'tmp_name' => '/private/var/tmp/phpbsUWfH',
  834. 'error' => 0,
  835. 'size' => 123,
  836. 'type' => 'application/octet-stream',
  837. ),
  838. 'passport' => array(
  839. 'name' => 'passport.txt',
  840. 'tmp_name' => '/private/var/tmp/php7f5zLt',
  841. 'error' => 0,
  842. 'size' => 458,
  843. 'type' => 'application/octet-stream',
  844. ),
  845. 'drivers_license' => array(
  846. 'name' => 'ugly pic.jpg',
  847. 'tmp_name' => '/private/var/tmp/phpMXpZgT',
  848. 'error' => 0,
  849. 'size' => 875,
  850. 'type' => 'application/octet-stream',
  851. ),
  852. ),
  853. 2 => array(
  854. 'birth_cert' => array(
  855. 'name' => 'aunt betty.txt',
  856. 'tmp_name' => '/private/var/tmp/php5kHZt0',
  857. 'error' => 0,
  858. 'size' => 876,
  859. 'type' => 'application/octet-stream',
  860. ),
  861. 'passport' => array(
  862. 'name' => 'betty-passport.txt',
  863. 'tmp_name' => '/private/var/tmp/phpnYkOuM',
  864. 'error' => 0,
  865. 'size' => 976,
  866. 'type' => 'application/octet-stream',
  867. ),
  868. 'drivers_license' => array(
  869. 'name' => 'betty-photo.jpg',
  870. 'tmp_name' => '/private/var/tmp/php9Rq0P3',
  871. 'error' => 0,
  872. 'size' => 9783,
  873. 'type' => 'application/octet-stream',
  874. ),
  875. ),
  876. )
  877. );
  878. $this->assertEqual($result['data'], $expected);
  879. $_FILES = array(
  880. 'data' => array(
  881. 'name' => array('birth_cert' => 'born on.txt'),
  882. 'type' => array('birth_cert' => 'application/octet-stream'),
  883. 'tmp_name' => array('birth_cert' => '/private/var/tmp/phpbsUWfH'),
  884. 'error' => array('birth_cert' => 0),
  885. 'size' => array('birth_cert' => 123)
  886. )
  887. );
  888. $Dispatcher =& new Dispatcher();
  889. $result = $Dispatcher->parseParams('/');
  890. $expected = array(
  891. 'birth_cert' => array(
  892. 'name' => 'born on.txt',
  893. 'type' => 'application/octet-stream',
  894. 'tmp_name' => '/private/var/tmp/phpbsUWfH',
  895. 'error' => 0,
  896. 'size' => 123
  897. )
  898. );
  899. $this->assertEqual($result['data'], $expected);
  900. }
  901. /**
  902. * testGetUrl method
  903. *
  904. * @return void
  905. * @access public
  906. */
  907. function testGetUrl() {
  908. $Dispatcher =& new Dispatcher();
  909. $Dispatcher->base = '/app/webroot/index.php';
  910. $uri = '/app/webroot/index.php/posts/add';
  911. $result = $Dispatcher->getUrl($uri);
  912. $expected = 'posts/add';
  913. $this->assertEqual($expected, $result);
  914. Configure::write('App.baseUrl', '/app/webroot/index.php');
  915. $uri = '/posts/add';
  916. $result = $Dispatcher->getUrl($uri);
  917. $expected = 'posts/add';
  918. $this->assertEqual($expected, $result);
  919. $_GET['url'] = array();
  920. Configure::write('App.base', '/control');
  921. $Dispatcher =& new Dispatcher();
  922. $Dispatcher->baseUrl();
  923. $uri = '/control/students/browse';
  924. $result = $Dispatcher->getUrl($uri);
  925. $expected = 'students/browse';
  926. $this->assertEqual($expected, $result);
  927. $_GET['url'] = array();
  928. $Dispatcher =& new Dispatcher();
  929. $Dispatcher->base = '';
  930. $uri = '/?/home';
  931. $result = $Dispatcher->getUrl($uri);
  932. $expected = '?/home';
  933. $this->assertEqual($expected, $result);
  934. $_GET['url'] = array();
  935. $Dispatcher =& new Dispatcher();
  936. $Dispatcher->base = '/shop';
  937. $uri = '/shop/fr/pages/shop';
  938. $result = $Dispatcher->getUrl($uri);
  939. $expected = 'fr/pages/shop';
  940. $this->assertEqual($expected, $result);
  941. }
  942. /**
  943. * testBaseUrlAndWebrootWithModRewrite method
  944. *
  945. * @return void
  946. * @access public
  947. */
  948. function testBaseUrlAndWebrootWithModRewrite() {
  949. $Dispatcher =& new Dispatcher();
  950. $Dispatcher->base = false;
  951. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
  952. $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
  953. $_SERVER['PHP_SELF'] = '/1.2.x.x/app/webroot/index.php';
  954. $result = $Dispatcher->baseUrl();
  955. $expected = '/1.2.x.x';
  956. $this->assertEqual($expected, $result);
  957. $expectedWebroot = '/1.2.x.x/';
  958. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  959. $Dispatcher->base = false;
  960. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/app/webroot';
  961. $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
  962. $_SERVER['PHP_SELF'] = '/index.php';
  963. $result = $Dispatcher->baseUrl();
  964. $expected = '';
  965. $this->assertEqual($expected, $result);
  966. $expectedWebroot = '/';
  967. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  968. $Dispatcher->base = false;
  969. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/test/';
  970. $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/test/webroot/index.php';
  971. $_SERVER['PHP_SELF'] = '/webroot/index.php';
  972. $result = $Dispatcher->baseUrl();
  973. $expected = '';
  974. $this->assertEqual($expected, $result);
  975. $expectedWebroot = '/';
  976. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  977. $Dispatcher->base = false;
  978. $_SERVER['DOCUMENT_ROOT'] = '/some/apps/where';
  979. $_SERVER['SCRIPT_FILENAME'] = '/some/apps/where/app/webroot/index.php';
  980. $_SERVER['PHP_SELF'] = '/some/apps/where/app/webroot/index.php';
  981. $result = $Dispatcher->baseUrl();
  982. $expected = '/some/apps/where';
  983. $this->assertEqual($expected, $result);
  984. $expectedWebroot = '/some/apps/where/';
  985. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  986. Configure::write('App.dir', 'auth');
  987. $Dispatcher->base = false;
  988. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
  989. $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/demos/auth/webroot/index.php';
  990. $_SERVER['PHP_SELF'] = '/demos/auth/webroot/index.php';
  991. $result = $Dispatcher->baseUrl();
  992. $expected = '/demos/auth';
  993. $this->assertEqual($expected, $result);
  994. $expectedWebroot = '/demos/auth/';
  995. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  996. Configure::write('App.dir', 'code');
  997. $Dispatcher->base = false;
  998. $_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents';
  999. $_SERVER['SCRIPT_FILENAME'] = '/Library/WebServer/Documents/clients/PewterReport/code/webroot/index.php';
  1000. $_SERVER['PHP_SELF'] = '/clients/PewterReport/code/webroot/index.php';
  1001. $result = $Dispatcher->baseUrl();
  1002. $expected = '/clients/PewterReport/code';
  1003. $this->assertEqual($expected, $result);
  1004. $expectedWebroot = '/clients/PewterReport/code/';
  1005. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1006. }
  1007. /**
  1008. * testBaseUrlwithModRewriteAlias method
  1009. *
  1010. * @return void
  1011. * @access public
  1012. */
  1013. function testBaseUrlwithModRewriteAlias() {
  1014. $_SERVER['DOCUMENT_ROOT'] = '/home/aplusnur/public_html';
  1015. $_SERVER['SCRIPT_FILENAME'] = '/home/aplusnur/cake2/app/webroot/index.php';
  1016. $_SERVER['PHP_SELF'] = '/control/index.php';
  1017. Configure::write('App.base', '/control');
  1018. $Dispatcher =& new Dispatcher();
  1019. $result = $Dispatcher->baseUrl();
  1020. $expected = '/control';
  1021. $this->assertEqual($expected, $result);
  1022. $expectedWebroot = '/control/';
  1023. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1024. Configure::write('App.base', false);
  1025. Configure::write('App.dir', 'affiliate');
  1026. Configure::write('App.webroot', 'newaffiliate');
  1027. $_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html';
  1028. $_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php';
  1029. $_SERVER['PHP_SELF'] = '/newaffiliate/index.php';
  1030. $Dispatcher =& new Dispatcher();
  1031. $result = $Dispatcher->baseUrl();
  1032. $expected = '/newaffiliate';
  1033. $this->assertEqual($expected, $result);
  1034. $expectedWebroot = '/newaffiliate/';
  1035. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1036. }
  1037. /**
  1038. * testBaseUrlAndWebrootWithBaseUrl method
  1039. *
  1040. * @return void
  1041. * @access public
  1042. */
  1043. function testBaseUrlAndWebrootWithBaseUrl() {
  1044. $Dispatcher =& new Dispatcher();
  1045. Configure::write('App.dir', 'app');
  1046. Configure::write('App.baseUrl', '/app/webroot/index.php');
  1047. $result = $Dispatcher->baseUrl();
  1048. $expected = '/app/webroot/index.php';
  1049. $this->assertEqual($expected, $result);
  1050. $expectedWebroot = '/app/webroot/';
  1051. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1052. Configure::write('App.baseUrl', '/app/webroot/test.php');
  1053. $result = $Dispatcher->baseUrl();
  1054. $expected = '/app/webroot/test.php';
  1055. $this->assertEqual($expected, $result);
  1056. $expectedWebroot = '/app/webroot/';
  1057. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1058. Configure::write('App.baseUrl', '/app/index.php');
  1059. $result = $Dispatcher->baseUrl();
  1060. $expected = '/app/index.php';
  1061. $this->assertEqual($expected, $result);
  1062. $expectedWebroot = '/app/webroot/';
  1063. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1064. Configure::write('App.baseUrl', '/index.php');
  1065. $result = $Dispatcher->baseUrl();
  1066. $expected = '/index.php';
  1067. $this->assertEqual($expected, $result);
  1068. $expectedWebroot = '/app/webroot/';
  1069. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1070. Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
  1071. $result = $Dispatcher->baseUrl();
  1072. $expected = '/CakeBB/app/webroot/index.php';
  1073. $this->assertEqual($expected, $result);
  1074. $expectedWebroot = '/CakeBB/app/webroot/';
  1075. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1076. Configure::write('App.baseUrl', '/CakeBB/app/index.php');
  1077. $result = $Dispatcher->baseUrl();
  1078. $expected = '/CakeBB/app/index.php';
  1079. $this->assertEqual($expected, $result);
  1080. $expectedWebroot = '/CakeBB/app/webroot/';
  1081. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1082. Configure::write('App.baseUrl', '/CakeBB/index.php');
  1083. $result = $Dispatcher->baseUrl();
  1084. $expected = '/CakeBB/index.php';
  1085. $this->assertEqual($expected, $result);
  1086. $expectedWebroot = '/CakeBB/app/webroot/';
  1087. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1088. Configure::write('App.baseUrl', '/dbhauser/index.php');
  1089. $_SERVER['DOCUMENT_ROOT'] = '/kunden/homepages/4/d181710652/htdocs/joomla';
  1090. $_SERVER['SCRIPT_FILENAME'] = '/kunden/homepages/4/d181710652/htdocs/joomla/dbhauser/index.php';
  1091. $result = $Dispatcher->baseUrl();
  1092. $expected = '/dbhauser/index.php';
  1093. $this->assertEqual($expected, $result);
  1094. $expectedWebroot = '/dbhauser/app/webroot/';
  1095. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1096. }
  1097. /**
  1098. * Check that a sub-directory containing app|webroot doesn't get mishandled when re-writing is off.
  1099. *
  1100. * @return void
  1101. */
  1102. function testBaseUrlWithAppAndWebrootInDirname() {
  1103. Configure::write('App.baseUrl', '/approval/index.php');
  1104. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/';
  1105. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/approval/index.php';
  1106. $Dispatcher =& new Dispatcher();
  1107. $result = $Dispatcher->baseUrl();
  1108. $this->assertEqual('/approval/index.php', $result);
  1109. $this->assertEqual('/approval/app/webroot/', $Dispatcher->webroot);
  1110. Configure::write('App.baseUrl', '/webrootable/index.php');
  1111. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/';
  1112. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/webrootable/index.php';
  1113. $Dispatcher =& new Dispatcher();
  1114. $result = $Dispatcher->baseUrl();
  1115. $this->assertEqual('/webrootable/index.php', $result);
  1116. $this->assertEqual('/webrootable/app/webroot/', $Dispatcher->webroot);
  1117. }
  1118. /**
  1119. * test baseUrl with no rewrite and using the top level index.php.
  1120. *
  1121. * @return void
  1122. */
  1123. function testBaseUrlNoRewriteTopLevelIndex() {
  1124. $Dispatcher =& new Dispatcher();
  1125. Configure::write('App.baseUrl', '/index.php');
  1126. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev';
  1127. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/index.php';
  1128. $result = $Dispatcher->baseUrl();
  1129. $this->assertEqual('/index.php', $result);
  1130. $this->assertEqual('/app/webroot/', $Dispatcher->webroot);
  1131. $this->assertEqual('', $Dispatcher->base);
  1132. }
  1133. /**
  1134. * test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts.
  1135. *
  1136. * @return void
  1137. */
  1138. function testBaseUrlNoRewriteWebrootIndex() {
  1139. $Dispatcher =& new Dispatcher();
  1140. Configure::write('App.baseUrl', '/index.php');
  1141. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev/app/webroot';
  1142. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/app/webroot/index.php';
  1143. $result = $Dispatcher->baseUrl();
  1144. $this->assertEqual('/index.php', $result);
  1145. $this->assertEqual('/', $Dispatcher->webroot);
  1146. $this->assertEqual('', $Dispatcher->base);
  1147. }
  1148. /**
  1149. * testBaseUrlAndWebrootWithBase method
  1150. *
  1151. * @return void
  1152. * @access public
  1153. */
  1154. function testBaseUrlAndWebrootWithBase() {
  1155. $Dispatcher =& new Dispatcher();
  1156. $Dispatcher->base = '/app';
  1157. $result = $Dispatcher->baseUrl();
  1158. $expected = '/app';
  1159. $this->assertEqual($expected, $result);
  1160. $expectedWebroot = '/app/';
  1161. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1162. $Dispatcher->base = '';
  1163. $result = $Dispatcher->baseUrl();
  1164. $expected = '';
  1165. $this->assertEqual($expected, $result);
  1166. $expectedWebroot = '/';
  1167. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1168. Configure::write('App.dir', 'testbed');
  1169. $Dispatcher->base = '/cake/testbed/webroot';
  1170. $result = $Dispatcher->baseUrl();
  1171. $expected = '/cake/testbed/webroot';
  1172. $this->assertEqual($expected, $result);
  1173. $expectedWebroot = '/cake/testbed/webroot/';
  1174. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1175. }
  1176. /**
  1177. * testMissingController method
  1178. *
  1179. * @return void
  1180. * @access public
  1181. */
  1182. function testMissingController() {
  1183. $Dispatcher =& new TestDispatcher();
  1184. Configure::write('App.baseUrl', '/index.php');
  1185. $url = 'some_controller/home/param:value/param2:value2';
  1186. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1187. $expected = array('missingController', array(array(
  1188. 'className' => 'SomeControllerController',
  1189. 'webroot' => '/app/webroot/',
  1190. 'url' => 'some_controller/home/param:value/param2:value2',
  1191. 'base' => '/index.php'
  1192. )));
  1193. $this->assertEqual($expected, $controller);
  1194. }
  1195. /**
  1196. * testPrivate method
  1197. *
  1198. * @return void
  1199. * @access public
  1200. */
  1201. function testPrivate() {
  1202. $Dispatcher =& new TestDispatcher();
  1203. Configure::write('App.baseUrl','/index.php');
  1204. $url = 'some_pages/_protected/param:value/param2:value2';
  1205. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1206. $expected = array('privateAction', array(array(
  1207. 'className' => 'SomePagesController',
  1208. 'action' => '_protected',
  1209. 'webroot' => '/app/webroot/',
  1210. 'url' => 'some_pages/_protected/param:value/param2:value2',
  1211. 'base' => '/index.php'
  1212. )));
  1213. $this->assertEqual($controller, $expected);
  1214. }
  1215. /**
  1216. * testMissingAction method
  1217. *
  1218. * @return void
  1219. * @access public
  1220. */
  1221. function testMissingAction() {
  1222. $Dispatcher =& new TestDispatcher();
  1223. Configure::write('App.baseUrl', '/index.php');
  1224. $url = 'some_pages/home/param:value/param2:value2';
  1225. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1226. $expected = array('missingAction', array(array(
  1227. 'className' => 'SomePagesController',
  1228. 'action' => 'home',
  1229. 'webroot' => '/app/webroot/',
  1230. 'url' => '/index.php/some_pages/home/param:value/param2:value2',
  1231. 'base' => '/index.php'
  1232. )));
  1233. $this->assertEqual($expected, $controller);
  1234. $Dispatcher =& new TestDispatcher();
  1235. Configure::write('App.baseUrl','/index.php');
  1236. $url = 'some_pages/redirect/param:value/param2:value2';
  1237. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1238. $expected = array('missingAction', array(array(
  1239. 'className' => 'SomePagesController',
  1240. 'action' => 'redirect',
  1241. 'webroot' => '/app/webroot/',
  1242. 'url' => '/index.php/some_pages/redirect/param:value/param2:value2',
  1243. 'base' => '/index.php'
  1244. )));
  1245. $this->assertEqual($expected, $controller);
  1246. }
  1247. /**
  1248. * testDispatch method
  1249. *
  1250. * @return void
  1251. * @access public
  1252. */
  1253. function testDispatch() {
  1254. $Dispatcher =& new TestDispatcher();
  1255. Configure::write('App.baseUrl','/index.php');
  1256. $url = 'pages/home/param:value/param2:value2';
  1257. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1258. $expected = 'Pages';
  1259. $this->assertEqual($expected, $controller->name);
  1260. $expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
  1261. $this->assertIdentical($expected, $controller->passedArgs);
  1262. Configure::write('App.baseUrl','/pages/index.php');
  1263. $url = 'pages/home';
  1264. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1265. $expected = 'Pages';
  1266. $this->assertEqual($expected, $controller->name);
  1267. $url = 'pages/home/';
  1268. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1269. $this->assertNull($controller->plugin);
  1270. $this->assertNull($Dispatcher->params['plugin']);
  1271. $expected = 'Pages';
  1272. $this->assertEqual($expected, $controller->name);
  1273. unset($Dispatcher);
  1274. $Dispatcher =& new TestDispatcher();
  1275. Configure::write('App.baseUrl','/timesheets/index.php');
  1276. $url = 'timesheets';
  1277. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1278. $expected = 'Timesheets';
  1279. $this->assertEqual($expected, $controller->name);
  1280. $url = 'timesheets/';
  1281. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1282. $this->assertEqual('Timesheets', $controller->name);
  1283. $this->assertEqual('/timesheets/index.php', $Dispatcher->base);
  1284. $url = 'test_dispatch_pages/camelCased';
  1285. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1286. $this->assertEqual('TestDispatchPages', $controller->name);
  1287. $url = 'test_dispatch_pages/camelCased/something. .';
  1288. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1289. $this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s');
  1290. }
  1291. /**
  1292. * testDispatchWithArray method
  1293. *
  1294. * @return void
  1295. * @access public
  1296. */
  1297. function testDispatchWithArray() {
  1298. $Dispatcher =& new TestDispatcher();
  1299. $url = 'pages/home/param:value/param2:value2';
  1300. $url = array('controller' => 'pages', 'action' => 'display');
  1301. $controller = $Dispatcher->dispatch($url, array(
  1302. 'pass' => array('home'),
  1303. 'named' => array('param' => 'value', 'param2' => 'value2'),
  1304. 'return' => 1
  1305. ));
  1306. $expected = 'Pages';
  1307. $this->assertEqual($expected, $controller->name);
  1308. $expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
  1309. $this->assertIdentical($expected, $controller->passedArgs);
  1310. $this->assertEqual($Dispatcher->base . '/pages/display/home/param:value/param2:value2', $Dispatcher->here);
  1311. }
  1312. /**
  1313. * test that a garbage url doesn't cause errors.
  1314. *
  1315. * @return void
  1316. */
  1317. function testDispatchWithGarbageUrl() {
  1318. Configure::write('App.baseUrl', '/index.php');
  1319. $Dispatcher =& new TestDispatcher();
  1320. $url = 'http://google.com';
  1321. $result = $Dispatcher->dispatch($url);
  1322. $expected = array('missingController', array(array(
  1323. 'className' => 'Controller',
  1324. 'webroot' => '/app/webroot/',
  1325. 'url' => 'http://google.com',
  1326. 'base' => '/index.php'
  1327. )));
  1328. $this->assertEqual($expected, $result);
  1329. }
  1330. /**
  1331. * testAdminDispatch method
  1332. *
  1333. * @return void
  1334. * @access public
  1335. */
  1336. function testAdminDispatch() {
  1337. $_POST = array();
  1338. $Dispatcher =& new TestDispatcher();
  1339. Configure::write('Routing.prefixes', array('admin'));
  1340. Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php');
  1341. $url = 'admin/test_dispatch_pages/index/param:value/param2:value2';
  1342. Router::reload();
  1343. $Router =& Router::getInstance();
  1344. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1345. $this->assertEqual($controller->name, 'TestDispatchPages');
  1346. $this->assertIdentical($controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
  1347. $this->assertTrue($controller->params['admin']);
  1348. $expected = '/cake/repo/branches/1.2.x.x/index.php/admin/test_dispatch_pages/index/param:value/param2:value2';
  1349. $this->assertIdentical($expected, $controller->here);
  1350. $expected = '/cake/repo/branches/1.2.x.x/index.php';
  1351. $this->assertIdentical($expected, $controller->base);
  1352. }
  1353. /**
  1354. * testPluginDispatch method
  1355. *
  1356. * @return void
  1357. * @access public
  1358. */
  1359. function testPluginDispatch() {
  1360. $_POST = array();
  1361. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1362. Router::reload();
  1363. $Dispatcher =& new TestDispatcher();
  1364. Router::connect(
  1365. '/my_plugin/:controller/*',
  1366. array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
  1367. );
  1368. $Dispatcher->base = false;
  1369. $url = 'my_plugin/some_pages/home/param:value/param2:value2';
  1370. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1371. $result = $Dispatcher->parseParams($url);
  1372. $expected = array(
  1373. 'pass' => array('home'),
  1374. 'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
  1375. 'controller'=> 'some_pages', 'action'=> 'display', 'form'=> null,
  1376. 'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'),
  1377. );
  1378. ksort($expected);
  1379. ksort($result);
  1380. $this->assertEqual($expected, $result);
  1381. $this->assertIdentical($controller->plugin, 'my_plugin');
  1382. $this->assertIdentical($controller->name, 'SomePages');
  1383. $this->assertIdentical($controller->params['controller'], 'some_pages');
  1384. $this->assertIdentical($controller->passedArgs, array('0' => 'home', 'param'=>'value', 'param2'=>'value2'));
  1385. $expected = '/cake/repo/branches/1.2.x.x/my_plugin/some_pages/home/param:value/param2:value2';
  1386. $this->assertIdentical($expected, $controller->here);
  1387. $expected = '/cake/repo/branches/1.2.x.x';
  1388. $this->assertIdentical($expected, $controller->base);
  1389. }
  1390. /**
  1391. * testAutomaticPluginDispatch method
  1392. *
  1393. * @return void
  1394. * @access public
  1395. */
  1396. function testAutomaticPluginDispatch() {
  1397. $_POST = array();
  1398. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1399. Router::reload();
  1400. $Dispatcher =& new TestDispatcher();
  1401. Router::connect(
  1402. '/my_plugin/:controller/:action/*',
  1403. array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
  1404. );
  1405. $Dispatcher->base = false;
  1406. $url = 'my_plugin/other_pages/index/param:value/param2:value2';
  1407. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1408. $this->assertIdentical($controller->plugin, 'my_plugin');
  1409. $this->assertIdentical($controller->name, 'OtherPages');
  1410. $this->assertIdentical($controller->action, 'index');
  1411. $this->assertIdentical($controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
  1412. $expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2';
  1413. $this->assertIdentical($expected, $controller->here);
  1414. $expected = '/cake/repo/branches/1.2.x.x';
  1415. $this->assertIdentical($expected, $controller->base);
  1416. }
  1417. /**
  1418. * testAutomaticPluginControllerDispatch method
  1419. *
  1420. * @return void
  1421. * @access public
  1422. */
  1423. function testAutomaticPluginControllerDispatch() {
  1424. $_POST = array();
  1425. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1426. $plugins = App::objects('plugin');
  1427. $plugins[] = 'MyPlugin';
  1428. $plugins[] = 'ArticlesTest';
  1429. $app = App::getInstance();
  1430. $app->__objects['plugin'] = $plugins;
  1431. Router::reload();
  1432. $Dispatcher =& new TestDispatcher();
  1433. $Dispatcher->base = false;
  1434. $url = 'my_plugin/my_plugin/add/param:value/param2:value2';
  1435. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1436. $this->assertIdentical($controller->plugin, 'my_plugin');
  1437. $this->assertIdentical($controller->name, 'MyPlugin');
  1438. $this->assertIdentical($controller->action, 'add');
  1439. $this->assertEqual($controller->params['named'], array('param' => 'value', 'param2' => 'value2'));
  1440. Router::reload();
  1441. $Dispatcher =& new TestDispatcher();
  1442. $Dispatcher->base = false;
  1443. // Simulates the Route for a real plugin, installed in APP/plugins
  1444. Router::connect('/my_plugin/:controller/:action/*', array('plugin' => 'my_plugin'));
  1445. $plugin = 'MyPlugin';
  1446. $pluginUrl = Inflector::underscore($plugin);
  1447. $url = $pluginUrl;
  1448. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1449. $this->assertIdentical($controller->plugin, 'my_plugin');
  1450. $this->assertIdentical($controller->name, 'MyPlugin');
  1451. $this->assertIdentical($controller->action, 'index');
  1452. $expected = $pluginUrl;
  1453. $this->assertEqual($controller->params['controller'], $expected);
  1454. Configure::write('Routing.prefixes', array('admin'));
  1455. Router::reload();
  1456. $Dispatcher =& new TestDispatcher();
  1457. $Dispatcher->base = false;
  1458. $url = 'admin/my_plugin/my_plugin/add/5/param:value/param2:value2';
  1459. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1460. $this->assertEqual($controller->params['plugin'], 'my_plugin');
  1461. $this->assertEqual($controller->params['controller'], 'my_plugin');
  1462. $this->assertEqual($controller->params['action'], 'admin_add');
  1463. $this->assertEqual($controller->params['pass'], array(5));
  1464. $this->assertEqual($controller->params['named'], array('param' => 'value', 'param2' => 'value2'));
  1465. $this->assertIdentical($controller->plugin, 'my_plugin');
  1466. $this->assertIdentical($controller->name, 'MyPlugin');
  1467. $this->assertIdentical($controller->action, 'admin_add');
  1468. $expected = array(0 => 5, 'param'=>'value', 'param2'=>'value2');
  1469. $this->assertEqual($controller->passedArgs, $expected);
  1470. Configure::write('Routing.prefixes', array('admin'));
  1471. Router::reload();
  1472. $Dispatcher =& new TestDispatcher();
  1473. $Dispatcher->base = false;
  1474. $controller = $Dispatcher->dispatch('admin/articles_test', array('return' => 1));
  1475. $this->assertIdentical($controller->plugin, 'articles_test');
  1476. $this->assertIdentical($controller->name, 'ArticlesTest');
  1477. $this->assertIdentical($controller->action, 'admin_index');
  1478. $expected = array(
  1479. 'pass'=> array(),
  1480. 'named' => array(),
  1481. 'controller' => 'articles_test',
  1482. 'plugin' => 'articles_test',
  1483. 'action' => 'admin_index',
  1484. 'prefix' => 'admin',
  1485. 'admin' => true,
  1486. 'form' => array(),
  1487. 'url' => array('url' => 'admin/articles_test'),
  1488. 'return' => 1
  1489. );
  1490. $this->assertEqual($controller->params, $expected);
  1491. }
  1492. /**
  1493. * test Plugin dispatching without controller name and using
  1494. * plugin short form instead.
  1495. *
  1496. * @return void
  1497. * @access public
  1498. */
  1499. function testAutomaticPluginDispatchWithShortAccess() {
  1500. $_POST = array();
  1501. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1502. $plugins = App::objects('plugin');
  1503. $plugins[] = 'MyPlugin';
  1504. $app = App::getInstance();
  1505. $app->__objects['plugin'] = $plugins;
  1506. Router::reload();
  1507. $Dispatcher =& new TestDispatcher();
  1508. $Dispatcher->base = false;
  1509. $url = 'my_plugin/';
  1510. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1511. $this->assertEqual($controller->params['controller'], 'my_plugin');
  1512. $this->assertEqual($controller->params['plugin'], 'my_plugin');
  1513. $this->assertEqual($controller->params['action'], 'index');
  1514. $this->assertFalse(isset($controller->params['pass'][0]));
  1515. }
  1516. /**
  1517. * test plugin shortcut urls with controllers that need to be loaded,
  1518. * the above test uses a controller that has already been included.
  1519. *
  1520. * @return void
  1521. */
  1522. function testPluginShortCutUrlsWithControllerThatNeedsToBeLoaded() {
  1523. $loaded = class_exists('TestPluginController', false);
  1524. if ($this->skipIf($loaded, 'TestPluginController already loaded, this test will always pass, skipping %s')) {
  1525. return true;
  1526. }
  1527. Router::reload();
  1528. App::build(array(
  1529. 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
  1530. ), true);
  1531. App::objects('plugin', null, false);
  1532. $Dispatcher =& new TestDispatcher();
  1533. $Dispatcher->base = false;
  1534. $url = 'test_plugin/';
  1535. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1536. $this->assertEqual($controller->params['controller'], 'test_plugin');
  1537. $this->assertEqual($controller->params['plugin'], 'test_plugin');
  1538. $this->assertEqual($controller->params['action'], 'index');
  1539. $this->assertFalse(isset($controller->params['pass'][0]));
  1540. $url = '/test_plugin/tests/index';
  1541. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1542. $this->assertEqual($controller->params['controller'], 'tests');
  1543. $this->assertEqual($controller->params['plugin'], 'test_plugin');
  1544. $this->assertEqual($controller->params['action'], 'index');
  1545. $this->assertFalse(isset($controller->params['pass'][0]));
  1546. $url = '/test_plugin/tests/index/some_param';
  1547. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1548. $this->assertEqual($controller->params['controller'], 'tests');
  1549. $this->assertEqual($controller->params['plugin'], 'test_plugin');
  1550. $this->assertEqual($controller->params['action'], 'index');
  1551. $this->assertEqual($controller->params['pass'][0], 'some_param');
  1552. App::build();
  1553. }
  1554. /**
  1555. * testAutomaticPluginControllerMissingActionDispatch method
  1556. *
  1557. * @return void
  1558. * @access public
  1559. */
  1560. function testAutomaticPluginControllerMissingActionDispatch() {
  1561. $_POST = array();
  1562. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1563. Router::reload();
  1564. $Dispatcher =& new TestDispatcher();
  1565. $Dispatcher->base = false;
  1566. $url = 'my_plugin/not_here/param:value/param2:value2';
  1567. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1568. $expected = array('missingAction', array(array(
  1569. 'className' => 'MyPluginController',
  1570. 'action' => 'not_here',
  1571. 'webroot' => '/cake/repo/branches/1.2.x.x/',
  1572. 'url' => '/cake/repo/branches/1.2.x.x/my_plugin/not_here/param:value/param2:value2',
  1573. 'base' => '/cake/repo/branches/1.2.x.x'
  1574. )));
  1575. $this->assertIdentical($expected, $controller);
  1576. Router::reload();
  1577. $Dispatcher =& new TestDispatcher();
  1578. $Dispatcher->base = false;
  1579. $url = 'my_plugin/param:value/param2:value2';
  1580. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1581. $expected = array('missingAction', array(array(
  1582. 'className' => 'MyPluginController',
  1583. 'action' => 'param:value',
  1584. 'webroot' => '/cake/repo/branches/1.2.x.x/',
  1585. 'url' => '/cake/repo/branches/1.2.x.x/my_plugin/param:value/param2:value2',
  1586. 'base' => '/cake/repo/branches/1.2.x.x'
  1587. )));
  1588. $this->assertIdentical($expected, $controller);
  1589. }
  1590. /**
  1591. * testPrefixProtection method
  1592. *
  1593. * @return void
  1594. * @access public
  1595. */
  1596. function testPrefixProtection() {
  1597. $_POST = array();
  1598. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1599. Router::reload();
  1600. Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin'), array('controller', 'action'));
  1601. $Dispatcher =& new TestDispatcher();
  1602. $Dispatcher->base = false;
  1603. $url = 'test_dispatch_pages/admin_index/param:value/param2:value2';
  1604. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1605. $expected = array('privateAction', array(array(
  1606. 'className' => 'TestDispatchPagesController',
  1607. 'action' => 'admin_index',
  1608. 'webroot' => '/cake/repo/branches/1.2.x.x/',
  1609. 'url' => 'test_dispatch_pages/admin_index/param:value/param2:value2',
  1610. 'base' => '/cake/repo/branches/1.2.x.x'
  1611. )));
  1612. $this->assertIdentical($expected, $controller);
  1613. }
  1614. /**
  1615. * Test dispatching into the TestPlugin in the test_app
  1616. *
  1617. * @return void
  1618. * @access public
  1619. */
  1620. function testTestPluginDispatch() {
  1621. $Dispatcher =& new TestDispatcher();
  1622. App::build(array(
  1623. 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
  1624. ));
  1625. App::objects('plugin', null, false);
  1626. Router::reload();
  1627. Router::parse('/');
  1628. $url = '/test_plugin/tests/index';
  1629. $result = $Dispatcher->dispatch($url, array('return' => 1));
  1630. $this->assertTrue(class_exists('TestsController'));
  1631. $this->assertTrue(class_exists('TestPluginAppController'));
  1632. $this->assertTrue(class_exists('OtherComponentComponent'));
  1633. $this->assertTrue(class_exists('PluginsComponentComponent'));
  1634. $this->assertEqual($result->params['controller'], 'tests');
  1635. $this->assertEqual($result->params['plugin'], 'test_plugin');
  1636. $this->assertEqual($result->params['action'], 'index');
  1637. App::build();
  1638. }
  1639. /**
  1640. * testChangingParamsFromBeforeFilter method
  1641. *
  1642. * @return void
  1643. * @access public
  1644. */
  1645. function testChangingParamsFromBeforeFilter() {
  1646. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1647. $Dispatcher =& new TestDispatcher();
  1648. $url = 'some_posts/index/param:value/param2:value2';
  1649. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1650. $expected = array('missingAction', array(array(
  1651. 'className' => 'SomePostsController',
  1652. 'action' => 'view',
  1653. 'webroot' => '/cake/repo/branches/1.2.x.x/',
  1654. 'url' => '/cake/repo/branches/1.2.x.x/some_posts/index/param:value/param2:value2',
  1655. 'base' => '/cake/repo/branches/1.2.x.x'
  1656. )));
  1657. $this->assertEqual($expected, $controller);
  1658. $url = 'some_posts/something_else/param:value/param2:value2';
  1659. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1660. $expected = 'SomePosts';
  1661. $this->assertEqual($expected, $controller->name);
  1662. $expected = 'change';
  1663. $this->assertEqual($expected, $controller->action);
  1664. $expected = array('changed');
  1665. $this->assertIdentical($expected, $controller->params['pass']);
  1666. }
  1667. /**
  1668. * testStaticAssets method
  1669. *
  1670. * @return void
  1671. * @access public
  1672. */
  1673. function testAssets() {
  1674. Router::reload();
  1675. $Configure =& Configure::getInstance();
  1676. $Configure->__objects = null;
  1677. App::build(array(
  1678. 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
  1679. 'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS),
  1680. 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
  1681. ));
  1682. $Dispatcher =& new TestDispatcher();
  1683. $debug = Configure::read('debug');
  1684. Configure::write('debug', 0);
  1685. ob_start();
  1686. $Dispatcher->dispatch('theme/test_theme/../webroot/css/test_asset.css');
  1687. $result = ob_get_clean();
  1688. $this->assertFalse($result);
  1689. ob_start();
  1690. $Dispatcher->dispatch('theme/test_theme/pdfs');
  1691. $result = ob_get_clean();
  1692. $this->assertFalse($result);
  1693. ob_start();
  1694. $Dispatcher->dispatch('theme/test_theme/flash/theme_test.swf');
  1695. $result = ob_get_clean();
  1696. $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');
  1697. $this->assertEqual($file, $result);
  1698. $this->assertEqual('this is just a test to load swf file from the theme.', $result);
  1699. ob_start();
  1700. $Dispatcher->dispatch('theme/test_theme/pdfs/theme_test.pdf');
  1701. $result = ob_get_clean();
  1702. $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');
  1703. $this->assertEqual($file, $result);
  1704. $this->assertEqual('this is just a test to load pdf file from the theme.', $result);
  1705. ob_start();
  1706. $Dispatcher->dispatch('theme/test_theme/img/test.jpg');
  1707. $result = ob_get_clean();
  1708. $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');
  1709. $this->assertEqual($file, $result);
  1710. $Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/css/test_asset.css');
  1711. ob_start();
  1712. $Dispatcher->asset('theme/test_theme/css/test_asset.css');
  1713. $result = ob_get_clean();
  1714. $this->assertEqual('this is the test asset css file', $result);
  1715. $Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/js/theme.js');
  1716. ob_start();
  1717. $Dispatcher->asset('theme/test_theme/js/theme.js');
  1718. $result = ob_get_clean();
  1719. $this->assertEqual('root theme js file', $result);
  1720. $Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/js/one/theme_one.js');
  1721. ob_start();
  1722. $Dispatcher->asset('theme/test_theme/js/one/theme_one.js');
  1723. $result = ob_get_clean();
  1724. $this->assertEqual('nested theme js file', $result);
  1725. ob_start();
  1726. $Dispatcher->asset('test_plugin/root.js');
  1727. $result = ob_get_clean();
  1728. $expected = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'webroot' . DS . 'root.js');
  1729. $this->assertEqual($result, $expected);
  1730. ob_start();
  1731. $Dispatcher->dispatch('test_plugin/flash/plugin_test.swf');
  1732. $result = ob_get_clean();
  1733. $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');
  1734. $this->assertEqual($file, $result);
  1735. $this->assertEqual('this is just a test to load swf file from the plugin.', $result);
  1736. ob_start();
  1737. $Dispatcher->dispatch('test_plugin/pdfs/plugin_test.pdf');
  1738. $result = ob_get_clean();
  1739. $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');
  1740. $this->assertEqual($file, $result);
  1741. $this->assertEqual('this is just a test to load pdf file from the plugin.', $result);
  1742. ob_start();
  1743. $Dispatcher->asset('test_plugin/js/test_plugin/test.js');
  1744. $result = ob_get_clean();
  1745. $this->assertEqual('alert("Test App");', $result);
  1746. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/js/test_plugin/test.js');
  1747. ob_start();
  1748. $Dispatcher->asset('test_plugin/js/test_plugin/test.js');
  1749. $result = ob_get_clean();
  1750. $this->assertEqual('alert("Test App");', $result);
  1751. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css');
  1752. ob_start();
  1753. $Dispatcher->asset('test_plugin/css/test_plugin_asset.css');
  1754. $result = ob_get_clean();
  1755. $this->assertEqual('this is the test plugin asset css file', $result);
  1756. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/img/cake.icon.gif');
  1757. ob_start();
  1758. $Dispatcher->asset('test_plugin/img/cake.icon.gif');
  1759. $result = ob_get_clean();
  1760. $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');
  1761. $this->assertEqual($file, $result);
  1762. $Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/plugin_js.js');
  1763. ob_start();
  1764. $Dispatcher->asset('plugin_js/js/plugin_js.js');
  1765. $result = ob_get_clean();
  1766. $expected = "alert('win sauce');";
  1767. $this->assertEqual($result, $expected);
  1768. $Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/one/plugin_one.js');
  1769. ob_start();
  1770. $Dispatcher->asset('plugin_js/js/one/plugin_one.js');
  1771. $result = ob_get_clean();
  1772. $expected = "alert('plugin one nested js file');";
  1773. $this->assertEqual($result, $expected);
  1774. Configure::write('debug', $debug);
  1775. //reset the header content-type without page can render as plain text.
  1776. header('Content-type: text/html');
  1777. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/theme_one.htc');
  1778. ob_start();
  1779. $Dispatcher->asset('test_plugin/css/unknown.extension');
  1780. $result = ob_get_clean();
  1781. $this->assertEqual('Testing a file with unknown extension to mime mapping.', $result);
  1782. header('Content-type: text/html');
  1783. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/theme_one.htc');
  1784. ob_start();
  1785. $Dispatcher->asset('test_plugin/css/theme_one.htc');
  1786. $result = ob_get_clean();
  1787. $this->assertEqual('htc file', $result);
  1788. header('Content-type: text/html');
  1789. }
  1790. /**
  1791. * test that missing asset processors trigger a 404 with no response body.
  1792. *
  1793. * @return void
  1794. */
  1795. function testMissingAssetProcessor404() {
  1796. $Dispatcher =& new TestDispatcher();
  1797. Configure::write('Asset.filter', array(
  1798. 'js' => '',
  1799. 'css' => null
  1800. ));
  1801. $this->assertNoErrors();
  1802. ob_start();
  1803. $Dispatcher->asset('ccss/cake.generic.css');
  1804. $result = ob_get_clean();
  1805. $this->assertTrue($Dispatcher->stopped);
  1806. header('HTTP/1.1 200 Ok');
  1807. }
  1808. /**
  1809. * test that asset filters work for theme and plugin assets
  1810. *
  1811. * @return void
  1812. */
  1813. function testAssetFilterForThemeAndPlugins() {
  1814. $Dispatcher =& new TestDispatcher();
  1815. Configure::write('Asset.filter', array(
  1816. 'js' => '',
  1817. 'css' => ''
  1818. ));
  1819. $Dispatcher->asset('theme/test_theme/ccss/cake.generic.css');
  1820. $this->assertTrue($Dispatcher->stopped);
  1821. $Dispatcher->stopped = false;
  1822. $Dispatcher->asset('theme/test_theme/cjs/debug_kit.js');
  1823. $this->assertTrue($Dispatcher->stopped);
  1824. $Dispatcher->stopped = false;
  1825. $Dispatcher->asset('test_plugin/ccss/cake.generic.css');
  1826. $this->assertTrue($Dispatcher->stopped);
  1827. $Dispatcher->stopped = false;
  1828. $Dispatcher->asset('test_plugin/cjs/debug_kit.js');
  1829. $this->assertTrue($Dispatcher->stopped);
  1830. $Dispatcher->stopped = false;
  1831. $Dispatcher->asset('css/ccss/debug_kit.css');
  1832. $this->assertFalse($Dispatcher->stopped);
  1833. $Dispatcher->stopped = false;
  1834. $Dispatcher->asset('js/cjs/debug_kit.js');
  1835. $this->assertFalse($Dispatcher->stopped);
  1836. }
  1837. /**
  1838. * testFullPageCachingDispatch method
  1839. *
  1840. * @return void
  1841. * @access public
  1842. */
  1843. function testFullPageCachingDispatch() {
  1844. Configure::write('Cache.disable', false);
  1845. Configure::write('Cache.check', true);
  1846. Configure::write('debug', 2);
  1847. $_POST = array();
  1848. $_SERVER['PHP_SELF'] = '/';
  1849. Router::reload();
  1850. Router::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index'));
  1851. App::build(array(
  1852. 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
  1853. ), true);
  1854. $dispatcher =& new TestDispatcher();
  1855. $dispatcher->base = false;
  1856. $url = '/';
  1857. ob_start();
  1858. $dispatcher->dispatch($url);
  1859. $out = ob_get_clean();
  1860. ob_start();
  1861. $dispatcher->cached($url);
  1862. $cached = ob_get_clean();
  1863. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1864. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1865. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1866. $this->assertEqual($result, $expected);
  1867. $filename = $this->__cachePath($dispatcher->here);
  1868. unlink($filename);
  1869. $dispatcher->base = false;
  1870. $url = 'test_cached_pages/index';
  1871. ob_start();
  1872. $dispatcher->dispatch($url);
  1873. $out = ob_get_clean();
  1874. ob_start();
  1875. $dispatcher->cached($url);
  1876. $cached = ob_get_clean();
  1877. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1878. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1879. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1880. $this->assertEqual($result, $expected);
  1881. $filename = $this->__cachePath($dispatcher->here);
  1882. unlink($filename);
  1883. $url = 'TestCachedPages/index';
  1884. ob_start();
  1885. $dispatcher->dispatch($url);
  1886. $out = ob_get_clean();
  1887. ob_start();
  1888. $dispatcher->cached($url);
  1889. $cached = ob_get_clean();
  1890. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1891. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1892. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1893. $this->assertEqual($result, $expected);
  1894. $filename = $this->__cachePath($dispatcher->here);
  1895. unlink($filename);
  1896. $url = 'TestCachedPages/test_nocache_tags';
  1897. ob_start();
  1898. $dispatcher->dispatch($url);
  1899. $out = ob_get_clean();
  1900. ob_start();
  1901. $dispatcher->cached($url);
  1902. $cached = ob_get_clean();
  1903. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1904. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1905. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1906. $this->assertEqual($result, $expected);
  1907. $filename = $this->__cachePath($dispatcher->here);
  1908. unlink($filename);
  1909. $url = 'test_cached_pages/view/param/param';
  1910. ob_start();
  1911. $dispatcher->dispatch($url);
  1912. $out = ob_get_clean();
  1913. ob_start();
  1914. $dispatcher->cached($url);
  1915. $cached = ob_get_clean();
  1916. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1917. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1918. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1919. $this->assertEqual($result, $expected);
  1920. $filename = $this->__cachePath($dispatcher->here);
  1921. unlink($filename);
  1922. $url = 'test_cached_pages/view/foo:bar/value:goo';
  1923. ob_start();
  1924. $dispatcher->dispatch($url);
  1925. $out = ob_get_clean();
  1926. ob_start();
  1927. $dispatcher->cached($url);
  1928. $cached = ob_get_clean();
  1929. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1930. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1931. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1932. $this->assertEqual($result, $expected);
  1933. $filename = $this->__cachePath($dispatcher->here);
  1934. $this->assertTrue(file_exists($filename));
  1935. unlink($filename);
  1936. }
  1937. /**
  1938. * test that cached() registers a view and un-registers it. Tests
  1939. * that helpers using ClassRegistry::getObject('view'); don't fail
  1940. *
  1941. * @return void
  1942. */
  1943. function testCachedRegisteringViewObject() {
  1944. Configure::write('Cache.disable', false);
  1945. Configure::write('Cache.check', true);
  1946. Configure::write('debug', 2);
  1947. $_POST = array();
  1948. $_SERVER['PHP_SELF'] = '/';
  1949. Router::reload();
  1950. App::build(array(
  1951. 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
  1952. ));
  1953. $dispatcher =& new TestDispatcher();
  1954. $dispatcher->base = false;
  1955. $url = 'test_cached_pages/cache_form';
  1956. ob_start();
  1957. $dispatcher->dispatch($url);
  1958. $out = ob_get_clean();
  1959. ClassRegistry::flush();
  1960. ob_start();
  1961. $dispatcher->cached($url);
  1962. $cached = ob_get_clean();
  1963. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1964. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1965. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1966. $this->assertEqual($result, $expected);
  1967. $filename = $this->__cachePath($dispatcher->here);
  1968. @unlink($filename);
  1969. ClassRegistry::flush();
  1970. }
  1971. /**
  1972. * testHttpMethodOverrides method
  1973. *
  1974. * @return void
  1975. * @access public
  1976. */
  1977. function testHttpMethodOverrides() {
  1978. Router::reload();
  1979. Router::mapResources('Posts');
  1980. $_SERVER['REQUEST_METHOD'] = 'POST';
  1981. $dispatcher =& new Dispatcher();
  1982. $dispatcher->base = false;
  1983. $result = $dispatcher->parseParams('/posts');
  1984. $expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'form' => array(), 'url' => array());
  1985. $this->assertEqual($result, $expected);
  1986. $_SERVER['REQUEST_METHOD'] = 'GET';
  1987. $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
  1988. $result = $dispatcher->parseParams('/posts/5');
  1989. $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
  1990. $this->assertEqual($result, $expected);
  1991. unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
  1992. $_SERVER['REQUEST_METHOD'] = 'GET';
  1993. $result = $dispatcher->parseParams('/posts/5');
  1994. $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'form' => array(), 'url' => array());
  1995. $this->assertEqual($result, $expected);
  1996. $_POST['_method'] = 'PUT';
  1997. $result = $dispatcher->parseParams('/posts/5');
  1998. $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
  1999. $this->assertEqual($result, $expected);
  2000. $_POST['_method'] = 'POST';
  2001. $_POST['data'] = array('Post' => array('title' => 'New Post'));
  2002. $_POST['extra'] = 'data';
  2003. $_SERVER = array();
  2004. $result = $dispatcher->parseParams('/posts');
  2005. $expected = array(
  2006. 'pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add',
  2007. '[method]' => 'POST', 'form' => array('extra' => 'data'), 'data' => array('Post' => array('title' => 'New Post')),
  2008. 'url' => array()
  2009. );
  2010. $this->assertEqual($result, $expected);
  2011. unset($_POST['_method']);
  2012. }
  2013. /**
  2014. * Tests that invalid characters cannot be injected into the application base path.
  2015. *
  2016. * @return void
  2017. * @access public
  2018. */
  2019. function testBasePathInjection() {
  2020. $self = $_SERVER['PHP_SELF'];
  2021. $_SERVER['PHP_SELF'] = urldecode(
  2022. "/index.php/%22%3E%3Ch1%20onclick=%22alert('xss');%22%3Eheya%3C/h1%3E"
  2023. );
  2024. $dispatcher =& new Dispatcher();
  2025. $result = $dispatcher->baseUrl();
  2026. $expected = '/index.php/h1 onclick=alert(xss);heya';
  2027. $this->assertEqual($result, $expected);
  2028. }
  2029. /**
  2030. * testEnvironmentDetection method
  2031. *
  2032. * @return void
  2033. * @access public
  2034. */
  2035. function testEnvironmentDetection() {
  2036. $dispatcher =& new Dispatcher();
  2037. $environments = array(
  2038. 'IIS' => array(
  2039. 'No rewrite base path' => array(
  2040. 'App' => array('base' => false, 'baseUrl' => '/index.php?', 'server' => 'IIS'),
  2041. '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),
  2042. 'reload' => true,
  2043. 'path' => ''
  2044. ),
  2045. 'No rewrite with path' => array(
  2046. 'SERVER' => array('QUERY_STRING' => '/posts/add', 'REQUEST_URI' => '/index.php?/posts/add', 'URL' => '/index.php?/posts/add', 'argv' => array('/posts/add'), 'argc' => 1),
  2047. 'reload' => false,
  2048. 'path' => '/posts/add'
  2049. ),
  2050. 'No rewrite sub dir 1' => array(
  2051. 'GET' => array(),
  2052. '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),
  2053. 'reload' => false,
  2054. 'path' => ''
  2055. ),
  2056. 'No rewrite sub dir 1 with path' => array(
  2057. 'GET' => array('/posts/add' => ''),
  2058. '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),
  2059. 'reload' => false,
  2060. 'path' => '/posts/add'
  2061. ),
  2062. 'No rewrite sub dir 2' => array(
  2063. 'App' => array('base' => false, 'baseUrl' => '/site/index.php?', 'dir' => 'app', 'webroot' => 'webroot', 'server' => 'IIS'),
  2064. 'GET' => array(),
  2065. 'POST' => array(),
  2066. '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),
  2067. 'reload' => false,
  2068. 'path' => ''
  2069. ),
  2070. 'No rewrite sub dir 2 with path' => array(
  2071. 'GET' => array('/posts/add' => ''),
  2072. '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),
  2073. 'reload' => false,
  2074. 'path' => '/posts/add'
  2075. )
  2076. ),
  2077. 'Apache' => array(
  2078. 'No rewrite base path' => array(
  2079. 'App' => array('base' => false, 'baseUrl' => '/index.php', 'dir' => 'app', 'webroot' => 'webroot'),
  2080. 'SERVER' => array(
  2081. 'SERVER_NAME' => 'localhost',
  2082. 'SERVER_ADDR' => '::1',
  2083. 'SERVER_PORT' => '80',
  2084. 'REMOTE_ADDR' => '::1',
  2085. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot',
  2086. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
  2087. 'QUERY_STRING' => '',
  2088. 'REQUEST_URI' => '/',
  2089. 'SCRIPT_NAME' => '/index.php',
  2090. 'PHP_SELF' => '/index.php',
  2091. 'argv' => array(),
  2092. 'argc' => 0
  2093. ),
  2094. 'reload' => true,
  2095. 'path' => ''
  2096. ),
  2097. 'No rewrite with path' => array(
  2098. 'SERVER' => array(
  2099. 'HTTP_HOST' => 'localhost',
  2100. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot',
  2101. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/officespace/app/webroot/index.php',
  2102. 'QUERY_STRING' => '',
  2103. 'REQUEST_URI' => '/index.php/posts/add',
  2104. 'SCRIPT_NAME' => '/index.php',
  2105. 'PATH_INFO' => '/posts/add',
  2106. 'PHP_SELF' => '/index.php/posts/add',
  2107. 'argv' => array(),
  2108. 'argc' => 0),
  2109. 'reload' => false,
  2110. 'path' => '/posts/add'
  2111. ),
  2112. 'GET Request at base domain' => array(
  2113. 'App' => array('base' => false, 'baseUrl' => null, 'dir' => 'app', 'webroot' => 'webroot'),
  2114. 'SERVER' => array(
  2115. 'HTTP_HOST' => 'cake.1.2',
  2116. 'SERVER_NAME' => 'cake.1.2',
  2117. 'SERVER_ADDR' => '127.0.0.1',
  2118. 'SERVER_PORT' => '80',
  2119. 'REMOTE_ADDR' => '127.0.0.1',
  2120. 'DOCUMENT_ROOT' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot',
  2121. 'SCRIPT_FILENAME' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot/index.php',
  2122. 'REMOTE_PORT' => '53550',
  2123. 'QUERY_STRING' => 'a=b',
  2124. 'REQUEST_URI' => '/?a=b',
  2125. 'SCRIPT_NAME' => '/index.php',
  2126. 'PHP_SELF' => '/index.php'
  2127. ),
  2128. 'GET' => array('a' => 'b'),
  2129. 'POST' => array(),
  2130. 'reload' => true,
  2131. 'path' => '',
  2132. 'urlParams' => array('a' => 'b'),
  2133. 'environment' => array('CGI_MODE' => false)
  2134. ),
  2135. 'New CGI no mod_rewrite' => array(
  2136. 'App' => array('base' => false, 'baseUrl' => '/limesurvey20/index.php', 'dir' => 'app', 'webroot' => 'webroot'),
  2137. 'SERVER' => array(
  2138. 'DOCUMENT_ROOT' => '/home/.sites/110/site313/web',
  2139. 'PATH_INFO' => '/installations',
  2140. 'PATH_TRANSLATED' => '/home/.sites/110/site313/web/limesurvey20/index.php',
  2141. 'PHPRC' => '/home/.sites/110/site313',
  2142. 'QUERY_STRING' => '',
  2143. 'REQUEST_URI' => '/limesurvey20/index.php/installations',
  2144. 'SCRIPT_FILENAME' => '/home/.sites/110/site313/web/limesurvey20/index.php',
  2145. 'SCRIPT_NAME' => '/limesurvey20/index.php',
  2146. 'SCRIPT_URI' => 'http://www.gisdat-umfragen.at/limesurvey20/index.php/installations',
  2147. 'PHP_SELF' => '/limesurvey20/index.php/installations',
  2148. 'CGI_MODE' => true
  2149. ),
  2150. 'GET' => array(),
  2151. 'POST' => array(),
  2152. 'reload' => true,
  2153. 'path' => '/installations',
  2154. 'urlParams' => array(),
  2155. 'environment' => array('CGI_MODE' => true)
  2156. )
  2157. )
  2158. );
  2159. $backup = $this->__backupEnvironment();
  2160. foreach ($environments as $name => $env) {
  2161. foreach ($env as $descrip => $settings) {
  2162. if ($settings['reload']) {
  2163. $this->__reloadEnvironment();
  2164. }
  2165. $this->__loadEnvironment($settings);
  2166. $this->assertEqual($dispatcher->uri(), $settings['path'], "%s on environment: {$name}, on setting: {$descrip}");
  2167. if (isset($settings['urlParams'])) {
  2168. $this->assertEqual($_GET, $settings['urlParams'], "%s on environment: {$name}, on setting: {$descrip}");
  2169. }
  2170. if (isset($settings['environment'])) {
  2171. foreach ($settings['environment'] as $key => $val) {
  2172. $this->assertEqual(env($key), $val, "%s on key {$key} on environment: {$name}, on setting: {$descrip}");
  2173. }
  2174. }
  2175. }
  2176. }
  2177. $this->__loadEnvironment(array_merge(array('reload' => true), $backup));
  2178. }
  2179. /**
  2180. * Tests that the Dispatcher does not return an empty action
  2181. *
  2182. * @return void
  2183. * @access public
  2184. */
  2185. function testTrailingSlash() {
  2186. $_POST = array();
  2187. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  2188. Router::reload();
  2189. $Dispatcher =& new TestDispatcher();
  2190. Router::connect('/myalias/:action/*', array('controller' => 'my_controller', 'action' => null));
  2191. $Dispatcher->base = false;
  2192. $url = 'myalias/'; //Fails
  2193. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  2194. $result = $Dispatcher->parseParams($url);
  2195. $this->assertEqual('index', $result['action']);
  2196. $url = 'myalias'; //Passes
  2197. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  2198. $result = $Dispatcher->parseParams($url);
  2199. $this->assertEqual('index', $result['action']);
  2200. }
  2201. /**
  2202. * backupEnvironment method
  2203. *
  2204. * @return void
  2205. * @access private
  2206. */
  2207. function __backupEnvironment() {
  2208. return array(
  2209. 'App' => Configure::read('App'),
  2210. 'GET' => $_GET,
  2211. 'POST' => $_POST,
  2212. 'SERVER'=> $_SERVER
  2213. );
  2214. }
  2215. /**
  2216. * reloadEnvironment method
  2217. *
  2218. * @return void
  2219. * @access private
  2220. */
  2221. function __reloadEnvironment() {
  2222. foreach ($_GET as $key => $val) {
  2223. unset($_GET[$key]);
  2224. }
  2225. foreach ($_POST as $key => $val) {
  2226. unset($_POST[$key]);
  2227. }
  2228. foreach ($_SERVER as $key => $val) {
  2229. unset($_SERVER[$key]);
  2230. }
  2231. Configure::write('App', array());
  2232. }
  2233. /**
  2234. * loadEnvironment method
  2235. *
  2236. * @param mixed $env
  2237. * @return void
  2238. * @access private
  2239. */
  2240. function __loadEnvironment($env) {
  2241. if ($env['reload']) {
  2242. $this->__reloadEnvironment();
  2243. }
  2244. if (isset($env['App'])) {
  2245. Configure::write('App', $env['App']);
  2246. }
  2247. if (isset($env['GET'])) {
  2248. foreach ($env['GET'] as $key => $val) {
  2249. $_GET[$key] = $val;
  2250. }
  2251. }
  2252. if (isset($env['POST'])) {
  2253. foreach ($env['POST'] as $key => $val) {
  2254. $_POST[$key] = $val;
  2255. }
  2256. }
  2257. if (isset($env['SERVER'])) {
  2258. foreach ($env['SERVER'] as $key => $val) {
  2259. $_SERVER[$key] = $val;
  2260. }
  2261. }
  2262. }
  2263. /**
  2264. * cachePath method
  2265. *
  2266. * @param mixed $her
  2267. * @return string
  2268. * @access private
  2269. */
  2270. function __cachePath($here) {
  2271. $path = $here;
  2272. if ($here == '/') {
  2273. $path = 'home';
  2274. }
  2275. $path = strtolower(Inflector::slug($path));
  2276. $filename = CACHE . 'views' . DS . $path . '.php';
  2277. if (!file_exists($filename)) {
  2278. $filename = CACHE . 'views' . DS . $path . '_index.php';
  2279. }
  2280. return $filename;
  2281. }
  2282. }