PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://skygames.googlecode.com/
PHP | 1941 lines | 1137 code | 188 blank | 616 comment | 16 complexity | 0f8be6a69abbf011c0abf3f5423fbdde MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, CC-BY-SA-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* SVN FILE: $Id: dispatcher.test.php 7848 2008-11-08 02:58:37Z renan.saddam $ */
  3. /**
  4. * Short description for file.
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11. * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  12. *
  13. * Licensed under The Open Group Test Suite License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @filesource
  17. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  18. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  19. * @package cake.tests
  20. * @subpackage cake.tests.cases
  21. * @since CakePHP(tm) v 1.2.0.4206
  22. * @version $Revision: 7848 $
  23. * @modifiedby $LastChangedBy: renan.saddam $
  24. * @lastmodified $Date: 2008-11-07 20:58:37 -0600 (Fri, 07 Nov 2008) $
  25. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  26. */
  27. require_once CAKE.'dispatcher.php';
  28. App::import('Core', 'AppController');
  29. /**
  30. * TestDispatcher class
  31. *
  32. * @package cake
  33. * @subpackage cake.tests.cases
  34. */
  35. class TestDispatcher extends Dispatcher {
  36. /**
  37. * invoke method
  38. *
  39. * @param mixed $controller
  40. * @param mixed $params
  41. * @param mixed $missingAction
  42. * @access protected
  43. * @return void
  44. */
  45. function _invoke(&$controller, $params) {
  46. restore_error_handler();
  47. if ($result = parent::_invoke($controller, $params)) {
  48. if ($result === 'missingAction') {
  49. return $result;
  50. }
  51. }
  52. set_error_handler('simpleTestErrorHandler');
  53. return $controller;
  54. }
  55. /**
  56. * cakeError method
  57. *
  58. * @param mixed $filename
  59. * @access public
  60. * @return void
  61. */
  62. function cakeError($filename) {
  63. return $filename;
  64. }
  65. /**
  66. * _stop method
  67. *
  68. * @access protected
  69. * @return void
  70. */
  71. function _stop() {
  72. return true;
  73. }
  74. }
  75. /**
  76. * MyPluginAppController class
  77. *
  78. * @package cake
  79. * @subpackage cake.tests.cases
  80. */
  81. class MyPluginAppController extends AppController {
  82. }
  83. /**
  84. * MyPluginController class
  85. *
  86. * @package cake
  87. * @subpackage cake.tests.cases
  88. */
  89. class MyPluginController extends MyPluginAppController {
  90. /**
  91. * name property
  92. *
  93. * @var string 'MyPlugin'
  94. * @access public
  95. */
  96. var $name = 'MyPlugin';
  97. /**
  98. * uses property
  99. *
  100. * @var array
  101. * @access public
  102. */
  103. var $uses = array();
  104. /**
  105. * index method
  106. *
  107. * @access public
  108. * @return void
  109. */
  110. function index() {
  111. return true;
  112. }
  113. /**
  114. * add method
  115. *
  116. * @access public
  117. * @return void
  118. */
  119. function add() {
  120. return true;
  121. }
  122. /**
  123. * admin_add method
  124. *
  125. * @param mixed $id
  126. * @access public
  127. * @return void
  128. */
  129. function admin_add($id = null) {
  130. return $id;
  131. }
  132. }
  133. /**
  134. * SomePagesController class
  135. *
  136. * @package cake
  137. * @subpackage cake.tests.cases
  138. */
  139. class SomePagesController extends AppController {
  140. /**
  141. * name property
  142. *
  143. * @var string 'SomePages'
  144. * @access public
  145. */
  146. var $name = 'SomePages';
  147. /**
  148. * uses property
  149. *
  150. * @var array
  151. * @access public
  152. */
  153. var $uses = array();
  154. /**
  155. * display method
  156. *
  157. * @param mixed $page
  158. * @access public
  159. * @return void
  160. */
  161. function display($page = null) {
  162. return $page;
  163. }
  164. /**
  165. * index method
  166. *
  167. * @access public
  168. * @return void
  169. */
  170. function index() {
  171. return true;
  172. }
  173. /**
  174. * protected method
  175. *
  176. * @access protected
  177. * @return void
  178. */
  179. function _protected() {
  180. return true;
  181. }
  182. /**
  183. * redirect method overriding
  184. *
  185. * @access public
  186. * @return void
  187. */
  188. function redirect() {
  189. echo 'this should not be accessible';
  190. }
  191. }
  192. /**
  193. * OtherPagesController class
  194. *
  195. * @package cake
  196. * @subpackage cake.tests.cases
  197. */
  198. class OtherPagesController extends MyPluginAppController {
  199. /**
  200. * name property
  201. *
  202. * @var string 'OtherPages'
  203. * @access public
  204. */
  205. var $name = 'OtherPages';
  206. /**
  207. * uses property
  208. *
  209. * @var array
  210. * @access public
  211. */
  212. var $uses = array();
  213. /**
  214. * display method
  215. *
  216. * @param mixed $page
  217. * @access public
  218. * @return void
  219. */
  220. function display($page = null) {
  221. return $page;
  222. }
  223. /**
  224. * index method
  225. *
  226. * @access public
  227. * @return void
  228. */
  229. function index() {
  230. return true;
  231. }
  232. }
  233. /**
  234. * TestDispatchPagesController class
  235. *
  236. * @package cake
  237. * @subpackage cake.tests.cases
  238. */
  239. class TestDispatchPagesController extends AppController {
  240. /**
  241. * name property
  242. *
  243. * @var string 'TestDispatchPages'
  244. * @access public
  245. */
  246. var $name = 'TestDispatchPages';
  247. /**
  248. * uses property
  249. *
  250. * @var array
  251. * @access public
  252. */
  253. var $uses = array();
  254. /**
  255. * admin_index method
  256. *
  257. * @access public
  258. * @return void
  259. */
  260. function admin_index() {
  261. return true;
  262. }
  263. /**
  264. * camelCased method
  265. *
  266. * @access public
  267. * @return void
  268. */
  269. function camelCased() {
  270. return true;
  271. }
  272. }
  273. /**
  274. * ArticlesTestAppController class
  275. *
  276. * @package cake
  277. * @subpackage cake.tests.cases
  278. */
  279. class ArticlesTestAppController extends AppController {
  280. }
  281. /**
  282. * ArticlesTestController class
  283. *
  284. * @package cake
  285. * @subpackage cake.tests.cases
  286. */
  287. class ArticlesTestController extends ArticlesTestAppController {
  288. /**
  289. * name property
  290. *
  291. * @var string 'ArticlesTest'
  292. * @access public
  293. */
  294. var $name = 'ArticlesTest';
  295. /**
  296. * uses property
  297. *
  298. * @var array
  299. * @access public
  300. */
  301. var $uses = array();
  302. /**
  303. * admin_index method
  304. *
  305. * @access public
  306. * @return void
  307. */
  308. function admin_index() {
  309. return true;
  310. }
  311. }
  312. /**
  313. * SomePostsController class
  314. *
  315. * @package cake
  316. * @subpackage cake.tests.cases
  317. */
  318. class SomePostsController extends AppController {
  319. /**
  320. * name property
  321. *
  322. * @var string 'SomePosts'
  323. * @access public
  324. */
  325. var $name = 'SomePosts';
  326. /**
  327. * uses property
  328. *
  329. * @var array
  330. * @access public
  331. */
  332. var $uses = array();
  333. /**
  334. * autoRender property
  335. *
  336. * @var bool false
  337. * @access public
  338. */
  339. var $autoRender = false;
  340. /**
  341. * beforeFilter method
  342. *
  343. * @access public
  344. * @return void
  345. */
  346. function beforeFilter() {
  347. if ($this->params['action'] == 'index') {
  348. $this->params['action'] = 'view';
  349. } else {
  350. $this->params['action'] = 'change';
  351. }
  352. $this->params['pass'] = array('changed');
  353. }
  354. /**
  355. * index method
  356. *
  357. * @access public
  358. * @return void
  359. */
  360. function index() {
  361. return true;
  362. }
  363. /**
  364. * change method
  365. *
  366. * @access public
  367. * @return void
  368. */
  369. function change() {
  370. return true;
  371. }
  372. }
  373. /**
  374. * TestCachedPagesController class
  375. *
  376. * @package cake
  377. * @subpackage cake.tests.cases
  378. */
  379. class TestCachedPagesController extends AppController {
  380. /**
  381. * name property
  382. *
  383. * @var string 'TestCachedPages'
  384. * @access public
  385. */
  386. var $name = 'TestCachedPages';
  387. /**
  388. * uses property
  389. *
  390. * @var array
  391. * @access public
  392. */
  393. var $uses = array();
  394. /**
  395. * helpers property
  396. *
  397. * @var array
  398. * @access public
  399. */
  400. var $helpers = array('Cache');
  401. /**
  402. * cacheAction property
  403. *
  404. * @var array
  405. * @access public
  406. */
  407. var $cacheAction = array(
  408. 'index'=> '+2 sec', 'test_nocache_tags'=>'+2 sec',
  409. 'view/' => '+2 sec'
  410. );
  411. /**
  412. * viewPath property
  413. *
  414. * @var string 'posts'
  415. * @access public
  416. */
  417. var $viewPath = 'posts';
  418. /**
  419. * index method
  420. *
  421. * @access public
  422. * @return void
  423. */
  424. function index() {
  425. $this->render();
  426. }
  427. /**
  428. * test_nocache_tags method
  429. *
  430. * @access public
  431. * @return void
  432. */
  433. function test_nocache_tags() {
  434. $this->render();
  435. }
  436. /**
  437. * view method
  438. *
  439. * @access public
  440. * @return void
  441. */
  442. function view($id = null) {
  443. $this->render('index');
  444. }
  445. }
  446. /**
  447. * TimesheetsController class
  448. *
  449. * @package cake
  450. * @subpackage cake.tests.cases
  451. */
  452. class TimesheetsController extends AppController {
  453. /**
  454. * name property
  455. *
  456. * @var string 'Timesheets'
  457. * @access public
  458. */
  459. var $name = 'Timesheets';
  460. /**
  461. * uses property
  462. *
  463. * @var array
  464. * @access public
  465. */
  466. var $uses = array();
  467. /**
  468. * index method
  469. *
  470. * @access public
  471. * @return void
  472. */
  473. function index() {
  474. return true;
  475. }
  476. }
  477. /**
  478. * Short description for class.
  479. *
  480. * @package cake.tests
  481. * @subpackage cake.tests.cases
  482. */
  483. class DispatcherTest extends CakeTestCase {
  484. /**
  485. * setUp method
  486. *
  487. * @access public
  488. * @return void
  489. */
  490. function setUp() {
  491. $this->_get = $_GET;
  492. $_GET = array();
  493. Configure::write('App.base', false);
  494. Configure::write('App.baseUrl', false);
  495. Configure::write('App.dir', 'app');
  496. Configure::write('App.webroot', 'webroot');
  497. Configure::write('Cache.disable', true);
  498. }
  499. /**
  500. * testParseParamsWithoutZerosAndEmptyPost method
  501. *
  502. * @access public
  503. * @return void
  504. */
  505. function testParseParamsWithoutZerosAndEmptyPost() {
  506. $Dispatcher =& new Dispatcher();
  507. $test = $Dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3");
  508. $this->assertIdentical($test['controller'], 'testcontroller');
  509. $this->assertIdentical($test['action'], 'testaction');
  510. $this->assertIdentical($test['pass'][0], 'params1');
  511. $this->assertIdentical($test['pass'][1], 'params2');
  512. $this->assertIdentical($test['pass'][2], 'params3');
  513. $this->assertFalse(!empty($test['form']));
  514. }
  515. /**
  516. * testParseParamsReturnsPostedData method
  517. *
  518. * @access public
  519. * @return void
  520. */
  521. function testParseParamsReturnsPostedData() {
  522. $_POST['testdata'] = "My Posted Content";
  523. $Dispatcher =& new Dispatcher();
  524. $test = $Dispatcher->parseParams("/");
  525. $this->assertTrue($test['form'], "Parsed URL not returning post data");
  526. $this->assertIdentical($test['form']['testdata'], "My Posted Content");
  527. }
  528. /**
  529. * testParseParamsWithSingleZero method
  530. *
  531. * @access public
  532. * @return void
  533. */
  534. function testParseParamsWithSingleZero() {
  535. $Dispatcher =& new Dispatcher();
  536. $test = $Dispatcher->parseParams("/testcontroller/testaction/1/0/23");
  537. $this->assertIdentical($test['controller'], 'testcontroller');
  538. $this->assertIdentical($test['action'], 'testaction');
  539. $this->assertIdentical($test['pass'][0], '1');
  540. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
  541. $this->assertIdentical($test['pass'][2], '23');
  542. }
  543. /**
  544. * testParseParamsWithManySingleZeros method
  545. *
  546. * @access public
  547. * @return void
  548. */
  549. function testParseParamsWithManySingleZeros() {
  550. $Dispatcher =& new Dispatcher();
  551. $test = $Dispatcher->parseParams("/testcontroller/testaction/0/0/0/0/0/0");
  552. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][0]);
  553. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
  554. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][2]);
  555. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][3]);
  556. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][4]);
  557. $this->assertPattern('/\\A(?:0)\\z/', $test['pass'][5]);
  558. }
  559. /**
  560. * testParseParamsWithManyZerosInEachSectionOfUrl method
  561. *
  562. * @access public
  563. * @return void
  564. */
  565. function testParseParamsWithManyZerosInEachSectionOfUrl() {
  566. $Dispatcher =& new Dispatcher();
  567. $test = $Dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
  568. $this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0]);
  569. $this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1]);
  570. $this->assertPattern('/\\A(?:00000)\\z/', $test['pass'][2]);
  571. $this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][3]);
  572. $this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][4]);
  573. $this->assertPattern('/\\A(?:0000000)\\z/', $test['pass'][5]);
  574. }
  575. /**
  576. * testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl method
  577. *
  578. * @access public
  579. * @return void
  580. */
  581. function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
  582. $Dispatcher =& new Dispatcher();
  583. $test = $Dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
  584. $this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]);
  585. $this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1]);
  586. $this->assertPattern('/\\A(?:04010)\\z/', $test['pass'][2]);
  587. $this->assertPattern('/\\A(?:000002)\\z/', $test['pass'][3]);
  588. $this->assertPattern('/\\A(?:000030)\\z/', $test['pass'][4]);
  589. $this->assertPattern('/\\A(?:0000400)\\z/', $test['pass'][5]);
  590. }
  591. /**
  592. * testQueryStringOnRoot method
  593. *
  594. * @access public
  595. * @return void
  596. */
  597. function testQueryStringOnRoot() {
  598. $_GET = array('coffee' => 'life', 'sleep' => 'sissies');
  599. $Dispatcher =& new Dispatcher();
  600. $uri = 'posts/home/?coffee=life&sleep=sissies';
  601. $result = $Dispatcher->parseParams($uri);
  602. $this->assertPattern('/posts/', $result['controller']);
  603. $this->assertPattern('/home/', $result['action']);
  604. $this->assertTrue(isset($result['url']['sleep']));
  605. $this->assertTrue(isset($result['url']['coffee']));
  606. $Dispatcher =& new Dispatcher();
  607. $uri = '/?coffee=life&sleep=sissy';
  608. $result = $Dispatcher->parseParams($uri);
  609. $this->assertPattern('/pages/', $result['controller']);
  610. $this->assertPattern('/display/', $result['action']);
  611. $this->assertTrue(isset($result['url']['sleep']));
  612. $this->assertTrue(isset($result['url']['coffee']));
  613. $this->assertEqual($result['url']['coffee'], 'life');
  614. $_GET = $this->_get;
  615. }
  616. /**
  617. * testFileUploadArrayStructure method
  618. *
  619. * @access public
  620. * @return void
  621. */
  622. function testFileUploadArrayStructure() {
  623. $_FILES = array('data' => array('name' => array(
  624. 'File' => array(
  625. array('data' => 'cake_mssql_patch.patch'),
  626. array('data' => 'controller.diff'),
  627. array('data' => ''),
  628. array('data' => ''),
  629. ),
  630. 'Post' => array('attachment' => 'jquery-1.2.1.js'),
  631. ),
  632. 'type' => array(
  633. 'File' => array(
  634. array('data' => ''),
  635. array('data' => ''),
  636. array('data' => ''),
  637. array('data' => ''),
  638. ),
  639. 'Post' => array('attachment' => 'application/x-javascript'),
  640. ),
  641. 'tmp_name' => array(
  642. 'File' => array(
  643. array('data' => '/private/var/tmp/phpy05Ywj'),
  644. array('data' => '/private/var/tmp/php7MBztY'),
  645. array('data' => ''),
  646. array('data' => ''),
  647. ),
  648. 'Post' => array('attachment' => '/private/var/tmp/phpEwlrIo'),
  649. ),
  650. 'error' => array(
  651. 'File' => array(
  652. array('data' => 0),
  653. array('data' => 0),
  654. array('data' => 4),
  655. array('data' => 4)
  656. ),
  657. 'Post' => array('attachment' => 0)
  658. ),
  659. 'size' => array(
  660. 'File' => array(
  661. array('data' => 6271),
  662. array('data' => 350),
  663. array('data' => 0),
  664. array('data' => 0),
  665. ),
  666. 'Post' => array('attachment' => 80469)
  667. ),
  668. ));
  669. $Dispatcher =& new Dispatcher();
  670. $result = $Dispatcher->parseParams('/');
  671. $expected = array(
  672. 'File' => array(
  673. array('data' => array(
  674. 'name' => 'cake_mssql_patch.patch',
  675. 'type' => '',
  676. 'tmp_name' => '/private/var/tmp/phpy05Ywj',
  677. 'error' => 0,
  678. 'size' => 6271,
  679. ),
  680. ),
  681. array('data' => array(
  682. 'name' => 'controller.diff',
  683. 'type' => '',
  684. 'tmp_name' => '/private/var/tmp/php7MBztY',
  685. 'error' => 0,
  686. 'size' => 350,
  687. )),
  688. array('data' => array(
  689. 'name' => '',
  690. 'type' => '',
  691. 'tmp_name' => '',
  692. 'error' => 4,
  693. 'size' => 0,
  694. )),
  695. array('data' => array(
  696. 'name' => '',
  697. 'type' => '',
  698. 'tmp_name' => '',
  699. 'error' => 4,
  700. 'size' => 0,
  701. )),
  702. ),
  703. 'Post' => array('attachment' => array(
  704. 'name' => 'jquery-1.2.1.js',
  705. 'type' => 'application/x-javascript',
  706. 'tmp_name' => '/private/var/tmp/phpEwlrIo',
  707. 'error' => 0,
  708. 'size' => 80469,
  709. )));
  710. $this->assertEqual($result['data'], $expected);
  711. $_FILES = array(
  712. 'data' => array(
  713. 'name' => array(
  714. 'Document' => array(
  715. 1 => array(
  716. 'birth_cert' => 'born on.txt',
  717. 'passport' => 'passport.txt',
  718. 'drivers_license' => 'ugly pic.jpg'
  719. ),
  720. 2 => array(
  721. 'birth_cert' => 'aunt betty.txt',
  722. 'passport' => 'betty-passport.txt',
  723. 'drivers_license' => 'betty-photo.jpg'
  724. ),
  725. ),
  726. ),
  727. 'type' => array(
  728. 'Document' => array(
  729. 1 => array(
  730. 'birth_cert' => 'application/octet-stream',
  731. 'passport' => 'application/octet-stream',
  732. 'drivers_license' => 'application/octet-stream',
  733. ),
  734. 2 => array(
  735. 'birth_cert' => 'application/octet-stream',
  736. 'passport' => 'application/octet-stream',
  737. 'drivers_license' => 'application/octet-stream',
  738. )
  739. )
  740. ),
  741. 'tmp_name' => array(
  742. 'Document' => array(
  743. 1 => array(
  744. 'birth_cert' => '/private/var/tmp/phpbsUWfH',
  745. 'passport' => '/private/var/tmp/php7f5zLt',
  746. 'drivers_license' => '/private/var/tmp/phpMXpZgT',
  747. ),
  748. 2 => array(
  749. 'birth_cert' => '/private/var/tmp/php5kHZt0',
  750. 'passport' => '/private/var/tmp/phpnYkOuM',
  751. 'drivers_license' => '/private/var/tmp/php9Rq0P3',
  752. )
  753. )
  754. ),
  755. 'error' => array(
  756. 'Document' => array(
  757. 1 => array(
  758. 'birth_cert' => 0,
  759. 'passport' => 0,
  760. 'drivers_license' => 0,
  761. ),
  762. 2 => array(
  763. 'birth_cert' => 0,
  764. 'passport' => 0,
  765. 'drivers_license' => 0,
  766. )
  767. )
  768. ),
  769. 'size' => array(
  770. 'Document' => array(
  771. 1 => array(
  772. 'birth_cert' => 123,
  773. 'passport' => 458,
  774. 'drivers_license' => 875,
  775. ),
  776. 2 => array(
  777. 'birth_cert' => 876,
  778. 'passport' => 976,
  779. 'drivers_license' => 9783,
  780. )
  781. )
  782. )
  783. )
  784. );
  785. $Dispatcher =& new Dispatcher();
  786. $result = $Dispatcher->parseParams('/');
  787. $expected = array(
  788. 'Document' => array(
  789. 1 => array(
  790. 'birth_cert' => array(
  791. 'name' => 'born on.txt',
  792. 'tmp_name' => '/private/var/tmp/phpbsUWfH',
  793. 'error' => 0,
  794. 'size' => 123,
  795. 'type' => 'application/octet-stream',
  796. ),
  797. 'passport' => array(
  798. 'name' => 'passport.txt',
  799. 'tmp_name' => '/private/var/tmp/php7f5zLt',
  800. 'error' => 0,
  801. 'size' => 458,
  802. 'type' => 'application/octet-stream',
  803. ),
  804. 'drivers_license' => array(
  805. 'name' => 'ugly pic.jpg',
  806. 'tmp_name' => '/private/var/tmp/phpMXpZgT',
  807. 'error' => 0,
  808. 'size' => 875,
  809. 'type' => 'application/octet-stream',
  810. ),
  811. ),
  812. 2 => array(
  813. 'birth_cert' => array(
  814. 'name' => 'aunt betty.txt',
  815. 'tmp_name' => '/private/var/tmp/php5kHZt0',
  816. 'error' => 0,
  817. 'size' => 876,
  818. 'type' => 'application/octet-stream',
  819. ),
  820. 'passport' => array(
  821. 'name' => 'betty-passport.txt',
  822. 'tmp_name' => '/private/var/tmp/phpnYkOuM',
  823. 'error' => 0,
  824. 'size' => 976,
  825. 'type' => 'application/octet-stream',
  826. ),
  827. 'drivers_license' => array(
  828. 'name' => 'betty-photo.jpg',
  829. 'tmp_name' => '/private/var/tmp/php9Rq0P3',
  830. 'error' => 0,
  831. 'size' => 9783,
  832. 'type' => 'application/octet-stream',
  833. ),
  834. ),
  835. )
  836. );
  837. $this->assertEqual($result['data'], $expected);
  838. $_FILES = array();
  839. }
  840. /**
  841. * testGetUrl method
  842. *
  843. * @access public
  844. * @return void
  845. */
  846. function testGetUrl() {
  847. $Dispatcher =& new Dispatcher();
  848. $Dispatcher->base = '/app/webroot/index.php';
  849. $uri = '/app/webroot/index.php/posts/add';
  850. $result = $Dispatcher->getUrl($uri);
  851. $expected = 'posts/add';
  852. $this->assertEqual($expected, $result);
  853. Configure::write('App.baseUrl', '/app/webroot/index.php');
  854. $uri = '/posts/add';
  855. $result = $Dispatcher->getUrl($uri);
  856. $expected = 'posts/add';
  857. $this->assertEqual($expected, $result);
  858. $_GET['url'] = array();
  859. Configure::write('App.base', '/control');
  860. $Dispatcher =& new Dispatcher();
  861. $Dispatcher->baseUrl();
  862. $uri = '/control/students/browse';
  863. $result = $Dispatcher->getUrl($uri);
  864. $expected = 'students/browse';
  865. $this->assertEqual($expected, $result);
  866. $_GET['url'] = array();
  867. $Dispatcher =& new Dispatcher();
  868. $Dispatcher->base = '';
  869. $uri = '/?/home';
  870. $result = $Dispatcher->getUrl($uri);
  871. $expected = '?/home';
  872. $this->assertEqual($expected, $result);
  873. }
  874. /**
  875. * testBaseUrlAndWebrootWithModRewrite method
  876. *
  877. * @access public
  878. * @return void
  879. */
  880. function testBaseUrlAndWebrootWithModRewrite() {
  881. $Dispatcher =& new Dispatcher();
  882. $Dispatcher->base = false;
  883. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
  884. $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
  885. $_SERVER['PHP_SELF'] = '/1.2.x.x/app/webroot/index.php';
  886. $result = $Dispatcher->baseUrl();
  887. $expected = '/1.2.x.x';
  888. $this->assertEqual($expected, $result);
  889. $expectedWebroot = '/1.2.x.x/';
  890. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  891. $Dispatcher->base = false;
  892. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/app/webroot';
  893. $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
  894. $_SERVER['PHP_SELF'] = '/index.php';
  895. $result = $Dispatcher->baseUrl();
  896. $expected = '';
  897. $this->assertEqual($expected, $result);
  898. $expectedWebroot = '/';
  899. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  900. $Dispatcher->base = false;
  901. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/test/';
  902. $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/test/webroot/index.php';
  903. $_SERVER['PHP_SELF'] = '/webroot/index.php';
  904. $result = $Dispatcher->baseUrl();
  905. $expected = '';
  906. $this->assertEqual($expected, $result);
  907. $expectedWebroot = '/';
  908. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  909. $Dispatcher->base = false;;
  910. $_SERVER['DOCUMENT_ROOT'] = '/some/apps/where';
  911. $_SERVER['SCRIPT_FILENAME'] = '/some/apps/where/app/webroot/index.php';
  912. $_SERVER['PHP_SELF'] = '/some/apps/where/app/webroot/index.php';
  913. $result = $Dispatcher->baseUrl();
  914. $expected = '/some/apps/where';
  915. $this->assertEqual($expected, $result);
  916. $expectedWebroot = '/some/apps/where/';
  917. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  918. Configure::write('App.dir', 'auth');
  919. $Dispatcher->base = false;;
  920. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
  921. $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/demos/auth/webroot/index.php';
  922. $_SERVER['PHP_SELF'] = '/demos/auth/webroot/index.php';
  923. $result = $Dispatcher->baseUrl();
  924. $expected = '/demos/auth';
  925. $this->assertEqual($expected, $result);
  926. $expectedWebroot = '/demos/auth/';
  927. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  928. Configure::write('App.dir', 'code');
  929. $Dispatcher->base = false;;
  930. $_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents';
  931. $_SERVER['SCRIPT_FILENAME'] = '/Library/WebServer/Documents/clients/PewterReport/code/webroot/index.php';
  932. $_SERVER['PHP_SELF'] = '/clients/PewterReport/code/webroot/index.php';
  933. $result = $Dispatcher->baseUrl();
  934. $expected = '/clients/PewterReport/code';
  935. $this->assertEqual($expected, $result);
  936. $expectedWebroot = '/clients/PewterReport/code/';
  937. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  938. }
  939. /**
  940. * testBaseUrlwithModRewriteAlias method
  941. *
  942. * @access public
  943. * @return void
  944. */
  945. function testBaseUrlwithModRewriteAlias() {
  946. $_SERVER['DOCUMENT_ROOT'] = '/home/aplusnur/public_html';
  947. $_SERVER['SCRIPT_FILENAME'] = '/home/aplusnur/cake2/app/webroot/index.php';
  948. $_SERVER['PHP_SELF'] = '/control/index.php';
  949. Configure::write('App.base', '/control');
  950. $Dispatcher =& new Dispatcher();
  951. $result = $Dispatcher->baseUrl();
  952. $expected = '/control';
  953. $this->assertEqual($expected, $result);
  954. $expectedWebroot = '/control/';
  955. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  956. Configure::write('App.base', false);
  957. Configure::write('App.dir', 'affiliate');
  958. Configure::write('App.webroot', 'newaffiliate');
  959. $_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html';
  960. $_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php';
  961. $_SERVER['PHP_SELF'] = '/newaffiliate/index.php';
  962. $Dispatcher =& new Dispatcher();
  963. $result = $Dispatcher->baseUrl();
  964. $expected = '/newaffiliate';
  965. $this->assertEqual($expected, $result);
  966. $expectedWebroot = '/newaffiliate/';
  967. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  968. }
  969. /**
  970. * testBaseUrlAndWebrootWithBaseUrl method
  971. *
  972. * @access public
  973. * @return void
  974. */
  975. function testBaseUrlAndWebrootWithBaseUrl() {
  976. $Dispatcher =& new Dispatcher();
  977. Configure::write('App.dir', 'app');
  978. Configure::write('App.baseUrl', '/app/webroot/index.php');
  979. $result = $Dispatcher->baseUrl();
  980. $expected = '/app/webroot/index.php';
  981. $this->assertEqual($expected, $result);
  982. $expectedWebroot = '/app/webroot/';
  983. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  984. Configure::write('App.baseUrl', '/app/webroot/test.php');
  985. $result = $Dispatcher->baseUrl();
  986. $expected = '/app/webroot/test.php';
  987. $this->assertEqual($expected, $result);
  988. $expectedWebroot = '/app/webroot/';
  989. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  990. Configure::write('App.baseUrl', '/app/index.php');
  991. $result = $Dispatcher->baseUrl();
  992. $expected = '/app/index.php';
  993. $this->assertEqual($expected, $result);
  994. $expectedWebroot = '/app/webroot/';
  995. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  996. Configure::write('App.baseUrl', '/index.php');
  997. $result = $Dispatcher->baseUrl();
  998. $expected = '/index.php';
  999. $this->assertEqual($expected, $result);
  1000. $expectedWebroot = '/app/webroot/';
  1001. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1002. Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
  1003. $result = $Dispatcher->baseUrl();
  1004. $expected = '/CakeBB/app/webroot/index.php';
  1005. $this->assertEqual($expected, $result);
  1006. $expectedWebroot = '/CakeBB/app/webroot/';
  1007. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1008. Configure::write('App.baseUrl', '/CakeBB/app/index.php');
  1009. $result = $Dispatcher->baseUrl();
  1010. $expected = '/CakeBB/app/index.php';
  1011. $this->assertEqual($expected, $result);
  1012. $expectedWebroot = '/CakeBB/app/webroot/';
  1013. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1014. Configure::write('App.baseUrl', '/CakeBB/index.php');
  1015. $result = $Dispatcher->baseUrl();
  1016. $expected = '/CakeBB/index.php';
  1017. $this->assertEqual($expected, $result);
  1018. $expectedWebroot = '/CakeBB/app/webroot/';
  1019. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1020. Configure::write('App.baseUrl', '/dbhauser/index.php');
  1021. $_SERVER['DOCUMENT_ROOT'] = '/kunden/homepages/4/d181710652/htdocs/joomla';
  1022. $_SERVER['SCRIPT_FILENAME'] = '/kunden/homepages/4/d181710652/htdocs/joomla/dbhauser/index.php';
  1023. $result = $Dispatcher->baseUrl();
  1024. $expected = '/dbhauser/index.php';
  1025. $this->assertEqual($expected, $result);
  1026. $expectedWebroot = '/dbhauser/app/webroot/';
  1027. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1028. }
  1029. /**
  1030. * testBaseUrlAndWebrootWithBase method
  1031. *
  1032. * @access public
  1033. * @return void
  1034. */
  1035. function testBaseUrlAndWebrootWithBase() {
  1036. $Dispatcher =& new Dispatcher();
  1037. $Dispatcher->base = '/app';
  1038. $result = $Dispatcher->baseUrl();
  1039. $expected = '/app';
  1040. $this->assertEqual($expected, $result);
  1041. $expectedWebroot = '/app/';
  1042. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1043. $Dispatcher->base = '';
  1044. $result = $Dispatcher->baseUrl();
  1045. $expected = '';
  1046. $this->assertEqual($expected, $result);
  1047. $expectedWebroot = '/';
  1048. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1049. Configure::write('App.dir', 'testbed');
  1050. $Dispatcher->base = '/cake/testbed/webroot';
  1051. $result = $Dispatcher->baseUrl();
  1052. $expected = '/cake/testbed/webroot';
  1053. $this->assertEqual($expected, $result);
  1054. $expectedWebroot = '/cake/testbed/webroot/';
  1055. $this->assertEqual($expectedWebroot, $Dispatcher->webroot);
  1056. }
  1057. /**
  1058. * testMissingController method
  1059. *
  1060. * @access public
  1061. * @return void
  1062. */
  1063. function testMissingController() {
  1064. $Dispatcher =& new TestDispatcher();
  1065. Configure::write('App.baseUrl','/index.php');
  1066. $url = 'some_controller/home/param:value/param2:value2';
  1067. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1068. $expected = 'missingController';
  1069. $this->assertEqual($expected, $controller);
  1070. }
  1071. /**
  1072. * testPrivate method
  1073. *
  1074. * @access public
  1075. * @return void
  1076. */
  1077. function testPrivate() {
  1078. $Dispatcher =& new TestDispatcher();
  1079. Configure::write('App.baseUrl','/index.php');
  1080. $url = 'some_pages/_protected/param:value/param2:value2';
  1081. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1082. $expected = 'privateAction';
  1083. $this->assertEqual($controller, $expected);
  1084. }
  1085. /**
  1086. * testMissingAction method
  1087. *
  1088. * @access public
  1089. * @return void
  1090. */
  1091. function testMissingAction() {
  1092. $Dispatcher =& new TestDispatcher();
  1093. Configure::write('App.baseUrl','/index.php');
  1094. $url = 'some_pages/home/param:value/param2:value2';
  1095. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1096. $expected = 'missingAction';
  1097. $this->assertEqual($expected, $controller);
  1098. $Dispatcher =& new TestDispatcher();
  1099. Configure::write('App.baseUrl','/index.php');
  1100. $url = 'some_pages/redirect/param:value/param2:value2';
  1101. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1102. $expected = 'missingAction';
  1103. $this->assertEqual($expected, $controller);
  1104. }
  1105. /**
  1106. * testDispatch method
  1107. *
  1108. * @access public
  1109. * @return void
  1110. */
  1111. function testDispatch() {
  1112. $Dispatcher =& new TestDispatcher();
  1113. Configure::write('App.baseUrl','/index.php');
  1114. $url = 'pages/home/param:value/param2:value2';
  1115. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1116. $expected = 'Pages';
  1117. $this->assertEqual($expected, $controller->name);
  1118. $expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
  1119. $this->assertIdentical($expected, $controller->passedArgs);
  1120. Configure::write('App.baseUrl','/pages/index.php');
  1121. $url = 'pages/home';
  1122. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1123. $expected = 'Pages';
  1124. $this->assertEqual($expected, $controller->name);
  1125. $url = 'pages/home/';
  1126. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1127. $expected = 'Pages';
  1128. $this->assertEqual($expected, $controller->name);
  1129. unset($Dispatcher);
  1130. $Dispatcher =& new TestDispatcher();
  1131. Configure::write('App.baseUrl','/timesheets/index.php');
  1132. $url = 'timesheets';
  1133. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1134. $expected = 'Timesheets';
  1135. $this->assertEqual($expected, $controller->name);
  1136. $url = 'timesheets/';
  1137. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1138. $this->assertEqual('Timesheets', $controller->name);
  1139. $this->assertEqual('/timesheets/index.php', $Dispatcher->base);
  1140. $url = 'test_dispatch_pages/camelCased';
  1141. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1142. $this->assertEqual('TestDispatchPages', $controller->name);
  1143. }
  1144. /**
  1145. * testAdminDispatch method
  1146. *
  1147. * @access public
  1148. * @return void
  1149. */
  1150. function testAdminDispatch() {
  1151. $_POST = array();
  1152. $Dispatcher =& new TestDispatcher();
  1153. Configure::write('Routing.admin', 'admin');
  1154. Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php');
  1155. $url = 'admin/test_dispatch_pages/index/param:value/param2:value2';
  1156. Router::reload();
  1157. $Router =& Router::getInstance();
  1158. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1159. $expected = 'TestDispatchPages';
  1160. $this->assertEqual($expected, $controller->name);
  1161. $expected = array('param' => 'value', 'param2' => 'value2');
  1162. $this->assertIdentical($expected, $controller->passedArgs);
  1163. $this->assertTrue($controller->params['admin']);
  1164. $expected = '/cake/repo/branches/1.2.x.x/index.php/admin/test_dispatch_pages/index/param:value/param2:value2';
  1165. $this->assertIdentical($expected, $controller->here);
  1166. $expected = '/cake/repo/branches/1.2.x.x/index.php';
  1167. $this->assertIdentical($expected, $controller->base);
  1168. }
  1169. /**
  1170. * testPluginDispatch method
  1171. *
  1172. * @access public
  1173. * @return void
  1174. */
  1175. function testPluginDispatch() {
  1176. $_POST = array();
  1177. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1178. Router::reload();
  1179. $Dispatcher =& new TestDispatcher();
  1180. Router::connect('/my_plugin/:controller/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display'));
  1181. $Dispatcher->base = false;
  1182. $url = 'my_plugin/some_pages/home/param:value/param2:value2';
  1183. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1184. $result = $Dispatcher->parseParams($url);
  1185. $expected = array(
  1186. 'pass' => array('home'),
  1187. 'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
  1188. 'controller'=> 'some_pages', 'action'=> 'display', 'form'=> null,
  1189. 'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'),
  1190. );
  1191. ksort($expected);
  1192. ksort($result);
  1193. $this->assertEqual($expected, $result);
  1194. $expected = 'my_plugin';
  1195. $this->assertIdentical($expected, $controller->plugin);
  1196. $expected = 'SomePages';
  1197. $this->assertIdentical($expected, $controller->name);
  1198. $expected = array('0' => 'home', 'param'=>'value', 'param2'=>'value2');
  1199. $this->assertIdentical($expected, $controller->passedArgs);
  1200. $expected = '/cake/repo/branches/1.2.x.x/my_plugin/some_pages/home/param:value/param2:value2';
  1201. $this->assertIdentical($expected, $controller->here);
  1202. $expected = '/cake/repo/branches/1.2.x.x';
  1203. $this->assertIdentical($expected, $controller->base);
  1204. }
  1205. /**
  1206. * testAutomaticPluginDispatch method
  1207. *
  1208. * @access public
  1209. * @return void
  1210. */
  1211. function testAutomaticPluginDispatch() {
  1212. $_POST = array();
  1213. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1214. Router::reload();
  1215. $Dispatcher =& new TestDispatcher();
  1216. Router::connect('/my_plugin/:controller/:action/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display'));
  1217. $Dispatcher->base = false;
  1218. $url = 'my_plugin/other_pages/index/param:value/param2:value2';
  1219. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1220. $expected = 'my_plugin';
  1221. $this->assertIdentical($expected, $controller->plugin);
  1222. $expected = 'OtherPages';
  1223. $this->assertIdentical($expected, $controller->name);
  1224. $expected = 'index';
  1225. $this->assertIdentical($expected, $controller->action);
  1226. $expected = array('param' => 'value', 'param2' => 'value2');
  1227. $this->assertIdentical($expected, $controller->passedArgs);
  1228. $expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2';
  1229. $this->assertIdentical($expected, $controller->here);
  1230. $expected = '/cake/repo/branches/1.2.x.x';
  1231. $this->assertIdentical($expected, $controller->base);
  1232. }
  1233. /**
  1234. * testAutomaticPluginControllerDispatch method
  1235. *
  1236. * @access public
  1237. * @return void
  1238. */
  1239. function testAutomaticPluginControllerDispatch() {
  1240. $_POST = array();
  1241. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1242. Router::reload();
  1243. $Dispatcher =& new TestDispatcher();
  1244. $Dispatcher->base = false;
  1245. $url = 'my_plugin/add/param:value/param2:value2';
  1246. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1247. $expected = 'my_plugin';
  1248. $this->assertIdentical($controller->plugin, $expected);
  1249. $expected = 'MyPlugin';
  1250. $this->assertIdentical($controller->name, $expected);
  1251. $expected = 'add';
  1252. $this->assertIdentical($controller->action, $expected);
  1253. $expected = array('param' => 'value', 'param2' => 'value2');
  1254. $this->assertEqual($controller->params['named'], $expected);
  1255. Configure::write('Routing.admin', 'admin');
  1256. Router::reload();
  1257. $Dispatcher =& new TestDispatcher();
  1258. $Dispatcher->base = false;
  1259. $url = 'admin/my_plugin/add/5/param:value/param2:value2';
  1260. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1261. $expected = 'my_plugin';
  1262. $this->assertIdentical($controller->plugin, $expected);
  1263. $expected = 'MyPlugin';
  1264. $this->assertIdentical($controller->name, $expected);
  1265. $expected = 'admin_add';
  1266. $this->assertIdentical($controller->action, $expected);
  1267. $expected = array(0 => 5, 'param'=>'value', 'param2'=>'value2');
  1268. $this->assertEqual($controller->passedArgs, $expected);
  1269. Router::reload();
  1270. $Dispatcher =& new TestDispatcher();
  1271. $Dispatcher->base = false;
  1272. $controller = $Dispatcher->dispatch('admin/articles_test', array('return' => 1));
  1273. $expected = 'articles_test';
  1274. $this->assertIdentical($controller->plugin, $expected);
  1275. $expected = 'ArticlesTest';
  1276. $this->assertIdentical($controller->name, $expected);
  1277. $expected = 'admin_index';
  1278. $this->assertIdentical($controller->action, $expected);
  1279. $expected = array(
  1280. 'pass'=> array(), 'named' => array(), 'controller' => 'articles_test', 'plugin' => 'articles_test', 'action' => 'admin_index',
  1281. 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/articles_test'), 'return' => 1
  1282. );
  1283. $this->assertEqual($controller->params, $expected);
  1284. }
  1285. /**
  1286. * testAutomaticPluginControllerMissingActionDispatch method
  1287. *
  1288. * @access public
  1289. * @return void
  1290. */
  1291. function testAutomaticPluginControllerMissingActionDispatch() {
  1292. $_POST = array();
  1293. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1294. Router::reload();
  1295. $Dispatcher =& new TestDispatcher();
  1296. $Dispatcher->base = false;
  1297. $url = 'my_plugin/param:value/param2:value2';
  1298. $controller = $Dispatcher->dispatch($url, array('return'=> 1));
  1299. $expected = 'missingAction';
  1300. $this->assertIdentical($expected, $controller);
  1301. }
  1302. /**
  1303. * testPrefixProtection method
  1304. *
  1305. * @access public
  1306. * @return void
  1307. */
  1308. function testPrefixProtection() {
  1309. $_POST = array();
  1310. $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
  1311. Router::reload();
  1312. Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin'), array('controller', 'action'));
  1313. $Dispatcher =& new TestDispatcher();
  1314. $Dispatcher->base = false;
  1315. $url = 'test_dispatch_pages/admin_index/param:value/param2:value2';
  1316. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1317. $expected = 'privateAction';
  1318. $this->assertIdentical($expected, $controller);
  1319. }
  1320. /**
  1321. * undocumented function
  1322. *
  1323. * @return void
  1324. **/
  1325. function testTestPluginDispatch() {
  1326. $Dispatcher =& new TestDispatcher();
  1327. $_back = Configure::read('pluginPaths');
  1328. Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
  1329. $url = '/test_plugin/tests/index';
  1330. $result = $Dispatcher->dispatch($url, array('return' => 1));
  1331. $this->assertTrue(class_exists('TestsController'));
  1332. $this->assertTrue(class_exists('TestPluginAppController'));
  1333. $this->assertTrue(class_exists('OtherComponentComponent'));
  1334. $this->assertTrue(class_exists('PluginsComponentComponent'));
  1335. Configure::write('pluginPaths', $_back);
  1336. }
  1337. /**
  1338. * testChangingParamsFromBeforeFilter method
  1339. *
  1340. * @access public
  1341. * @return void
  1342. */
  1343. function testChangingParamsFromBeforeFilter() {
  1344. $Dispatcher =& new TestDispatcher();
  1345. $url = 'some_posts/index/param:value/param2:value2';
  1346. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1347. $expected = 'missingAction';
  1348. $this->assertEqual($expected, $controller);
  1349. $url = 'some_posts/something_else/param:value/param2:value2';
  1350. $controller = $Dispatcher->dispatch($url, array('return' => 1));
  1351. $expected = 'SomePosts';
  1352. $this->assertEqual($expected, $controller->name);
  1353. $expected = 'change';
  1354. $this->assertEqual($expected, $controller->action);
  1355. $expected = array('changed');
  1356. $this->assertIdentical($expected, $controller->params['pass']);
  1357. }
  1358. /**
  1359. * testStaticAssets method
  1360. *
  1361. * @access public
  1362. * @return void
  1363. */
  1364. function testStaticAssets() {
  1365. Router::reload();
  1366. $Configure = Configure::getInstance();
  1367. $Configure->__objects = null;
  1368. Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
  1369. Configure::write('vendorPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS));
  1370. $Dispatcher =& new TestDispatcher();
  1371. Configure::write('debug', 0);
  1372. ob_start();
  1373. $Dispatcher->dispatch('/img/test.jpg');
  1374. $result = ob_get_clean();
  1375. $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'img' . DS . 'test.jpg');
  1376. $this->assertEqual($file, $result);
  1377. Configure::write('debug', 0);
  1378. $Dispatcher->params = $Dispatcher->parseParams('css/test_asset.css');
  1379. ob_start();
  1380. $Dispatcher->cached('css/test_asset.css');
  1381. $result = ob_get_clean();
  1382. $this->assertEqual('this is the test asset css file', $result);
  1383. Configure::write('debug', 0);
  1384. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css');
  1385. ob_start();
  1386. $Dispatcher->cached('test_plugin/css/test_plugin_asset.css');
  1387. $result = ob_get_clean();
  1388. $this->assertEqual('this is the test plugin asset css file', $result);
  1389. Configure::write('debug', 0);
  1390. $Dispatcher->params = $Dispatcher->parseParams('test_plugin/img/cake.icon.gif');
  1391. ob_start();
  1392. $Dispatcher->cached('test_plugin/img/cake.icon.gif');
  1393. $result = ob_get_clean();
  1394. $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' .DS . 'vendors' . DS . 'img' . DS . 'cake.icon.gif');
  1395. $this->assertEqual($file, $result);
  1396. header('Content-type: text/html');//reset the header content-type without page can render as plain text.
  1397. }
  1398. /**
  1399. * testFullPageCachingDispatch method
  1400. *
  1401. * @access public
  1402. * @return void
  1403. */
  1404. function testFullPageCachingDispatch() {
  1405. Configure::write('Cache.disable', false);
  1406. Configure::write('Cache.check', true);
  1407. Configure::write('debug', 2);
  1408. $_POST = array();
  1409. $_SERVER['PHP_SELF'] = '/';
  1410. Router::reload();
  1411. Router::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index'));
  1412. Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
  1413. $dispatcher =& new Dispatcher();
  1414. $dispatcher->base = false;
  1415. $url = '/';
  1416. ob_start();
  1417. $dispatcher->dispatch($url);
  1418. $out = ob_get_clean();
  1419. ob_start();
  1420. $dispatcher->cached($url);
  1421. $cached = ob_get_clean();
  1422. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1423. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1424. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1425. $this->assertEqual($result, $expected);
  1426. $filename = $this->__cachePath($dispatcher->here);
  1427. unlink($filename);
  1428. $dispatcher->base = false;
  1429. $url = 'test_cached_pages/index';
  1430. ob_start();
  1431. $dispatcher->dispatch($url);
  1432. $out = ob_get_clean();
  1433. ob_start();
  1434. $dispatcher->cached($url);
  1435. $cached = ob_get_clean();
  1436. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1437. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1438. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1439. $this->assertEqual($result, $expected);
  1440. $filename = $this->__cachePath($dispatcher->here);
  1441. unlink($filename);
  1442. $url = 'TestCachedPages/index';
  1443. ob_start();
  1444. $dispatcher->dispatch($url);
  1445. $out = ob_get_clean();
  1446. ob_start();
  1447. $dispatcher->cached($url);
  1448. $cached = ob_get_clean();
  1449. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1450. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1451. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1452. $this->assertEqual($result, $expected);
  1453. $filename = $this->__cachePath($dispatcher->here);
  1454. unlink($filename);
  1455. $url = 'TestCachedPages/test_nocache_tags';
  1456. ob_start();
  1457. $dispatcher->dispatch($url);
  1458. $out = ob_get_clean();
  1459. ob_start();
  1460. $dispatcher->cached($url);
  1461. $cached = ob_get_clean();
  1462. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1463. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1464. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1465. $this->assertEqual($result, $expected);
  1466. $filename = $this->__cachePath($dispatcher->here);
  1467. unlink($filename);
  1468. $url = 'test_cached_pages/view/param/param';
  1469. ob_start();
  1470. $dispatcher->dispatch($url);
  1471. $out = ob_get_clean();
  1472. ob_start();
  1473. $dispatcher->cached($url);
  1474. $cached = ob_get_clean();
  1475. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1476. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1477. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1478. $this->assertEqual($result, $expected);
  1479. $filename = $this->__cachePath($dispatcher->here);
  1480. unlink($filename);
  1481. $url = 'test_cached_pages/view/foo:bar/value:goo';
  1482. ob_start();
  1483. $dispatcher->dispatch($url);
  1484. $out = ob_get_clean();
  1485. ob_start();
  1486. $dispatcher->cached($url);
  1487. $cached = ob_get_clean();
  1488. $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
  1489. $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
  1490. $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
  1491. $this->assertEqual($result, $expected);
  1492. $filename = $this->__cachePath($dispatcher->here);
  1493. $this->assertTrue(file_exists($filename));
  1494. unlink($filename);
  1495. }
  1496. /**
  1497. * testHttpMethodOverrides method
  1498. *
  1499. * @access public
  1500. * @return void
  1501. */
  1502. function testHttpMethodOverrides() {
  1503. Router::reload();
  1504. Router::mapResources('Posts');
  1505. $_SERVER['REQUEST_METHOD'] = 'POST';
  1506. $dispatcher =& new Dispatcher();
  1507. $dispatcher->base = false;
  1508. $result = $dispatcher->parseParams('/posts');
  1509. $expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'form' => array(), 'url' => array());
  1510. $this->assertEqual($result, $expected);
  1511. $_SERVER['REQUEST_METHOD'] = 'GET';
  1512. $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
  1513. $result = $dispatcher->parseParams('/posts/5');
  1514. $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
  1515. $this->assertEqual($result, $expected);
  1516. unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
  1517. $_SERVER['REQUEST_METHOD'] = 'GET';
  1518. $result = $dispatcher->parseParams('/posts/5');
  1519. $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'form' => array(), 'url' => array());
  1520. $this->assertEqual($result, $expected);
  1521. $_POST['_method'] = 'PUT';
  1522. $result = $dispatcher->parseParams('/posts/5');
  1523. $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
  1524. $this->assertEqual($result, $expected);
  1525. $_POST['_method'] = 'POST';
  1526. $_POST['data'] = array('Post' => array('title' => 'New Post'));
  1527. $_POST['extra'] = 'data';
  1528. $_SERVER = array();
  1529. $result = $dispatcher->parseParams('/posts');
  1530. $expected = array(
  1531. 'pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add',
  1532. '[method]' => 'POST', 'form' => array('extra' => 'data'), 'data' => array('Post' => array('title' => 'New Post')),
  1533. 'url' => array()
  1534. );
  1535. $this->assertEqual($result, $expected);
  1536. unset($_POST['_method']);
  1537. }
  1538. /**
  1539. * testEnvironmentDetection method
  1540. *
  1541. * @access public
  1542. * @return void
  1543. */
  1544. function testEnvironmentDetection() {
  1545. $dispatcher =& new Dispatcher();
  1546. $environments = array(
  1547. 'IIS' => array(
  1548. 'No rewrite base path' => array(
  1549. 'App' => array('base' => false, 'baseUrl' => '/index.php?', 'server' => 'IIS'),
  1550. 'SERVER' => array('HTTPS' => 'off', 'SCRIPT_NAME' => '/index.php', 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot', 'QUERY_STRING' => '', 'REMOTE_ADDR' => '127.0.0.1', 'REMOTE_HOST' => '127.0.0.1', 'REQUEST_METHOD' => 'GET', 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => '80', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'SERVER_SOFTWARE' => 'Microsoft-IIS/5.1', 'APPL_PHYSICAL_PATH' => 'C:\\Inetpub\\wwwroot\\', 'REQUEST_URI' => '/index.php', 'URL' => '/index.php', 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php', 'ORIG_PATH_INFO' => '/index.php', 'PATH_INFO' => '', 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\index.php', 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot', 'PHP_SELF' => '/index.php', 'HTTP_ACCEPT' => '*/*', 'HTTP_ACCEPT_LANGUAGE' => 'en-us', 'HTTP_CONNECTION' => 'Keep-Alive', 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'argv' => array(), 'argc' => 0),
  1551. 'reload' => true,
  1552. 'path' => ''
  1553. ),
  1554. 'No rewrite with path' => array(
  1555. 'SERVER' => array('QUERY_STRING' => '/posts/add', 'REQUEST_URI' => '/index.php?/posts/add', 'URL' => '/index.php?/posts/add', 'argv' => array('/posts/add'), 'argc' => 1),
  1556. 'reload' => false,
  1557. 'path' => '/posts/add'
  1558. ),
  1559. 'No rewrite sub dir 1' => array(
  1560. 'GET' => array(),
  1561. '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'

Large files files are truncated, but you can click here to view the full file