ControllerTest.php 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP Project
  11. * @package Cake.Test.Case.Controller
  12. * @since CakePHP(tm) v 1.2.0.5436
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. App::uses('Controller', 'Controller');
  16. App::uses('Router', 'Routing');
  17. App::uses('CakeRequest', 'Network');
  18. App::uses('CakeResponse', 'Network');
  19. App::uses('SecurityComponent', 'Controller/Component');
  20. App::uses('CookieComponent', 'Controller/Component');
  21. /**
  22. * AppController class
  23. *
  24. * @package Cake.Test.Case.Controller
  25. */
  26. class ControllerTestAppController extends Controller {
  27. /**
  28. * helpers property
  29. *
  30. * @var array
  31. */
  32. public $helpers = array('Html');
  33. /**
  34. * uses property
  35. *
  36. * @var array
  37. */
  38. public $uses = array('ControllerPost');
  39. /**
  40. * components property
  41. *
  42. * @var array
  43. */
  44. public $components = array('Cookie');
  45. }
  46. /**
  47. * ControllerPost class
  48. *
  49. * @package Cake.Test.Case.Controller
  50. */
  51. class ControllerPost extends CakeTestModel {
  52. /**
  53. * name property
  54. *
  55. * @var string 'ControllerPost'
  56. */
  57. public $name = 'ControllerPost';
  58. /**
  59. * useTable property
  60. *
  61. * @var string 'posts'
  62. */
  63. public $useTable = 'posts';
  64. /**
  65. * invalidFields property
  66. *
  67. * @var array
  68. */
  69. public $invalidFields = array('name' => 'error_msg');
  70. /**
  71. * lastQuery property
  72. *
  73. * @var mixed null
  74. */
  75. public $lastQuery = null;
  76. /**
  77. * beforeFind method
  78. *
  79. * @param mixed $query
  80. * @return void
  81. */
  82. public function beforeFind($query) {
  83. $this->lastQuery = $query;
  84. }
  85. /**
  86. * find method
  87. *
  88. * @param string $type
  89. * @param array $options
  90. * @return void
  91. */
  92. public function find($type = 'first', $options = array()) {
  93. if ($type == 'popular') {
  94. $conditions = array($this->name . '.' . $this->primaryKey . ' > ' => '1');
  95. $options = Hash::merge($options, compact('conditions'));
  96. return parent::find('all', $options);
  97. }
  98. return parent::find($type, $options);
  99. }
  100. }
  101. /**
  102. * ControllerPostsController class
  103. *
  104. * @package Cake.Test.Case.Controller
  105. */
  106. class ControllerCommentsController extends ControllerTestAppController {
  107. /**
  108. * name property
  109. *
  110. * @var string 'ControllerPost'
  111. */
  112. public $name = 'ControllerComments';
  113. protected $_mergeParent = 'ControllerTestAppController';
  114. }
  115. /**
  116. * ControllerComment class
  117. *
  118. * @package Cake.Test.Case.Controller
  119. */
  120. class ControllerComment extends CakeTestModel {
  121. /**
  122. * name property
  123. *
  124. * @var string 'ControllerComment'
  125. */
  126. public $name = 'Comment';
  127. /**
  128. * useTable property
  129. *
  130. * @var string 'comments'
  131. */
  132. public $useTable = 'comments';
  133. /**
  134. * data property
  135. *
  136. * @var array
  137. */
  138. public $data = array('name' => 'Some Name');
  139. /**
  140. * alias property
  141. *
  142. * @var string 'ControllerComment'
  143. */
  144. public $alias = 'ControllerComment';
  145. }
  146. /**
  147. * ControllerAlias class
  148. *
  149. * @package Cake.Test.Case.Controller
  150. */
  151. class ControllerAlias extends CakeTestModel {
  152. /**
  153. * name property
  154. *
  155. * @var string 'ControllerAlias'
  156. */
  157. public $name = 'ControllerAlias';
  158. /**
  159. * alias property
  160. *
  161. * @var string 'ControllerSomeAlias'
  162. */
  163. public $alias = 'ControllerSomeAlias';
  164. /**
  165. * useTable property
  166. *
  167. * @var string 'posts'
  168. */
  169. public $useTable = 'posts';
  170. }
  171. /**
  172. * NameTest class
  173. *
  174. * @package Cake.Test.Case.Controller
  175. */
  176. class NameTest extends CakeTestModel {
  177. /**
  178. * name property
  179. * @var string 'Name'
  180. */
  181. public $name = 'Name';
  182. /**
  183. * useTable property
  184. * @var string 'names'
  185. */
  186. public $useTable = 'comments';
  187. /**
  188. * alias property
  189. *
  190. * @var string 'ControllerComment'
  191. */
  192. public $alias = 'Name';
  193. }
  194. /**
  195. * TestController class
  196. *
  197. * @package Cake.Test.Case.Controller
  198. */
  199. class TestController extends ControllerTestAppController {
  200. /**
  201. * name property
  202. * @var string 'Name'
  203. */
  204. public $name = 'Test';
  205. /**
  206. * helpers property
  207. *
  208. * @var array
  209. */
  210. public $helpers = array('Session');
  211. /**
  212. * components property
  213. *
  214. * @var array
  215. */
  216. public $components = array('Security');
  217. /**
  218. * uses property
  219. *
  220. * @var array
  221. */
  222. public $uses = array('ControllerComment', 'ControllerAlias');
  223. protected $_mergeParent = 'ControllerTestAppController';
  224. /**
  225. * index method
  226. *
  227. * @param mixed $testId
  228. * @param mixed $test2Id
  229. * @return void
  230. */
  231. public function index($testId, $testTwoId) {
  232. $this->data = array(
  233. 'testId' => $testId,
  234. 'test2Id' => $testTwoId
  235. );
  236. }
  237. /**
  238. * view method
  239. *
  240. * @param mixed $testId
  241. * @param mixed $test2Id
  242. * @return void
  243. */
  244. public function view($testId, $testTwoId) {
  245. $this->data = array(
  246. 'testId' => $testId,
  247. 'test2Id' => $testTwoId
  248. );
  249. }
  250. public function returner() {
  251. return 'I am from the controller.';
  252. }
  253. //@codingStandardsIgnoreStart
  254. protected function protected_m() {
  255. }
  256. private function private_m() {
  257. }
  258. public function _hidden() {
  259. }
  260. //@codingStandardsIgnoreEnd
  261. public function admin_add() {
  262. }
  263. }
  264. /**
  265. * TestComponent class
  266. *
  267. * @package Cake.Test.Case.Controller
  268. */
  269. class TestComponent extends Object {
  270. /**
  271. * beforeRedirect method
  272. *
  273. * @return void
  274. */
  275. public function beforeRedirect() {
  276. }
  277. /**
  278. * initialize method
  279. *
  280. * @return void
  281. */
  282. public function initialize(Controller $controller) {
  283. }
  284. /**
  285. * startup method
  286. *
  287. * @return void
  288. */
  289. public function startup(Controller $controller) {
  290. }
  291. /**
  292. * shutdown method
  293. *
  294. * @return void
  295. */
  296. public function shutdown(Controller $controller) {
  297. }
  298. /**
  299. * beforeRender callback
  300. *
  301. * @return void
  302. */
  303. public function beforeRender(Controller $controller) {
  304. if ($this->viewclass) {
  305. $controller->viewClass = $this->viewclass;
  306. }
  307. }
  308. }
  309. class Test2Component extends TestComponent {
  310. public function beforeRender(Controller $controller) {
  311. return false;
  312. }
  313. }
  314. /**
  315. * AnotherTestController class
  316. *
  317. * @package Cake.Test.Case.Controller
  318. */
  319. class AnotherTestController extends ControllerTestAppController {
  320. /**
  321. * name property
  322. * @var string 'Name'
  323. */
  324. public $name = 'AnotherTest';
  325. /**
  326. * uses property
  327. *
  328. * @var array
  329. */
  330. public $uses = false;
  331. /**
  332. * merge parent
  333. *
  334. * @var string
  335. */
  336. protected $_mergeParent = 'ControllerTestAppController';
  337. }
  338. /**
  339. * ControllerTest class
  340. *
  341. * @package Cake.Test.Case.Controller
  342. */
  343. class ControllerTest extends CakeTestCase {
  344. /**
  345. * fixtures property
  346. *
  347. * @var array
  348. */
  349. public $fixtures = array(
  350. 'core.post',
  351. 'core.comment'
  352. );
  353. /**
  354. * reset environment.
  355. *
  356. * @return void
  357. */
  358. public function setUp() {
  359. parent::setUp();
  360. App::objects('plugin', null, false);
  361. App::build();
  362. Router::reload();
  363. }
  364. /**
  365. * tearDown
  366. *
  367. * @return void
  368. */
  369. public function tearDown() {
  370. parent::tearDown();
  371. CakePlugin::unload();
  372. }
  373. /**
  374. * testLoadModel method
  375. *
  376. * @return void
  377. */
  378. public function testLoadModel() {
  379. $request = new CakeRequest('controller_posts/index');
  380. $response = $this->getMock('CakeResponse');
  381. $Controller = new Controller($request, $response);
  382. $this->assertFalse(isset($Controller->ControllerPost));
  383. $result = $Controller->loadModel('ControllerPost');
  384. $this->assertTrue($result);
  385. $this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
  386. $this->assertTrue(in_array('ControllerPost', $Controller->uses));
  387. ClassRegistry::flush();
  388. unset($Controller);
  389. }
  390. /**
  391. * testLoadModel method from a plugin controller
  392. *
  393. * @return void
  394. */
  395. public function testLoadModelInPlugins() {
  396. App::build(array(
  397. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
  398. 'Controller' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS),
  399. 'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS)
  400. ));
  401. CakePlugin::load('TestPlugin');
  402. App::uses('TestPluginAppController', 'TestPlugin.Controller');
  403. App::uses('TestPluginController', 'TestPlugin.Controller');
  404. $Controller = new TestPluginController();
  405. $Controller->plugin = 'TestPlugin';
  406. $Controller->uses = false;
  407. $this->assertFalse(isset($Controller->Comment));
  408. $result = $Controller->loadModel('Comment');
  409. $this->assertTrue($result);
  410. $this->assertInstanceOf('Comment', $Controller->Comment);
  411. $this->assertTrue(in_array('Comment', $Controller->uses));
  412. ClassRegistry::flush();
  413. unset($Controller);
  414. }
  415. /**
  416. * testConstructClasses method
  417. *
  418. * @return void
  419. */
  420. public function testConstructClasses() {
  421. $request = new CakeRequest('controller_posts/index');
  422. $Controller = new Controller($request);
  423. $Controller->uses = array('ControllerPost', 'ControllerComment');
  424. $Controller->constructClasses();
  425. $this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
  426. $this->assertTrue(is_a($Controller->ControllerComment, 'ControllerComment'));
  427. $this->assertEquals('Comment', $Controller->ControllerComment->name);
  428. unset($Controller);
  429. App::build(array('Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
  430. CakePlugin::load('TestPlugin');
  431. $Controller = new Controller($request);
  432. $Controller->uses = array('TestPlugin.TestPluginPost');
  433. $Controller->constructClasses();
  434. $this->assertTrue(isset($Controller->TestPluginPost));
  435. $this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost'));
  436. }
  437. /**
  438. * testAliasName method
  439. *
  440. * @return void
  441. */
  442. public function testAliasName() {
  443. $request = new CakeRequest('controller_posts/index');
  444. $Controller = new Controller($request);
  445. $Controller->uses = array('NameTest');
  446. $Controller->constructClasses();
  447. $this->assertEquals('Name', $Controller->NameTest->name);
  448. $this->assertEquals('Name', $Controller->NameTest->alias);
  449. unset($Controller);
  450. }
  451. /**
  452. * testFlash method
  453. *
  454. * @return void
  455. */
  456. public function testFlash() {
  457. $request = new CakeRequest('controller_posts/index');
  458. $request->webroot = '/';
  459. $request->base = '/';
  460. $Controller = new Controller($request, $this->getMock('CakeResponse', array('_sendHeader')));
  461. $Controller->flash('this should work', '/flash');
  462. $result = $Controller->response->body();
  463. $expected = '<!DOCTYPE html>
  464. <html>
  465. <head>
  466. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  467. <title>this should work</title>
  468. <style><!--
  469. P { text-align:center; font:bold 1.1em sans-serif }
  470. A { color:#444; text-decoration:none }
  471. A:HOVER { text-decoration: underline; color:#44E }
  472. --></style>
  473. </head>
  474. <body>
  475. <p><a href="/flash">this should work</a></p>
  476. </body>
  477. </html>';
  478. $result = str_replace(array("\t", "\r\n", "\n"), "", $result);
  479. $expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
  480. $this->assertEquals($expected, $result);
  481. App::build(array(
  482. 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
  483. ));
  484. $Controller = new Controller($request);
  485. $Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
  486. $Controller->flash('this should work', '/flash', 1, 'ajax2');
  487. $result = $Controller->response->body();
  488. $this->assertRegExp('/Ajax!/', $result);
  489. App::build();
  490. }
  491. /**
  492. * testControllerSet method
  493. *
  494. * @return void
  495. */
  496. public function testControllerSet() {
  497. $request = new CakeRequest('controller_posts/index');
  498. $Controller = new Controller($request);
  499. $Controller->set('variable_with_underscores', null);
  500. $this->assertTrue(array_key_exists('variable_with_underscores', $Controller->viewVars));
  501. $Controller->viewVars = array();
  502. $viewVars = array('ModelName' => array('id' => 1, 'name' => 'value'));
  503. $Controller->set($viewVars);
  504. $this->assertTrue(array_key_exists('ModelName', $Controller->viewVars));
  505. $Controller->viewVars = array();
  506. $Controller->set('variable_with_underscores', 'value');
  507. $this->assertTrue(array_key_exists('variable_with_underscores', $Controller->viewVars));
  508. $Controller->viewVars = array();
  509. $viewVars = array('ModelName' => 'name');
  510. $Controller->set($viewVars);
  511. $this->assertTrue(array_key_exists('ModelName', $Controller->viewVars));
  512. $Controller->set('title', 'someTitle');
  513. $this->assertSame($Controller->viewVars['title'], 'someTitle');
  514. $this->assertTrue(empty($Controller->pageTitle));
  515. $Controller->viewVars = array();
  516. $expected = array('ModelName' => 'name', 'ModelName2' => 'name2');
  517. $Controller->set(array('ModelName', 'ModelName2'), array('name', 'name2'));
  518. $this->assertSame($expected, $Controller->viewVars);
  519. $Controller->viewVars = array();
  520. $Controller->set(array(3 => 'three', 4 => 'four'));
  521. $Controller->set(array(1 => 'one', 2 => 'two'));
  522. $expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
  523. $this->assertEquals($expected, $Controller->viewVars);
  524. }
  525. /**
  526. * testRender method
  527. *
  528. * @return void
  529. */
  530. public function testRender() {
  531. App::build(array(
  532. 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
  533. ), App::RESET);
  534. ClassRegistry::flush();
  535. $request = new CakeRequest('controller_posts/index');
  536. $request->params['action'] = 'index';
  537. $Controller = new Controller($request, new CakeResponse());
  538. $Controller->viewPath = 'Posts';
  539. $result = $Controller->render('index');
  540. $this->assertRegExp('/posts index/', (string)$result);
  541. $Controller->view = 'index';
  542. $result = $Controller->render();
  543. $this->assertRegExp('/posts index/', (string)$result);
  544. $result = $Controller->render('/Elements/test_element');
  545. $this->assertRegExp('/this is the test element/', (string)$result);
  546. $Controller->view = null;
  547. $Controller = new TestController($request, new CakeResponse());
  548. $Controller->uses = array('ControllerAlias', 'TestPlugin.ControllerComment', 'ControllerPost');
  549. $Controller->helpers = array('Html');
  550. $Controller->constructClasses();
  551. $Controller->ControllerComment->validationErrors = array('title' => 'tooShort');
  552. $expected = $Controller->ControllerComment->validationErrors;
  553. $Controller->viewPath = 'Posts';
  554. $result = $Controller->render('index');
  555. $View = $Controller->View;
  556. $this->assertTrue(isset($View->validationErrors['ControllerComment']));
  557. $this->assertEquals($expected, $View->validationErrors['ControllerComment']);
  558. $expectedModels = array(
  559. 'ControllerAlias' => array('plugin' => null, 'className' => 'ControllerAlias'),
  560. 'ControllerComment' => array('plugin' => 'TestPlugin', 'className' => 'ControllerComment'),
  561. 'ControllerPost' => array('plugin' => null, 'className' => 'ControllerPost')
  562. );
  563. $this->assertEquals($expectedModels, $Controller->request->params['models']);
  564. ClassRegistry::flush();
  565. App::build();
  566. }
  567. /**
  568. * test that a component beforeRender can change the controller view class.
  569. *
  570. * @return void
  571. */
  572. public function testComponentBeforeRenderChangingViewClass() {
  573. App::build(array(
  574. 'View' => array(
  575. CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS
  576. )
  577. ), true);
  578. $Controller = new Controller($this->getMock('CakeRequest'), new CakeResponse());
  579. $Controller->uses = array();
  580. $Controller->components = array('Test');
  581. $Controller->constructClasses();
  582. $Controller->Test->viewclass = 'Theme';
  583. $Controller->viewPath = 'Posts';
  584. $Controller->theme = 'TestTheme';
  585. $result = $Controller->render('index');
  586. $this->assertRegExp('/default test_theme layout/', (string)$result);
  587. App::build();
  588. }
  589. /**
  590. * test that a component beforeRender can change the controller view class.
  591. *
  592. * @return void
  593. */
  594. public function testComponentCancelRender() {
  595. $Controller = new Controller($this->getMock('CakeRequest'), new CakeResponse());
  596. $Controller->uses = array();
  597. $Controller->components = array('Test2');
  598. $Controller->constructClasses();
  599. $result = $Controller->render('index');
  600. $this->assertInstanceOf('CakeResponse', $result);
  601. }
  602. /**
  603. * testToBeInheritedGuardmethods method
  604. *
  605. * @return void
  606. */
  607. public function testToBeInheritedGuardmethods() {
  608. $request = new CakeRequest('controller_posts/index');
  609. $Controller = new Controller($request, $this->getMock('CakeResponse'));
  610. $this->assertTrue($Controller->beforeScaffold(''));
  611. $this->assertTrue($Controller->afterScaffoldSave(''));
  612. $this->assertTrue($Controller->afterScaffoldSaveError(''));
  613. $this->assertFalse($Controller->scaffoldError(''));
  614. }
  615. /**
  616. * Generates status codes for redirect test.
  617. *
  618. * @return void
  619. */
  620. public static function statusCodeProvider() {
  621. return array(
  622. array(300, "Multiple Choices"),
  623. array(301, "Moved Permanently"),
  624. array(302, "Found"),
  625. array(303, "See Other"),
  626. array(304, "Not Modified"),
  627. array(305, "Use Proxy"),
  628. array(307, "Temporary Redirect"),
  629. array(403, "Forbidden"),
  630. );
  631. }
  632. /**
  633. * testRedirect method
  634. *
  635. * @dataProvider statusCodeProvider
  636. * @return void
  637. */
  638. public function testRedirectByCode($code, $msg) {
  639. $Controller = new Controller(null);
  640. $Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
  641. $Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
  642. $Controller->response->expects($this->once())->method('statusCode')
  643. ->with($code);
  644. $Controller->response->expects($this->once())->method('header')
  645. ->with('Location', 'http://cakephp.org');
  646. $Controller->redirect('http://cakephp.org', (int)$code, false);
  647. $this->assertFalse($Controller->autoRender);
  648. }
  649. /**
  650. * test redirecting by message
  651. *
  652. * @dataProvider statusCodeProvider
  653. * @return void
  654. */
  655. public function testRedirectByMessage($code, $msg) {
  656. $Controller = new Controller(null);
  657. $Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
  658. $Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
  659. $Controller->response->expects($this->once())->method('statusCode')
  660. ->with($code);
  661. $Controller->response->expects($this->once())->method('header')
  662. ->with('Location', 'http://cakephp.org');
  663. $Controller->redirect('http://cakephp.org', $msg, false);
  664. $this->assertFalse($Controller->autoRender);
  665. }
  666. /**
  667. * test that redirect triggers methods on the components.
  668. *
  669. * @return void
  670. */
  671. public function testRedirectTriggeringComponentsReturnNull() {
  672. $Controller = new Controller(null);
  673. $Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
  674. $Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
  675. $Controller->Components->expects($this->once())->method('trigger')
  676. ->will($this->returnValue(null));
  677. $Controller->response->expects($this->once())->method('statusCode')
  678. ->with(301);
  679. $Controller->response->expects($this->once())->method('header')
  680. ->with('Location', 'http://cakephp.org');
  681. $Controller->redirect('http://cakephp.org', 301, false);
  682. }
  683. /**
  684. * test that beforeRedirect callback returning null doesn't affect things.
  685. *
  686. * @return void
  687. */
  688. public function testRedirectBeforeRedirectModifyingParams() {
  689. $Controller = new Controller(null);
  690. $Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
  691. $Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
  692. $Controller->Components->expects($this->once())->method('trigger')
  693. ->will($this->returnValue(array('http://book.cakephp.org')));
  694. $Controller->response->expects($this->once())->method('statusCode')
  695. ->with(301);
  696. $Controller->response->expects($this->once())->method('header')
  697. ->with('Location', 'http://book.cakephp.org');
  698. $Controller->redirect('http://cakephp.org', 301, false);
  699. }
  700. /**
  701. * test that beforeRedirect callback returning null doesn't affect things.
  702. *
  703. * @return void
  704. */
  705. public function testRedirectBeforeRedirectModifyingParamsArrayReturn() {
  706. $Controller = $this->getMock('Controller', array('header', '_stop'));
  707. $Controller->response = $this->getMock('CakeResponse');
  708. $Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
  709. $return = array(
  710. array(
  711. 'url' => 'http://example.com/test/1',
  712. 'exit' => false,
  713. 'status' => 302
  714. ),
  715. array(
  716. 'url' => 'http://example.com/test/2',
  717. ),
  718. );
  719. $Controller->Components->expects($this->once())->method('trigger')
  720. ->will($this->returnValue($return));
  721. $Controller->response->expects($this->once())->method('header')
  722. ->with('Location', 'http://example.com/test/2');
  723. $Controller->response->expects($this->at(1))->method('statusCode')
  724. ->with(302);
  725. $Controller->expects($this->never())->method('_stop');
  726. $Controller->redirect('http://cakephp.org', 301);
  727. }
  728. /**
  729. * test that beforeRedirect callback returning false in controller
  730. *
  731. * @return void
  732. */
  733. public function testRedirectBeforeRedirectInController() {
  734. $Controller = $this->getMock('Controller', array('_stop', 'beforeRedirect'));
  735. $Controller->response = $this->getMock('CakeResponse', array('header'));
  736. $Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
  737. $Controller->expects($this->once())->method('beforeRedirect')
  738. ->with('http://cakephp.org')
  739. ->will($this->returnValue(false));
  740. $Controller->response->expects($this->never())->method('header');
  741. $Controller->expects($this->never())->method('_stop');
  742. $Controller->redirect('http://cakephp.org');
  743. }
  744. /**
  745. * Test that beforeRedirect works with returning an array from the controller method.
  746. *
  747. * @return void
  748. */
  749. public function testRedirectBeforeRedirectInControllerWithArray() {
  750. $Controller = $this->getMock('Controller', array('_stop', 'beforeRedirect'));
  751. $Controller->response = $this->getMock('CakeResponse', array('header'));
  752. $Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
  753. $Controller->expects($this->once())
  754. ->method('beforeRedirect')
  755. ->with('http://cakephp.org', null, true)
  756. ->will($this->returnValue(array(
  757. 'url' => 'http://example.org',
  758. 'status' => 302,
  759. 'exit' => true
  760. )));
  761. $Controller->response->expects($this->at(0))
  762. ->method('header')
  763. ->with('Location', 'http://example.org');
  764. $Controller->expects($this->once())->method('_stop');
  765. $Controller->redirect('http://cakephp.org');
  766. }
  767. /**
  768. * testMergeVars method
  769. *
  770. * @return void
  771. */
  772. public function testMergeVars() {
  773. $request = new CakeRequest('controller_posts/index');
  774. $TestController = new TestController($request);
  775. $TestController->constructClasses();
  776. $testVars = get_class_vars('TestController');
  777. $appVars = get_class_vars('ControllerTestAppController');
  778. $components = is_array($appVars['components'])
  779. ? array_merge($appVars['components'], $testVars['components'])
  780. : $testVars['components'];
  781. if (!in_array('Session', $components)) {
  782. $components[] = 'Session';
  783. }
  784. $helpers = is_array($appVars['helpers'])
  785. ? array_merge($appVars['helpers'], $testVars['helpers'])
  786. : $testVars['helpers'];
  787. $uses = is_array($appVars['uses'])
  788. ? array_merge($appVars['uses'], $testVars['uses'])
  789. : $testVars['uses'];
  790. $this->assertEquals(0, count(array_diff_key($TestController->helpers, array_flip($helpers))));
  791. $this->assertEquals(0, count(array_diff($TestController->uses, $uses)));
  792. $this->assertEquals(count(array_diff_assoc(Hash::normalize($TestController->components), Hash::normalize($components))), 0);
  793. $expected = array('ControllerComment', 'ControllerAlias', 'ControllerPost');
  794. $this->assertEquals($expected, $TestController->uses, '$uses was merged incorrectly, ControllerTestAppController models should be last.');
  795. $TestController = new AnotherTestController($request);
  796. $TestController->constructClasses();
  797. $appVars = get_class_vars('ControllerTestAppController');
  798. $testVars = get_class_vars('AnotherTestController');
  799. $this->assertTrue(in_array('ControllerPost', $appVars['uses']));
  800. $this->assertFalse($testVars['uses']);
  801. $this->assertFalse(property_exists($TestController, 'ControllerPost'));
  802. $TestController = new ControllerCommentsController($request);
  803. $TestController->constructClasses();
  804. $appVars = get_class_vars('ControllerTestAppController');
  805. $testVars = get_class_vars('ControllerCommentsController');
  806. $this->assertTrue(in_array('ControllerPost', $appVars['uses']));
  807. $this->assertEquals(array('ControllerPost'), $testVars['uses']);
  808. $this->assertTrue(isset($TestController->ControllerPost));
  809. $this->assertTrue(isset($TestController->ControllerComment));
  810. }
  811. /**
  812. * test that options from child classes replace those in the parent classes.
  813. *
  814. * @return void
  815. */
  816. public function testChildComponentOptionsSupercedeParents() {
  817. $request = new CakeRequest('controller_posts/index');
  818. $TestController = new TestController($request);
  819. $expected = array('foo');
  820. $TestController->components = array('Cookie' => $expected);
  821. $TestController->constructClasses();
  822. $this->assertEquals($expected, $TestController->components['Cookie']);
  823. }
  824. /**
  825. * Ensure that _mergeControllerVars is not being greedy and merging with
  826. * ControllerTestAppController when you make an instance of Controller
  827. *
  828. * @return void
  829. */
  830. public function testMergeVarsNotGreedy() {
  831. $request = new CakeRequest('controller_posts/index');
  832. $Controller = new Controller($request);
  833. $Controller->components = array();
  834. $Controller->uses = array();
  835. $Controller->constructClasses();
  836. $this->assertFalse(isset($Controller->Session));
  837. }
  838. /**
  839. * testReferer method
  840. *
  841. * @return void
  842. */
  843. public function testReferer() {
  844. $request = $this->getMock('CakeRequest');
  845. $request->expects($this->any())->method('referer')
  846. ->with(true)
  847. ->will($this->returnValue('/posts/index'));
  848. $Controller = new Controller($request);
  849. $result = $Controller->referer(null, true);
  850. $this->assertEquals('/posts/index', $result);
  851. $Controller = new Controller($request);
  852. $request->setReturnValue('referer', '/', array(true));
  853. $result = $Controller->referer(array('controller' => 'posts', 'action' => 'index'), true);
  854. $this->assertEquals('/posts/index', $result);
  855. $request = $this->getMock('CakeRequest');
  856. $request->expects($this->any())->method('referer')
  857. ->with(false)
  858. ->will($this->returnValue('http://localhost/posts/index'));
  859. $Controller = new Controller($request);
  860. $result = $Controller->referer();
  861. $this->assertEquals('http://localhost/posts/index', $result);
  862. $Controller = new Controller(null);
  863. $result = $Controller->referer();
  864. $this->assertEquals('/', $result);
  865. }
  866. /**
  867. * testSetAction method
  868. *
  869. * @return void
  870. */
  871. public function testSetAction() {
  872. $request = new CakeRequest('controller_posts/index');
  873. $TestController = new TestController($request);
  874. $TestController->setAction('view', 1, 2);
  875. $expected = array('testId' => 1, 'test2Id' => 2);
  876. $this->assertSame($expected, $TestController->request->data);
  877. $this->assertSame('view', $TestController->request->params['action']);
  878. $this->assertSame('view', $TestController->view);
  879. }
  880. /**
  881. * testValidateErrors method
  882. *
  883. * @return void
  884. */
  885. public function testValidateErrors() {
  886. ClassRegistry::flush();
  887. $request = new CakeRequest('controller_posts/index');
  888. $TestController = new TestController($request);
  889. $TestController->constructClasses();
  890. $this->assertFalse($TestController->validateErrors());
  891. $this->assertEquals(0, $TestController->validate());
  892. $TestController->ControllerComment->invalidate('some_field', 'error_message');
  893. $TestController->ControllerComment->invalidate('some_field2', 'error_message2');
  894. $comment = new ControllerComment($request);
  895. $comment->set('someVar', 'data');
  896. $result = $TestController->validateErrors($comment);
  897. $expected = array('some_field' => array('error_message'), 'some_field2' => array('error_message2'));
  898. $this->assertSame($expected, $result);
  899. $this->assertEquals(2, $TestController->validate($comment));
  900. }
  901. /**
  902. * test that validateErrors works with any old model.
  903. *
  904. * @return void
  905. */
  906. public function testValidateErrorsOnArbitraryModels() {
  907. $TestController = new TestController();
  908. $Post = new ControllerPost();
  909. $Post->validate = array('title' => 'notEmpty');
  910. $Post->set('title', '');
  911. $result = $TestController->validateErrors($Post);
  912. $expected = array('title' => array('This field cannot be left blank'));
  913. $this->assertEquals($expected, $result);
  914. }
  915. /**
  916. * testPostConditions method
  917. *
  918. * @return void
  919. */
  920. public function testPostConditions() {
  921. $request = new CakeRequest('controller_posts/index');
  922. $Controller = new Controller($request);
  923. $data = array(
  924. 'Model1' => array('field1' => '23'),
  925. 'Model2' => array('field2' => 'string'),
  926. 'Model3' => array('field3' => '23'),
  927. );
  928. $expected = array(
  929. 'Model1.field1' => '23',
  930. 'Model2.field2' => 'string',
  931. 'Model3.field3' => '23',
  932. );
  933. $result = $Controller->postConditions($data);
  934. $this->assertSame($expected, $result);
  935. $data = array();
  936. $Controller->data = array(
  937. 'Model1' => array('field1' => '23'),
  938. 'Model2' => array('field2' => 'string'),
  939. 'Model3' => array('field3' => '23'),
  940. );
  941. $expected = array(
  942. 'Model1.field1' => '23',
  943. 'Model2.field2' => 'string',
  944. 'Model3.field3' => '23',
  945. );
  946. $result = $Controller->postConditions($data);
  947. $this->assertSame($expected, $result);
  948. $data = array();
  949. $Controller->data = array();
  950. $result = $Controller->postConditions($data);
  951. $this->assertNull($result);
  952. $data = array();
  953. $Controller->data = array(
  954. 'Model1' => array('field1' => '23'),
  955. 'Model2' => array('field2' => 'string'),
  956. 'Model3' => array('field3' => '23'),
  957. );
  958. $ops = array(
  959. 'Model1.field1' => '>',
  960. 'Model2.field2' => 'LIKE',
  961. 'Model3.field3' => '<=',
  962. );
  963. $expected = array(
  964. 'Model1.field1 >' => '23',
  965. 'Model2.field2 LIKE' => "%string%",
  966. 'Model3.field3 <=' => '23',
  967. );
  968. $result = $Controller->postConditions($data, $ops);
  969. $this->assertSame($expected, $result);
  970. }
  971. /**
  972. * testControllerHttpCodes method
  973. *
  974. * @return void
  975. */
  976. public function testControllerHttpCodes() {
  977. $response = $this->getMock('CakeResponse', array('httpCodes'));
  978. $Controller = new Controller(null, $response);
  979. $Controller->response->expects($this->at(0))->method('httpCodes')->with(null);
  980. $Controller->response->expects($this->at(1))->method('httpCodes')->with(100);
  981. $Controller->httpCodes();
  982. $Controller->httpCodes(100);
  983. }
  984. /**
  985. * Tests that the startup process calls the correct functions
  986. *
  987. * @return void
  988. */
  989. public function testStartupProcess() {
  990. $Controller = $this->getMock('Controller', array('getEventManager'));
  991. $eventManager = $this->getMock('CakeEventManager');
  992. $eventManager->expects($this->at(0))->method('dispatch')
  993. ->with(
  994. $this->logicalAnd(
  995. $this->isInstanceOf('CakeEvent'),
  996. $this->attributeEqualTo('_name', 'Controller.initialize'),
  997. $this->attributeEqualTo('_subject', $Controller)
  998. )
  999. );
  1000. $eventManager->expects($this->at(1))->method('dispatch')
  1001. ->with(
  1002. $this->logicalAnd(
  1003. $this->isInstanceOf('CakeEvent'),
  1004. $this->attributeEqualTo('_name', 'Controller.startup'),
  1005. $this->attributeEqualTo('_subject', $Controller)
  1006. )
  1007. );
  1008. $Controller->expects($this->exactly(2))->method('getEventManager')
  1009. ->will($this->returnValue($eventManager));
  1010. $Controller->startupProcess();
  1011. }
  1012. /**
  1013. * Tests that the shutdown process calls the correct functions
  1014. *
  1015. * @return void
  1016. */
  1017. public function testStartupProcessIndirect() {
  1018. $Controller = $this->getMock('Controller', array('beforeFilter'));
  1019. $Controller->components = array('MockShutdown');
  1020. $Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
  1021. $Controller->expects($this->once())->method('beforeFilter');
  1022. $Controller->Components->expects($this->exactly(2))->method('trigger')->with($this->isInstanceOf('CakeEvent'));
  1023. $Controller->startupProcess();
  1024. }
  1025. /**
  1026. * Tests that the shutdown process calls the correct functions
  1027. *
  1028. * @return void
  1029. */
  1030. public function testShutdownProcess() {
  1031. $Controller = $this->getMock('Controller', array('getEventManager'));
  1032. $eventManager = $this->getMock('CakeEventManager');
  1033. $eventManager->expects($this->once())->method('dispatch')
  1034. ->with(
  1035. $this->logicalAnd(
  1036. $this->isInstanceOf('CakeEvent'),
  1037. $this->attributeEqualTo('_name', 'Controller.shutdown'),
  1038. $this->attributeEqualTo('_subject', $Controller)
  1039. )
  1040. );
  1041. $Controller->expects($this->once())->method('getEventManager')
  1042. ->will($this->returnValue($eventManager));
  1043. $Controller->shutdownProcess();
  1044. }
  1045. /**
  1046. * Tests that the shutdown process calls the correct functions
  1047. *
  1048. * @return void
  1049. */
  1050. public function testShutdownProcessIndirect() {
  1051. $Controller = $this->getMock('Controller', array('afterFilter'));
  1052. $Controller->components = array('MockShutdown');
  1053. $Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
  1054. $Controller->expects($this->once())->method('afterFilter');
  1055. $Controller->Components->expects($this->exactly(1))->method('trigger')->with($this->isInstanceOf('CakeEvent'));
  1056. $Controller->shutdownProcess();
  1057. }
  1058. /**
  1059. * test that BC works for attributes on the request object.
  1060. *
  1061. * @return void
  1062. */
  1063. public function testPropertyBackwardsCompatibility() {
  1064. $request = new CakeRequest('posts/index', false);
  1065. $request->addParams(array('controller' => 'posts', 'action' => 'index'));
  1066. $request->data = array('Post' => array('id' => 1));
  1067. $request->here = '/posts/index';
  1068. $request->webroot = '/';
  1069. $Controller = new TestController($request);
  1070. $this->assertEquals($request->data, $Controller->data);
  1071. $this->assertEquals($request->webroot, $Controller->webroot);
  1072. $this->assertEquals($request->here, $Controller->here);
  1073. $this->assertEquals($request->action, $Controller->action);
  1074. $this->assertFalse(empty($Controller->data));
  1075. $this->assertTrue(isset($Controller->data));
  1076. $this->assertTrue(empty($Controller->something));
  1077. $this->assertFalse(isset($Controller->something));
  1078. $this->assertEquals($request, $Controller->params);
  1079. $this->assertEquals($request->params['controller'], $Controller->params['controller']);
  1080. }
  1081. /**
  1082. * test that the BC wrapper doesn't interfere with models and components.
  1083. *
  1084. * @return void
  1085. */
  1086. public function testPropertyCompatibilityAndModelsComponents() {
  1087. $request = new CakeRequest('controller_posts/index');
  1088. $Controller = new TestController($request);
  1089. $Controller->constructClasses();
  1090. $this->assertInstanceOf('SecurityComponent', $Controller->Security);
  1091. $this->assertInstanceOf('ControllerComment', $Controller->ControllerComment);
  1092. }
  1093. /**
  1094. * test that using Controller::paginate() falls back to PaginatorComponent
  1095. *
  1096. * @return void
  1097. */
  1098. public function testPaginateBackwardsCompatibility() {
  1099. $request = new CakeRequest('controller_posts/index');
  1100. $request->params['pass'] = $request->params['named'] = array();
  1101. $response = $this->getMock('CakeResponse', array('httpCodes'));
  1102. $Controller = new Controller($request, $response);
  1103. $Controller->uses = array('ControllerPost', 'ControllerComment');
  1104. $Controller->passedArgs[] = '1';
  1105. $Controller->params['url'] = array();
  1106. $Controller->constructClasses();
  1107. $expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named');
  1108. $this->assertEquals($expected, $Controller->paginate);
  1109. $results = Hash::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
  1110. $this->assertEquals(array(1, 2, 3), $results);
  1111. $Controller->passedArgs = array();
  1112. $Controller->paginate = array('limit' => '1');
  1113. $this->assertEquals(array('limit' => '1'), $Controller->paginate);
  1114. $Controller->paginate('ControllerPost');
  1115. $this->assertSame($Controller->params['paging']['ControllerPost']['page'], 1);
  1116. $this->assertSame($Controller->params['paging']['ControllerPost']['pageCount'], 3);
  1117. $this->assertSame($Controller->params['paging']['ControllerPost']['prevPage'], false);
  1118. $this->assertSame($Controller->params['paging']['ControllerPost']['nextPage'], true);
  1119. }
  1120. /**
  1121. * testMissingAction method
  1122. *
  1123. * @expectedException MissingActionException
  1124. * @expectedExceptionMessage Action TestController::missing() could not be found.
  1125. * @return void
  1126. */
  1127. public function testInvokeActionMissingAction() {
  1128. $url = new CakeRequest('test/missing');
  1129. $url->addParams(array('controller' => 'test_controller', 'action' => 'missing'));
  1130. $response = $this->getMock('CakeResponse');
  1131. $Controller = new TestController($url, $response);
  1132. $Controller->invokeAction($url);
  1133. }
  1134. /**
  1135. * test invoking private methods.
  1136. *
  1137. * @expectedException PrivateActionException
  1138. * @expectedExceptionMessage Private Action TestController::private_m() is not directly accessible.
  1139. * @return void
  1140. */
  1141. public function testInvokeActionPrivate() {
  1142. $url = new CakeRequest('test/private_m/');
  1143. $url->addParams(array('controller' => 'test_controller', 'action' => 'private_m'));
  1144. $response = $this->getMock('CakeResponse');
  1145. $Controller = new TestController($url, $response);
  1146. $Controller->invokeAction($url);
  1147. }
  1148. /**
  1149. * test invoking protected methods.
  1150. *
  1151. * @expectedException PrivateActionException
  1152. * @expectedExceptionMessage Private Action TestController::protected_m() is not directly accessible.
  1153. * @return void
  1154. */
  1155. public function testInvokeActionProtected() {
  1156. $url = new CakeRequest('test/protected_m/');
  1157. $url->addParams(array('controller' => 'test_controller', 'action' => 'protected_m'));
  1158. $response = $this->getMock('CakeResponse');
  1159. $Controller = new TestController($url, $response);
  1160. $Controller->invokeAction($url);
  1161. }
  1162. /**
  1163. * test invoking hidden methods.
  1164. *
  1165. * @expectedException PrivateActionException
  1166. * @expectedExceptionMessage Private Action TestController::_hidden() is not directly accessible.
  1167. * @return void
  1168. */
  1169. public function testInvokeActionHidden() {
  1170. $url = new CakeRequest('test/_hidden/');
  1171. $url->addParams(array('controller' => 'test_controller', 'action' => '_hidden'));
  1172. $response = $this->getMock('CakeResponse');
  1173. $Controller = new TestController($url, $response);
  1174. $Controller->invokeAction($url);
  1175. }
  1176. /**
  1177. * test invoking controller methods.
  1178. *
  1179. * @expectedException PrivateActionException
  1180. * @expectedExceptionMessage Private Action TestController::redirect() is not directly accessible.
  1181. * @return void
  1182. */
  1183. public function testInvokeActionBaseMethods() {
  1184. $url = new CakeRequest('test/redirect/');
  1185. $url->addParams(array('controller' => 'test_controller', 'action' => 'redirect'));
  1186. $response = $this->getMock('CakeResponse');
  1187. $Controller = new TestController($url, $response);
  1188. $Controller->invokeAction($url);
  1189. }
  1190. /**
  1191. * test invoking controller methods.
  1192. *
  1193. * @expectedException PrivateActionException
  1194. * @expectedExceptionMessage Private Action TestController::admin_add() is not directly accessible.
  1195. * @return void
  1196. */
  1197. public function testInvokeActionPrefixProtection() {
  1198. Router::reload();
  1199. Router::connect('/admin/:controller/:action/*', array('prefix' => 'admin'));
  1200. $url = new CakeRequest('test/admin_add/');
  1201. $url->addParams(array('controller' => 'test_controller', 'action' => 'admin_add'));
  1202. $response = $this->getMock('CakeResponse');
  1203. $Controller = new TestController($url, $response);
  1204. $Controller->invokeAction($url);
  1205. }
  1206. /**
  1207. * test invoking controller methods.
  1208. *
  1209. * @return void
  1210. */
  1211. public function testInvokeActionReturnValue() {
  1212. $url = new CakeRequest('test/returner/');
  1213. $url->addParams(array(
  1214. 'controller' => 'test_controller',
  1215. 'action' => 'returner',
  1216. 'pass' => array()
  1217. ));
  1218. $response = $this->getMock('CakeResponse');
  1219. $Controller = new TestController($url, $response);
  1220. $result = $Controller->invokeAction($url);
  1221. $this->assertEquals('I am from the controller.', $result);
  1222. }
  1223. }