PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

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

http://github.com/Datawalke/Coordino
PHP | 2625 lines | 1642 code | 343 blank | 640 comment | 18 complexity | 96eacdb30f0822786585913b5cd11ec8 MD5 | raw file

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

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

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