PageRenderTime 54ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/code/ryzom/tools/server/www/webtt/cake/tests/cases/dispatcher.test.php

https://bitbucket.org/mattraykowski/ryzomcore_demoshard
PHP | 2600 lines | 1626 code | 339 blank | 635 comment | 18 complexity | 71ef4d14aa2ec702da0881f3f167e5ef MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, LGPL-2.1
  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-2010, 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-2010, 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. * test baseUrl with no rewrite and using the top level index.php.
  1099. *
  1100. * @return void
  1101. */
  1102. function testBaseUrlNoRewriteTopLevelIndex() {
  1103. $Dispatcher =& new Dispatcher();
  1104. Configure::write('App.baseUrl', '/index.php');
  1105. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev';
  1106. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/index.php';
  1107. $result = $Dispatcher->baseUrl();
  1108. $this->assertEqual('/index.php', $result);
  1109. $this->assertEqual('/app/webroot/', $Dispatcher->webroot);
  1110. $this->assertEqual('', $Dispatcher->base);
  1111. }
  1112. /**
  1113. * test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts.
  1114. *
  1115. * @return void
  1116. */
  1117. function testBaseUrlNoRewriteWebrootIndex() {
  1118. $Dispatcher =& new Dispatcher();
  1119. Configure::write('App.baseUrl', '/index.php');
  1120. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev/app/webroot';
  1121. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/app/webroot/index.php';
  1122. $result = $Dispatcher->baseUrl();
  1123. $this->assertEqual('/index.php', $result);
  1124. $this->assertEqual('/', $Dispatcher->webroot);
  1125. $this->assertEqual('', $Dispatcher->base);
  1126. }
  1127. /**
  1128. * testBaseUrlAndWebrootWithBase method
  1129. *
  1130. * @return void
  1131. * @access public
  1132. */
  1133. function testBaseUrlAndWebrootWithBase() {
  1134. $Dispatcher =& new Dispatcher();
  1135. $Dispatcher->base = '/app';
  1136. $result = $Dispatcher->baseUrl();
  1137. $expected = '/app';
  1138. $this->assertEqual($expected, $result);
  1139. $expectedWebroot = '/app/';
  1140. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1141. $Dispatcher->base = '';
  1142. $result = $Dispatcher->baseUrl();
  1143. $expected = '';
  1144. $this->assertEqual($expected, $result);
  1145. $expectedWebroot = '/';
  1146. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1147. Configure::write('App.dir', 'testbed');
  1148. $Dispatcher->base = '/cake/testbed/webroot';
  1149. $result = $Dispatcher->baseUrl();
  1150. $expected = '/cake/testbed/webroot';
  1151. $this->assertEqual($expected, $result);
  1152. $expectedWebroot = '/cake/testbed/webroot/';
  1153. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1154. }
  1155. /**
  1156. * testMissingController method
  1157. *
  1158. * @return void
  1159. * @access public
  1160. */
  1161. function testMissingController() {
  1162. $Dispatcher =& new TestDispatcher();
  1163. Configure::write('App.baseUrl', '/index.php');
  1164. $url = 'some_controller/home/param:value/param2:value2';
  1165. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1166. $expected = array('missingController', array(array(
  1167. 'className' => 'SomeControllerController',
  1168. 'webroot' => '/app/webroot/',
  1169. 'url' => 'some_controller/home/param:value/param2:value2',
  1170. 'base' => '/index.php'
  1171. )));
  1172. $this->assertEqual($expected, $controller);
  1173. }
  1174. /**
  1175. * testPrivate method
  1176. *
  1177. * @return void
  1178. * @access public
  1179. */
  1180. function testPrivate() {
  1181. $Dispatcher =& new TestDispatcher();
  1182. Configure::write('App.baseUrl','/index.php');
  1183. $url = 'some_pages/_protected/param:value/param2:value2';
  1184. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1185. $expected = array('privateAction', array(array(
  1186. 'className' => 'SomePagesController',
  1187. 'action' => '_protected',
  1188. 'webroot' => '/app/webroot/',
  1189. 'url' => 'some_pages/_protected/param:value/param2:value2',
  1190. 'base' => '/index.php'
  1191. )));
  1192. $this->assertEqual($controller, $expected);
  1193. }
  1194. /**
  1195. * testMissingAction method
  1196. *
  1197. * @return void
  1198. * @access public
  1199. */
  1200. function testMissingAction() {
  1201. $Dispatcher =& new TestDispatcher();
  1202. Configure::write('App.baseUrl', '/index.php');
  1203. $url = 'some_pages/home/param:value/param2:value2';
  1204. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1205. $expected = array('missingAction', array(array(
  1206. 'className' => 'SomePagesController',
  1207. 'action' => 'home',
  1208. 'webroot' => '/app/webroot/',
  1209. 'url' => '/index.php/some_pages/home/param:value/param2:value2',
  1210. 'base' => '/index.php'
  1211. )));
  1212. $this->assertEqual($expected, $controller);
  1213. $Dispatcher =& new TestDispatcher();
  1214. Configure::write('App.baseUrl','/index.php');
  1215. $url = 'some_pages/redirect/param:value/param2:value2';
  1216. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1217. $expected = array('missingAction', array(array(
  1218. 'className' => 'SomePagesController',
  1219. 'action' => 'redirect',
  1220. 'webroot' => '/app/webroot/',
  1221. 'url' => '/index.php/some_pages/redirect/param:value/param2:value2',
  1222. 'base' => '/index.php'
  1223. )));
  1224. $this->assertEqual($expected, $controller);
  1225. }
  1226. /**
  1227. * testDispatch method
  1228. *
  1229. * @return void
  1230. * @access public
  1231. */
  1232. function testDispatch() {
  1233. $Dispatcher =& new TestDispatcher();
  1234. Configure::write('App.baseUrl','/index.php');
  1235. $url = 'pages/home/param:value/param2:value2';
  1236. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1237. $expected = 'Pages';
  1238. $this->assertEqual($expected, $controller->name);
  1239. $expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
  1240. $this->assertIdentical($expected, $controller->passedArgs);
  1241. Configure::write('App.baseUrl','/pages/index.php');
  1242. $url = 'pages/home';
  1243. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1244. $expected = 'Pages';
  1245. $this->assertEqual($expected, $controller->name);
  1246. $url = 'pages/home/';
  1247. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1248. $this->assertNull($controller->plugin);
  1249. $this->assertNull($Dispatcher->params['plugin']);
  1250. $expected = 'Pages';
  1251. $this->assertEqual($expected, $controller->name);
  1252. unset($Dispatcher);
  1253. $Dispatcher =& new TestDispatcher();
  1254. Configure::write('App.baseUrl','/timesheets/index.php');
  1255. $url = 'timesheets';
  1256. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1257. $expected = 'Timesheets';
  1258. $this->assertEqual($expected, $controller->name);
  1259. $url = 'timesheets/';
  1260. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1261. $this->assertEqual('Timesheets', $controller->name);
  1262. $this->assertEqual('/timesheets/index.php', $Dispatcher->base);
  1263. $url = 'test_dispatch_pages/camelCased';
  1264. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1265. $this->assertEqual('TestDispatchPages', $controller->name);
  1266. $url = 'test_dispatch_pages/camelCased/something. .';
  1267. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1268. $this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s');
  1269. }
  1270. /**
  1271. * testDispatchWithArray method
  1272. *
  1273. * @return void
  1274. * @access public
  1275. */
  1276. function testDispatchWithArray() {
  1277. $Dispatcher =& new TestDispatcher();
  1278. $url = 'pages/home/param:value/param2:value2';
  1279. $url = array('controller' => 'pages', 'action' => 'display');
  1280. $controller = $Dispatcher->dispatch($url, array(
  1281. 'pass' => array('home'),
  1282. 'named' => array('param' => 'value', 'param2' => 'value2'),
  1283. 'return' => 1
  1284. ));
  1285. $expected = 'Pages';
  1286. $this->assertEqual($expected, $controller->name);
  1287. $expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
  1288. $this->assertIdentical($expected, $controller->passedArgs);
  1289. $this->assertEqual($Dispatcher->base . '/pages/display/home/param:value/param2:value2', $Dispatcher->here);
  1290. }
  1291. /**
  1292. * test that a garbage url doesn't cause errors.
  1293. *
  1294. * @return void
  1295. */
  1296. function testDispatchWithGarbageUrl() {
  1297. Configure::write('App.baseUrl', '/index.php');
  1298. $Dispatcher =& new TestDispatcher();
  1299. $url = 'http://google.com';
  1300. $result = $Dispatcher->dispatch($url);
  1301. $expected = array('missingController', array(array(
  1302. 'className' => 'Controller',
  1303. 'webroot' => '/app/webroot/',
  1304. 'url' => 'http://google.com',
  1305. 'base' => '/index.php'
  1306. )));
  1307. $this->assertEqual($expected, $result);
  1308. }
  1309. /**
  1310. * testAdminDispatch method
  1311. *
  1312. * @return void
  1313. * @access public
  1314. */
  1315. function testAdminDispatch() {
  1316. $_POST = array();
  1317. $Dispatcher =& new TestDispatcher();
  1318. Configure::write('Routing.prefixes', array('admin'));
  1319. Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php');
  1320. $url = 'admin/test_dispatch_pages/index/param:value/param2:value2';
  1321. Router::reload();
  1322. $Router =& Router::getInstance();
  1323. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1324. $this->assertEqual($controller->name, 'TestDispatchPages');
  1325. $this->assertIdentical($controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
  1326. $this->assertTrue($controller->params['admin']);
  1327. $expected = '/cake/repo/branches/1.2.x.x/index.php/admin/test_dispatch_pages/index/param:value/param2:value2';
  1328. $this->assertIdentical($expected, $controller->here);
  1329. $expected = '/cake/repo/branches/1.2.x.x/index.php';
  1330. $this->assertIdentical($expected, $controller->base);
  1331. }
  1332. /**
  1333. * testPluginDispatch method
  1334. *
  1335. * @return void
  1336. * @access public
  1337. */
  1338. function testPluginDispatch() {
  1339. $_POST = array();
  1340. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1341. Router::reload();
  1342. $Dispatcher =& new TestDispatcher();
  1343. Router::connect(
  1344. '/my_plugin/:controller/*',
  1345. array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
  1346. );
  1347. $Dispatcher->base = false;
  1348. $url = 'my_plugin/some_pages/home/param:value/param2:value2';
  1349. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1350. $result = $Dispatcher->parseParams($url);
  1351. $expected = array(
  1352. 'pass' => array('home'),
  1353. 'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
  1354. 'controller'=> 'some_pages', 'action'=> 'display', 'form'=> null,
  1355. 'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'),
  1356. );
  1357. ksort($expected);
  1358. ksort($result);
  1359. $this->assertEqual($expected, $result);
  1360. $this->assertIdentical($controller->plugin, 'my_plugin');
  1361. $this->assertIdentical($controller->name, 'SomePages');
  1362. $this->assertIdentical($controller->params['controller'], 'some_pages');
  1363. $this->assertIdentical($controller->passedArgs, array('0' => 'home', 'param'=>'value', 'param2'=>'value2'));
  1364. $expected = '/cake/repo/branches/1.2.x.x/my_plugin/some_pages/home/param:value/param2:value2';
  1365. $this->assertIdentical($expected, $controller->here);
  1366. $expected = '/cake/repo/branches/1.2.x.x';
  1367. $this->assertIdentical($expected, $controller->base);
  1368. }
  1369. /**
  1370. * testAutomaticPluginDispatch method
  1371. *
  1372. * @return void
  1373. * @access public
  1374. */
  1375. function testAutomaticPluginDispatch() {
  1376. $_POST = array();
  1377. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1378. Router::reload();
  1379. $Dispatcher =& new TestDispatcher();
  1380. Router::connect(
  1381. '/my_plugin/:controller/:action/*',
  1382. array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
  1383. );
  1384. $Dispatcher->base = false;
  1385. $url = 'my_plugin/other_pages/index/param:value/param2:value2';
  1386. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1387. $this->assertIdentical($controller->plugin, 'my_plugin');
  1388. $this->assertIdentical($controller->name, 'OtherPages');
  1389. $this->assertIdentical($controller->action, 'index');
  1390. $this->assertIdentical($controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
  1391. $expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2';
  1392. $this->assertIdentical($expected, $controller->here);
  1393. $expected = '/cake/repo/branches/1.2.x.x';
  1394. $this->assertIdentical($expected, $controller->base);
  1395. }
  1396. /**
  1397. * testAutomaticPluginControllerDispatch method
  1398. *
  1399. * @return void
  1400. * @access public
  1401. */
  1402. function testAutomaticPluginControllerDispatch() {
  1403. $_POST = array();
  1404. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1405. $plugins = App::objects('plugin');
  1406. $plugins[] = 'MyPlugin';
  1407. $plugins[] = 'ArticlesTest';
  1408. $app = App::getInstance();
  1409. $app->__objects['plugin'] = $plugins;
  1410. Router::reload();
  1411. $Dispatcher =& new TestDispatcher();
  1412. $Dispatcher->base = false;
  1413. $url = 'my_plugin/my_plugin/add/param:value/param2:value2';
  1414. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1415. $this->assertIdentical($controller->plugin, 'my_plugin');
  1416. $this->assertIdentical($controller->name, 'MyPlugin');
  1417. $this->assertIdentical($controller->action, 'add');
  1418. $this->assertEqual($controller->params['named'], array('param' => 'value', 'param2' => 'value2'));
  1419. Router::reload();
  1420. $Dispatcher =& new TestDispatcher();
  1421. $Dispatcher->base = false;
  1422. // Simulates the Route for a real plugin, installed in APP/plugins
  1423. Router::connect('/my_plugin/:controller/:action/*', array('plugin' => 'my_plugin'));
  1424. $plugin = 'MyPlugin';
  1425. $pluginUrl = Inflector::underscore($plugin);
  1426. $url = $pluginUrl;
  1427. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1428. $this->assertIdentical($controller->plugin, 'my_plugin');
  1429. $this->assertIdentical($controller->name, 'MyPlugin');
  1430. $this->assertIdentical($controller->action, 'index');
  1431. $expected = $pluginUrl;
  1432. $this->assertEqual($controller->params['controller'], $expected);
  1433. Configure::write('Routing.prefixes', array('admin'));
  1434. Router::reload();
  1435. $Dispatcher =& new TestDispatcher();
  1436. $Dispatcher->base = false;
  1437. $url = 'admin/my_plugin/my_plugin/add/5/param:value/param2:value2';
  1438. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1439. $this->assertEqual($controller->params['plugin'], 'my_plugin');
  1440. $this->assertEqual($controller->params['controller'], 'my_plugin');
  1441. $this->assertEqual($controller->params['action'], 'admin_add');
  1442. $this->assertEqual($controller->params['pass'], array(5));
  1443. $this->assertEqual($controller->params['named'], array('param' => 'value', 'param2' => 'value2'));
  1444. $this->assertIdentical($controller->plugin, 'my_plugin');
  1445. $this->assertIdentical($controller->name, 'MyPlugin');
  1446. $this->assertIdentical($controller->action, 'admin_add');
  1447. $expected = array(0 => 5, 'param'=>'value', 'param2'=>'value2');
  1448. $this->assertEqual($controller->passedArgs, $expected);
  1449. Configure::write('Routing.prefixes', array('admin'));
  1450. Router::reload();
  1451. $Dispatcher =& new TestDispatcher();
  1452. $Dispatcher->base = false;
  1453. $controller = $Dispatcher->dispatch('admin/articles_test', array('return' => 1));
  1454. $this->assertIdentical($controller->plugin, 'articles_test');
  1455. $this->assertIdentical($controller->name, 'ArticlesTest');
  1456. $this->assertIdentical($controller->action, 'admin_index');
  1457. $expected = array(
  1458. 'pass'=> array(),
  1459. 'named' => array(),
  1460. 'controller' => 'articles_test',
  1461. 'plugin' => 'articles_test',
  1462. 'action' => 'admin_index',
  1463. 'prefix' => 'admin',
  1464. 'admin' => true,
  1465. 'form' => array(),
  1466. 'url' => array('url' => 'admin/articles_test'),
  1467. 'return' => 1
  1468. );
  1469. $this->assertEqual($controller->params, $expected);
  1470. }
  1471. /**
  1472. * test Plugin dispatching without controller name and using
  1473. * plugin short form instead.
  1474. *
  1475. * @return void
  1476. * @access public
  1477. */
  1478. function testAutomaticPluginDispatchWithShortAccess() {
  1479. $_POST = array();
  1480. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1481. $plugins = App::objects('plugin');
  1482. $plugins[] = 'MyPlugin';
  1483. $app = App::getInstance();
  1484. $app->__objects['plugin'] = $plugins;
  1485. Router::reload();
  1486. $Dispatcher =& new TestDispatcher();
  1487. $Dispatcher->base = false;
  1488. $url = 'my_plugin/';
  1489. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1490. $this->assertEqual($controller->params['controller'], 'my_plugin');
  1491. $this->assertEqual($controller->params['plugin'], 'my_plugin');
  1492. $this->assertEqual($controller->params['action'], 'index');
  1493. $this->assertFalse(isset($controller->params['pass'][0]));
  1494. }
  1495. /**
  1496. * test plugin shortcut urls with controllers that need to be loaded,
  1497. * the above test uses a controller that has already been included.
  1498. *
  1499. * @return void
  1500. */
  1501. function testPluginShortCutUrlsWithControllerThatNeedsToBeLoaded() {
  1502. $loaded = class_exists('TestPluginController', false);
  1503. if ($this->skipIf($loaded, 'TestPluginController already loaded, this test will always pass, skipping %s')) {
  1504. return true;
  1505. }
  1506. Router::reload();
  1507. App::build(array(
  1508. 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
  1509. ), true);
  1510. App::objects('plugin', null, false);
  1511. $Dispatcher =& new TestDispatcher();
  1512. $Dispatcher->base = false;
  1513. $url = 'test_plugin/';
  1514. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1515. $this->assertEqual($controller->params['controller'], 'test_plugin');
  1516. $this->assertEqual($controller->params['plugin'], 'test_plugin');
  1517. $this->assertEqual($controller->params['action'], 'index');
  1518. $this->assertFalse(isset($controller->params['pass'][0]));
  1519. $url = '/test_plugin/tests/index';
  1520. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1521. $this->assertEqual($controller->params['controller'], 'tests');
  1522. $this->assertEqual($controller->params['plugin'], 'test_plugin');
  1523. $this->assertEqual($controller->params['action'], 'index');
  1524. $this->assertFalse(isset($controller->params['pass'][0]));
  1525. $url = '/test_plugin/tests/index/some_param';
  1526. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1527. $this->assertEqual($controller->params['controller'], 'tests');
  1528. $this->assertEqual($controller->params['plugin'], 'test_plugin');
  1529. $this->assertEqual($controller->params['action'], 'index');
  1530. $this->assertEqual($controller->params['pass'][0], 'some_param');
  1531. App::build();
  1532. }
  1533. /**
  1534. * testAutomaticPluginControllerMissingActionDispatch method
  1535. *
  1536. * @return void
  1537. * @access public
  1538. */
  1539. function testAutomaticPluginControllerMissingActionDispatch() {
  1540. $_POST = array();
  1541. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1542. Router::reload();
  1543. $Dispatcher =& new TestDispatcher();
  1544. $Dispatcher->base = false;
  1545. $url = 'my_plugin/not_here/param:value/param2:value2';
  1546. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1547. $expected = array('missingAction', array(array(
  1548. 'className' => 'MyPluginController',
  1549. 'action' => 'not_here',
  1550. 'webroot' => '/cake/repo/branches/1.2.x.x/',
  1551. 'url' => '/cake/repo/branches/1.2.x.x/my_plugin/not_here/param:value/param2:value2',
  1552. 'base' => '/cake/repo/branches/1.2.x.x'
  1553. )));
  1554. $this->assertIdentical($expected, $controller);
  1555. Router::reload();
  1556. $Dispatcher =& new TestDispatcher();
  1557. $Dispatcher->base = false;
  1558. $url = 'my_plugin/param:value/param2:value2';
  1559. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1560. $expected = array('missingAction', array(array(
  1561. 'className' => 'MyPluginController',
  1562. 'action' => 'param:value',
  1563. 'webroot' => '/cake/repo/branches/1.2.x.x/',
  1564. 'url' => '/cake/repo/branches/1.2.x.x/my_plugin/param:value/param2:value2',
  1565. 'base' => '/cake/repo/branches/1.2.x.x'
  1566. )));
  1567. $this->assertIdentical($expected, $controller);
  1568. }
  1569. /**
  1570. * testPrefixProtection method
  1571. *
  1572. * @return void
  1573. * @access public
  1574. */
  1575. function testPrefixProtection() {
  1576. $_POST = array();
  1577. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1578. Router::reload();
  1579. Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin'), array('controller', 'action'));
  1580. $Dispatcher =& new TestDispatcher();
  1581. $Dispatcher->base = false;
  1582. $url = 'test_dispatch_pages/admin_index/param:value/param2:value2';
  1583. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1584. $expected = array('privateAction', array(array(
  1585. 'className' => 'TestDispatchPagesController',
  1586. 'action' => 'admin_index',
  1587. 'webroot' => '/cake/repo/branches/1.2.x.x/',
  1588. 'url' => 'test_dispatch_pages/admin_index/param:value/param2:value2',
  1589. 'base' => '/cake/repo/branches/1.2.x.x'
  1590. )));
  1591. $this->assertIdentical($expected, $controller);
  1592. }
  1593. /**
  1594. * Test dispatching into the TestPlugin in the test_app
  1595. *
  1596. * @return void
  1597. * @access public
  1598. */
  1599. function testTestPluginDispatch() {
  1600. $Dispatcher =& new TestDispatcher();
  1601. App::build(array(
  1602. 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
  1603. ));
  1604. App::objects('plugin', null, false);
  1605. Router::reload();
  1606. Router::parse('/');
  1607. $url = '/test_plugin/tests/index';
  1608. $result = $Dispatcher->dispatch($url, array('return' => 1));
  1609. $this->assertTrue(class_exists('TestsController'));
  1610. $this->assertTrue(class_exists('TestPluginAppController'));
  1611. $this->assertTrue(class_exists('OtherComponentComponent'));
  1612. $this->assertTrue(class_exists('PluginsComponentComponent'));
  1613. $this->assertEqual($result->params['controller'], 'tests');
  1614. $this->assertEqual($result->params['plugin'], 'test_plugin');
  1615. $this->assertEqual($result->params['action'], 'index');
  1616. App::build();
  1617. }
  1618. /**
  1619. * testChangingParamsFromBeforeFilter method
  1620. *
  1621. * @return void
  1622. * @access public
  1623. */
  1624. function testChangingParamsFromBeforeFilter() {
  1625. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1626. $Dispatcher =& new TestDispatcher();
  1627. $url = 'some_posts/index/param:value/param2:value2';
  1628. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1629. $expected = array('missingAction', array(array(
  1630. 'className' => 'SomePostsController',
  1631. 'action' => 'view',
  1632. 'webroot' => '/cake/repo/branches/1.2.x.x/',
  1633. 'url' => '/cake/repo/branches/1.2.x.x/some_posts/index/param:value/param2:value2',
  1634. 'base' => '/cake/repo/branches/1.2.x.x'
  1635. )));
  1636. $this->assertEqual($expected, $controller);
  1637. $url = 'some_posts/something_else/param:value/param2:value2';
  1638. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1639. $expected = 'SomePosts';
  1640. $this->assertEqual($expected, $controller->name);
  1641. $expected = 'change';
  1642. $this->assertEqual($expected, $controller->action);
  1643. $expected = array('changed');
  1644. $this->assertIdentical($expected, $controller->params['pass']);
  1645. }
  1646. /**
  1647. * testStaticAssets method
  1648. *
  1649. * @return void
  1650. * @access public
  1651. */
  1652. function testAssets() {
  1653. Router::reload();
  1654. $Configure =& Configure::getInstance();
  1655. $Configure->__objects = null;
  1656. App::build(array(
  1657. 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
  1658. 'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS),
  1659. 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
  1660. ));
  1661. $Dispatcher =& new TestDispatcher();
  1662. $debug = Configure::read('debug');
  1663. Configure::write('debug', 0);
  1664. ob_start();
  1665. $Dispatcher->dispatch('theme/test_theme/../webroot/css/test_asset.css');
  1666. $result = ob_get_clean();
  1667. $this->assertFalse($result);
  1668. ob_start();
  1669. $Dispatcher->dispatch('theme/test_theme/pdfs');
  1670. $result = ob_get_clean();
  1671. $this->assertFalse($result);
  1672. ob_start();
  1673. $Dispatcher->dispatch('theme/test_theme/flash/theme_test.swf');
  1674. $result = ob_get_clean();
  1675. $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');
  1676. $this->assertEqual($file, $result);
  1677. $this->assertEqual('this is just a test to load swf file from the theme.', $result);
  1678. ob_start();
  1679. $Dispatcher->dispatch('theme/test_theme/pdfs/theme_test.pdf');
  1680. $result = ob_get_clean();
  1681. $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');
  1682. $this->assertEqual($file, $result);
  1683. $this->assertEqual('this is just a test to load pdf file from the theme.', $result);
  1684. ob_start();
  1685. $Dispatcher->dispatch('theme/test_theme/img/test.jpg');
  1686. $result = ob_get_clean();
  1687. $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');
  1688. $this->assertEqual($file, $result);
  1689. $Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/css/test_asset.css');
  1690. ob_start();
  1691. $Dispatcher->asset('theme/test_theme/css/test_asset.css');
  1692. $result = ob_get_clean();
  1693. $this->assertEqual('this is the test asset css file', $result);
  1694. $Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/js/theme.js');
  1695. ob_start();
  1696. $Dispatcher->asset('theme/test_theme/js/theme.js');
  1697. $result = ob_get_clean();
  1698. $this->assertEqual('root theme js file', $result);
  1699. $Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/js/one/theme_one.js');
  1700. ob_start();
  1701. $Dispatcher->asset('theme/test_theme/js/one/theme_one.js');
  1702. $result = ob_get_clean();
  1703. $this->assertEqual('nested theme js file', $result);
  1704. ob_start();
  1705. $Dispatcher->asset('test_plugin/root.js');
  1706. $result = ob_get_clean();
  1707. $expected = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'webroot' . DS . 'root.js');
  1708. $this->assertEqual($result, $expected);
  1709. ob_start();
  1710. $Dispatcher->dispatch('test_plugin/flash/plugin_test.swf');
  1711. $result = ob_get_clean();
  1712. $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');
  1713. $this->assertEqual($file, $result);
  1714. $this->assertEqual('this is just a test to load swf file from the plugin.', $result);
  1715. ob_start();
  1716. $Dispatcher->dispatch('test_plugin/pdfs/plugin_test.pdf');
  1717. $result = ob_get_clean();
  1718. $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');
  1719. $this->assertEqual($file, $result);
  1720. $this->assertEqual('this is just a test to load pdf file from the plugin.', $result);
  1721. ob_start();
  1722. $Dispatcher->asset('test_plugin/js/test_plugin/test.js');
  1723. $result = ob_get_clean();
  1724. $this->assertEqual('alert("Test App");', $result);
  1725. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/js/test_plugin/test.js');
  1726. ob_start();
  1727. $Dispatcher->asset('test_plugin/js/test_plugin/test.js');
  1728. $result = ob_get_clean();
  1729. $this->assertEqual('alert("Test App");', $result);
  1730. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css');
  1731. ob_start();
  1732. $Dispatcher->asset('test_plugin/css/test_plugin_asset.css');
  1733. $result = ob_get_clean();
  1734. $this->assertEqual('this is the test plugin asset css file', $result);
  1735. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/img/cake.icon.gif');
  1736. ob_start();
  1737. $Dispatcher->asset('test_plugin/img/cake.icon.gif');
  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 . 'img' . DS . 'cake.icon.gif');
  1740. $this->assertEqual($file, $result);
  1741. $Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/plugin_js.js');
  1742. ob_start();
  1743. $Dispatcher->asset('plugin_js/js/plugin_js.js');
  1744. $result = ob_get_clean();
  1745. $expected = "alert('win sauce');";
  1746. $this->assertEqual($result, $expected);
  1747. $Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/one/plugin_one.js');
  1748. ob_start();
  1749. $Dispatcher->asset('plugin_js/js/one/plugin_one.js');
  1750. $result = ob_get_clean();
  1751. $expected = "alert('plugin one nested js file');";
  1752. $this->assertEqual($result, $expected);
  1753. Configure::write('debug', $debug);
  1754. //reset the header content-type without page can render as plain text.
  1755. header('Content-type: text/html');
  1756. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/theme_one.htc');
  1757. ob_start();
  1758. $Dispatcher->asset('test_plugin/css/unknown.extension');
  1759. $result = ob_get_clean();
  1760. $this->assertEqual('Testing a file with unknown extension to mime mapping.', $result);
  1761. header('Content-type: text/html');
  1762. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/theme_one.htc');
  1763. ob_start();
  1764. $Dispatcher->asset('test_plugin/css/theme_one.htc');
  1765. $result = ob_get_clean();
  1766. $this->assertEqual('htc file', $result);
  1767. header('Content-type: text/html');
  1768. }
  1769. /**
  1770. * test that missing asset processors trigger a 404 with no response body.
  1771. *
  1772. * @return void
  1773. */
  1774. function testMissingAssetProcessor404() {
  1775. $Dispatcher =& new TestDispatcher();
  1776. Configure::write('Asset.filter', array(
  1777. 'js' => '',
  1778. 'css' => null
  1779. ));
  1780. $this->assertNoErrors();
  1781. ob_start();
  1782. $Dispatcher->asset('ccss/cake.generic.css');
  1783. $result = ob_get_clean();
  1784. $this->assertTrue($Dispatcher->stopped);
  1785. header('HTTP/1.1 200 Ok');
  1786. }
  1787. /**
  1788. * test that asset filters work for theme and plugin assets
  1789. *
  1790. * @return void
  1791. */
  1792. function testAssetFilterForThemeAndPlugins() {
  1793. $Dispatcher =& new TestDispatcher();
  1794. Configure::write('Asset.filter', array(
  1795. 'js' => '',
  1796. 'css' => ''
  1797. ));
  1798. $Dispatcher->asset('theme/test_theme/ccss/cake.generic.css');
  1799. $this->assertTrue($Dispatcher->stopped);
  1800. $Dispatcher->stopped = false;
  1801. $Dispatcher->asset('theme/test_theme/cjs/debug_kit.js');
  1802. $this->assertTrue($Dispatcher->stopped);
  1803. $Dispatcher->stopped = false;
  1804. $Dispatcher->asset('test_plugin/ccss/cake.generic.css');
  1805. $this->assertTrue($Dispatcher->stopped);
  1806. $Dispatcher->stopped = false;
  1807. $Dispatcher->asset('test_plugin/cjs/debug_kit.js');
  1808. $this->assertTrue($Dispatcher->stopped);
  1809. $Dispatcher->stopped = false;
  1810. $Dispatcher->asset('css/ccss/debug_kit.css');
  1811. $this->assertFalse($Dispatcher->stopped);
  1812. $Dispatcher->stopped = false;
  1813. $Dispatcher->asset('js/cjs/debug_kit.js');
  1814. $this->assertFalse($Dispatcher->stopped);
  1815. }
  1816. /**
  1817. * testFullPageCachingDispatch method
  1818. *
  1819. * @return void
  1820. * @access public
  1821. */
  1822. function testFullPageCachingDispatch() {
  1823. Configure::write('Cache.disable', false);
  1824. Configure::write('Cache.check', true);
  1825. Configure::write('debug', 2);
  1826. $_POST = array();
  1827. $_SERVER['PHP_SELF'] = '/';
  1828. Router::reload();
  1829. Router::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index'));
  1830. App::build(array(
  1831. 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
  1832. ), true);
  1833. $dispatcher =& new TestDispatcher();
  1834. $dispatcher->base = false;
  1835. $url = '/';
  1836. ob_start();
  1837. $dispatcher->dispatch($url);
  1838. $out = ob_get_clean();
  1839. ob_start();
  1840. $dispatcher->cached($url);
  1841. $cached = ob_get_clean();
  1842. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1843. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1844. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1845. $this->assertEqual($result, $expected);
  1846. $filename = $this->__cachePath($dispatcher->here);
  1847. unlink($filename);
  1848. $dispatcher->base = false;
  1849. $url = 'test_cached_pages/index';
  1850. ob_start();
  1851. $dispatcher->dispatch($url);
  1852. $out = ob_get_clean();
  1853. ob_start();
  1854. $dispatcher->cached($url);
  1855. $cached = ob_get_clean();
  1856. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1857. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1858. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1859. $this->assertEqual($result, $expected);
  1860. $filename = $this->__cachePath($dispatcher->here);
  1861. unlink($filename);
  1862. $url = 'TestCachedPages/index';
  1863. ob_start();
  1864. $dispatcher->dispatch($url);
  1865. $out = ob_get_clean();
  1866. ob_start();
  1867. $dispatcher->cached($url);
  1868. $cached = ob_get_clean();
  1869. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1870. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1871. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1872. $this->assertEqual($result, $expected);
  1873. $filename = $this->__cachePath($dispatcher->here);
  1874. unlink($filename);
  1875. $url = 'TestCachedPages/test_nocache_tags';
  1876. ob_start();
  1877. $dispatcher->dispatch($url);
  1878. $out = ob_get_clean();
  1879. ob_start();
  1880. $dispatcher->cached($url);
  1881. $cached = ob_get_clean();
  1882. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1883. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1884. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1885. $this->assertEqual($result, $expected);
  1886. $filename = $this->__cachePath($dispatcher->here);
  1887. unlink($filename);
  1888. $url = 'test_cached_pages/view/param/param';
  1889. ob_start();
  1890. $dispatcher->dispatch($url);
  1891. $out = ob_get_clean();
  1892. ob_start();
  1893. $dispatcher->cached($url);
  1894. $cached = ob_get_clean();
  1895. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1896. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1897. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1898. $this->assertEqual($result, $expected);
  1899. $filename = $this->__cachePath($dispatcher->here);
  1900. unlink($filename);
  1901. $url = 'test_cached_pages/view/foo:bar/value:goo';
  1902. ob_start();
  1903. $dispatcher->dispatch($url);
  1904. $out = ob_get_clean();
  1905. ob_start();
  1906. $dispatcher->cached($url);
  1907. $cached = ob_get_clean();
  1908. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1909. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1910. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1911. $this->assertEqual($result, $expected);
  1912. $filename = $this->__cachePath($dispatcher->here);
  1913. $this->assertTrue(file_exists($filename));
  1914. unlink($filename);
  1915. }
  1916. /**
  1917. * test that cached() registers a view and un-registers it. Tests
  1918. * that helpers using ClassRegistry::getObject('view'); don't fail
  1919. *
  1920. * @return void
  1921. */
  1922. function testCachedRegisteringViewObject() {
  1923. Configure::write('Cache.disable', false);
  1924. Configure::write('Cache.check', true);
  1925. Configure::write('debug', 2);
  1926. $_POST = array();
  1927. $_SERVER['PHP_SELF'] = '/';
  1928. Router::reload();
  1929. App::build(array(
  1930. 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
  1931. ));
  1932. $dispatcher =& new TestDispatcher();
  1933. $dispatcher->base = false;
  1934. $url = 'test_cached_pages/cache_form';
  1935. ob_start();
  1936. $dispatcher->dispatch($url);
  1937. $out = ob_get_clean();
  1938. ClassRegistry::flush();
  1939. ob_start();
  1940. $dispatcher->cached($url);
  1941. $cached = ob_get_clean();
  1942. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1943. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1944. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1945. $this->assertEqual($result, $expected);
  1946. $filename = $this->__cachePath($dispatcher->here);
  1947. @unlink($filename);
  1948. ClassRegistry::flush();
  1949. }
  1950. /**
  1951. * testHttpMethodOverrides method
  1952. *
  1953. * @return void
  1954. * @access public
  1955. */
  1956. function testHttpMethodOverrides() {
  1957. Router::reload();
  1958. Router::mapResources('Posts');
  1959. $_SERVER['REQUEST_METHOD'] = 'POST';
  1960. $dispatcher =& new Dispatcher();
  1961. $dispatcher->base = false;
  1962. $result = $dispatcher->parseParams('/posts');
  1963. $expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'form' => array(), 'url' => array());
  1964. $this->assertEqual($result, $expected);
  1965. $_SERVER['REQUEST_METHOD'] = 'GET';
  1966. $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
  1967. $result = $dispatcher->parseParams('/posts/5');
  1968. $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
  1969. $this->assertEqual($result, $expected);
  1970. unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
  1971. $_SERVER['REQUEST_METHOD'] = 'GET';
  1972. $result = $dispatcher->parseParams('/posts/5');
  1973. $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'form' => array(), 'url' => array());
  1974. $this->assertEqual($result, $expected);
  1975. $_POST['_method'] = 'PUT';
  1976. $result = $dispatcher->parseParams('/posts/5');
  1977. $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
  1978. $this->assertEqual($result, $expected);
  1979. $_POST['_method'] = 'POST';
  1980. $_POST['data'] = array('Post' => array('title' => 'New Post'));
  1981. $_POST['extra'] = 'data';
  1982. $_SERVER = array();
  1983. $result = $dispatcher->parseParams('/posts');
  1984. $expected = array(
  1985. 'pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add',
  1986. '[method]' => 'POST', 'form' => array('extra' => 'data'), 'data' => array('Post' => array('title' => 'New Post')),
  1987. 'url' => array()
  1988. );
  1989. $this->assertEqual($result, $expected);
  1990. unset($_POST['_method']);
  1991. }
  1992. /**
  1993. * Tests that invalid characters cannot be injected into the application base path.
  1994. *
  1995. * @return void
  1996. * @access public
  1997. */
  1998. function testBasePathInjection() {
  1999. $self = $_SERVER['PHP_SELF'];
  2000. $_SERVER['PHP_SELF'] = urldecode(
  2001. "/index.php/%22%3E%3Ch1%20onclick=%22alert('xss');%22%3Eheya%3C/h1%3E"
  2002. );
  2003. $dispatcher =& new Dispatcher();
  2004. $result = $dispatcher->baseUrl();
  2005. $expected = '/index.php/h1 onclick=alert(xss);heya';
  2006. $this->assertEqual($result, $expected);
  2007. }
  2008. /**
  2009. * testEnvironmentDetection method
  2010. *
  2011. * @return void
  2012. * @access public
  2013. */
  2014. function testEnvironmentDetection() {
  2015. $dispatcher =& new Dispatcher();
  2016. $environments = array(
  2017. 'IIS' => array(
  2018. 'No rewrite base path' => array(
  2019. 'App' => array('base' => false, 'baseUrl' => '/index.php?', 'server' => 'IIS'),
  2020. '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),
  2021. 'reload' => true,
  2022. 'path' => ''
  2023. ),
  2024. 'No rewrite with path' => array(
  2025. 'SERVER' => array('QUERY_STRING' => '/posts/add', 'REQUEST_URI' => '/index.php?/posts/add', 'URL' => '/index.php?/posts/add', 'argv' => array('/posts/add'), 'argc' => 1),
  2026. 'reload' => false,
  2027. 'path' => '/posts/add'
  2028. ),
  2029. 'No rewrite sub dir 1' => array(
  2030. 'GET' => array(),
  2031. '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),
  2032. 'reload' => false,
  2033. 'path' => ''
  2034. ),
  2035. 'No rewrite sub dir 1 with path' => array(
  2036. 'GET' => array('/posts/add' => ''),
  2037. '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),
  2038. 'reload' => false,
  2039. 'path' => '/posts/add'
  2040. ),
  2041. 'No rewrite sub dir 2' => array(
  2042. 'App' => array('base' => false, 'baseUrl' => '/site/index.php?', 'dir' => 'app', 'webroot' => 'webroot', 'server' => 'IIS'),
  2043. 'GET' => array(),
  2044. 'POST' => array(),
  2045. '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),
  2046. 'reload' => false,
  2047. 'path' => ''
  2048. ),
  2049. 'No rewrite sub dir 2 with path' => array(
  2050. 'GET' => array('/posts/add' => ''),
  2051. '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),
  2052. 'reload' => false,
  2053. 'path' => '/posts/add'
  2054. )
  2055. ),
  2056. 'Apache' => array(
  2057. 'No rewrite base path' => array(
  2058. 'App' => array('base' => false, 'baseUrl' => '/index.php', 'dir' => 'app', 'webroot' => 'webroot'),
  2059. 'SERVER' => array(
  2060. 'SERVER_NAME' => 'localhost',
  2061. 'SERVER_ADDR' => '::1',
  2062. 'SERVER_PORT' => '80',
  2063. 'REMOTE_ADDR' => '::1',
  2064. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot',
  2065. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
  2066. 'QUERY_STRING' => '',
  2067. 'REQUEST_URI' => '/',
  2068. 'SCRIPT_NAME' => '/index.php',
  2069. 'PHP_SELF' => '/index.php',
  2070. 'argv' => array(),
  2071. 'argc' => 0
  2072. ),
  2073. 'reload' => true,
  2074. 'path' => ''
  2075. ),
  2076. 'No rewrite with path' => array(
  2077. 'SERVER' => array(
  2078. 'HTTP_HOST' => 'localhost',
  2079. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot',
  2080. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/officespace/app/webroot/index.php',
  2081. 'QUERY_STRING' => '',
  2082. 'REQUEST_URI' => '/index.php/posts/add',
  2083. 'SCRIPT_NAME' => '/index.php',
  2084. 'PATH_INFO' => '/posts/add',
  2085. 'PHP_SELF' => '/index.php/posts/add',
  2086. 'argv' => array(),
  2087. 'argc' => 0),
  2088. 'reload' => false,
  2089. 'path' => '/posts/add'
  2090. ),
  2091. 'GET Request at base domain' => array(
  2092. 'App' => array('base' => false, 'baseUrl' => null, 'dir' => 'app', 'webroot' => 'webroot'),
  2093. 'SERVER' => array(
  2094. 'HTTP_HOST' => 'cake.1.2',
  2095. 'SERVER_NAME' => 'cake.1.2',
  2096. 'SERVER_ADDR' => '127.0.0.1',
  2097. 'SERVER_PORT' => '80',
  2098. 'REMOTE_ADDR' => '127.0.0.1',
  2099. 'DOCUMENT_ROOT' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot',
  2100. 'SCRIPT_FILENAME' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot/index.php',
  2101. 'REMOTE_PORT' => '53550',
  2102. 'QUERY_STRING' => 'a=b',
  2103. 'REQUEST_URI' => '/?a=b',
  2104. 'SCRIPT_NAME' => '/index.php',
  2105. 'PHP_SELF' => '/index.php'
  2106. ),
  2107. 'GET' => array('a' => 'b'),
  2108. 'POST' => array(),
  2109. 'reload' => true,
  2110. 'path' => '',
  2111. 'urlParams' => array('a' => 'b'),
  2112. 'environment' => array('CGI_MODE' => false)
  2113. ),
  2114. 'New CGI no mod_rewrite' => array(
  2115. 'App' => array('base' => false, 'baseUrl' => '/limesurvey20/index.php', 'dir' => 'app', 'webroot' => 'webroot'),
  2116. 'SERVER' => array(
  2117. 'DOCUMENT_ROOT' => '/home/.sites/110/site313/web',
  2118. 'PATH_INFO' => '/installations',
  2119. 'PATH_TRANSLATED' => '/home/.sites/110/site313/web/limesurvey20/index.php',
  2120. 'PHPRC' => '/home/.sites/110/site313',
  2121. 'QUERY_STRING' => '',
  2122. 'REQUEST_URI' => '/limesurvey20/index.php/installations',
  2123. 'SCRIPT_FILENAME' => '/home/.sites/110/site313/web/limesurvey20/index.php',
  2124. 'SCRIPT_NAME' => '/limesurvey20/index.php',
  2125. 'SCRIPT_URI' => 'http://www.gisdat-umfragen.at/limesurvey20/index.php/installations',
  2126. 'PHP_SELF' => '/limesurvey20/index.php/installations',
  2127. 'CGI_MODE' => true
  2128. ),
  2129. 'GET' => array(),
  2130. 'POST' => array(),
  2131. 'reload' => true,
  2132. 'path' => '/installations',
  2133. 'urlParams' => array(),
  2134. 'environment' => array('CGI_MODE' => true)
  2135. )
  2136. )
  2137. );
  2138. $backup = $this->__backupEnvironment();
  2139. foreach ($environments as $name => $env) {
  2140. foreach ($env as $descrip => $settings) {
  2141. if ($settings['reload']) {
  2142. $this->__reloadEnvironment();
  2143. }
  2144. $this->__loadEnvironment($settings);
  2145. $this->assertEqual($dispatcher->uri(), $settings['path'], "%s on environment: {$name}, on setting: {$descrip}");
  2146. if (isset($settings['urlParams'])) {
  2147. $this->assertEqual($_GET, $settings['urlParams'], "%s on environment: {$name}, on setting: {$descrip}");
  2148. }
  2149. if (isset($settings['environment'])) {
  2150. foreach ($settings['environment'] as $key => $val) {
  2151. $this->assertEqual(env($key), $val, "%s on key {$key} on environment: {$name}, on setting: {$descrip}");
  2152. }
  2153. }
  2154. }
  2155. }
  2156. $this->__loadEnvironment(array_merge(array('reload' => true), $backup));
  2157. }
  2158. /**
  2159. * Tests that the Dispatcher does not return an empty action
  2160. *
  2161. * @return void
  2162. * @access public
  2163. */
  2164. function testTrailingSlash() {
  2165. $_POST = array();
  2166. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  2167. Router::reload();
  2168. $Dispatcher =& new TestDispatcher();
  2169. Router::connect('/myalias/:action/*', array('controller' => 'my_controller', 'action' => null));
  2170. $Dispatcher->base = false;
  2171. $url = 'myalias/'; //Fails
  2172. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  2173. $result = $Dispatcher->parseParams($url);
  2174. $this->assertEqual('index', $result['action']);
  2175. $url = 'myalias'; //Passes
  2176. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  2177. $result = $Dispatcher->parseParams($url);
  2178. $this->assertEqual('index', $result['action']);
  2179. }
  2180. /**
  2181. * backupEnvironment method
  2182. *
  2183. * @return void
  2184. * @access private
  2185. */
  2186. function __backupEnvironment() {
  2187. return array(
  2188. 'App' => Configure::read('App'),
  2189. 'GET' => $_GET,
  2190. 'POST' => $_POST,
  2191. 'SERVER'=> $_SERVER
  2192. );
  2193. }
  2194. /**
  2195. * reloadEnvironment method
  2196. *
  2197. * @return void
  2198. * @access private
  2199. */
  2200. function __reloadEnvironment() {
  2201. foreach ($_GET as $key => $val) {
  2202. unset($_GET[$key]);
  2203. }
  2204. foreach ($_POST as $key => $val) {
  2205. unset($_POST[$key]);
  2206. }
  2207. foreach ($_SERVER as $key => $val) {
  2208. unset($_SERVER[$key]);
  2209. }
  2210. Configure::write('App', array());
  2211. }
  2212. /**
  2213. * loadEnvironment method
  2214. *
  2215. * @param mixed $env
  2216. * @return void
  2217. * @access private
  2218. */
  2219. function __loadEnvironment($env) {
  2220. if ($env['reload']) {
  2221. $this->__reloadEnvironment();
  2222. }
  2223. if (isset($env['App'])) {
  2224. Configure::write('App', $env['App']);
  2225. }
  2226. if (isset($env['GET'])) {
  2227. foreach ($env['GET'] as $key => $val) {
  2228. $_GET[$key] = $val;
  2229. }
  2230. }
  2231. if (isset($env['POST'])) {
  2232. foreach ($env['POST'] as $key => $val) {
  2233. $_POST[$key] = $val;
  2234. }
  2235. }
  2236. if (isset($env['SERVER'])) {
  2237. foreach ($env['SERVER'] as $key => $val) {
  2238. $_SERVER[$key] = $val;
  2239. }
  2240. }
  2241. }
  2242. /**
  2243. * cachePath method
  2244. *
  2245. * @param mixed $her
  2246. * @return string
  2247. * @access private
  2248. */
  2249. function __cachePath($here) {
  2250. $path = $here;
  2251. if ($here == '/') {
  2252. $path = 'home';
  2253. }
  2254. $path = strtolower(Inflector::slug($path));
  2255. $filename = CACHE . 'views' . DS . $path . '.php';
  2256. if (!file_exists($filename)) {
  2257. $filename = CACHE . 'views' . DS . $path . '_index.php';
  2258. }
  2259. return $filename;
  2260. }
  2261. }