PageRenderTime 66ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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