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

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

https://bitbucket.org/aaoliveira/bibliocake
PHP | 2489 lines | 1495 code | 331 blank | 663 comment | 18 complexity | da142310395d529785f4f1d67bae7e73 MD5 | raw file

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

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

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