Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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