PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

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

http://myopensources.googlecode.com/
PHP | 2242 lines | 1358 code | 239 blank | 645 comment | 17 complexity | cb41377786034d5ea161fcff3b3590a0 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

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

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

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