PageRenderTime 62ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/cases/dispatcher.test.php

https://github.com/daviebf/cake1_2_9
PHP | 2253 lines | 1368 code | 241 blank | 644 comment | 17 complexity | 4e4ff47c918fdbfdd20b15d5f28eecb3 MD5 | raw file

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

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