PageRenderTime 65ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/miamiruby/cakestuff
PHP | 1943 lines | 1137 code | 188 blank | 618 comment | 16 complexity | 5f91432dd183fb48322b15a8afbc8aa3 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.0, MIT

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

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

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