PageRenderTime 52ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/mattraykowski/ryzomcore_demoshard
PHP | 2600 lines | 1626 code | 339 blank | 635 comment | 18 complexity | 71ef4d14aa2ec702da0881f3f167e5ef MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, LGPL-2.1

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

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