source: Dev/branches/cakephp/cake/tests/cases/libs/object.test.php @ 126

Last change on this file since 126 was 126, checked in by fpvanagthoven, 14 years ago

Cakephp branch.

File size: 23.7 KB
Line 
1<?php
2/**
3 * ObjectTest file
4 *
5 * PHP versions 4 and 5
6 *
7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
8 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
9 *
10 *  Licensed under The Open Group Test Suite License
11 *  Redistributions of files must retain the above copyright notice.
12 *
13 * @copyright     Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
14 * @link          http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
15 * @package       cake
16 * @subpackage    cake.tests.cases.libs
17 * @since         CakePHP(tm) v 1.2.0.5432
18 * @license       http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
19 */
20App::import('Core', array('Object', 'Controller', 'Model'));
21
22/**
23 * RequestActionPost class
24 *
25 * @package       cake
26 * @subpackage    cake.tests.cases.libs.object
27 */
28class RequestActionPost extends CakeTestModel {
29
30/**
31 * name property
32 *
33 * @var string 'ControllerPost'
34 * @access public
35 */
36        var $name = 'RequestActionPost';
37
38/**
39 * useTable property
40 *
41 * @var string 'posts'
42 * @access public
43 */
44        var $useTable = 'posts';
45}
46
47/**
48 * RequestActionController class
49 *
50 * @package       cake
51 * @subpackage    cake.tests.cases.libs
52 */
53class RequestActionController extends Controller {
54
55/**
56* uses property
57*
58* @var array
59* @access public
60*/
61        var $uses = array('RequestActionPost');
62
63/**
64* test_request_action method
65*
66* @access public
67* @return void
68*/
69        function test_request_action() {
70                return 'This is a test';
71        }
72
73/**
74* another_ra_test method
75*
76* @param mixed $id
77* @param mixed $other
78* @access public
79* @return void
80*/
81        function another_ra_test($id, $other) {
82                return $id + $other;
83        }
84
85/**
86 * normal_request_action method
87 *
88 * @access public
89 * @return void
90 */
91        function normal_request_action() {
92                return 'Hello World';
93        }
94
95/**
96 * returns $this->here
97 *
98 * @return void
99 */
100        function return_here() {
101                return $this->here;
102        }
103
104/**
105 * paginate_request_action method
106 *
107 * @access public
108 * @return void
109 */
110        function paginate_request_action() {
111                $data = $this->paginate();
112                return true;
113        }
114
115/**
116 * post pass, testing post passing
117 *
118 * @return array
119 */
120        function post_pass() {
121                return $this->data;
122        }
123
124/**
125 * test param passing and parsing.
126 *
127 * @return array
128 */
129        function params_pass() {
130                return $this->params;
131        }
132}
133
134/**
135 * RequestActionPersistentController class
136 *
137 * @package       cake
138 * @subpackage    cake.tests.cases.libs
139 */
140class RequestActionPersistentController extends Controller {
141
142/**
143* uses property
144*
145* @var array
146* @access public
147*/
148        var $uses = array('PersisterOne');
149
150/**
151* persistModel property
152*
153* @var array
154* @access public
155*/
156        var $persistModel = true;
157
158/**
159 * post pass, testing post passing
160 *
161 * @return array
162 */
163        function index() {
164                return 'This is a test';
165        }
166}
167
168/**
169 * TestObject class
170 *
171 * @package       cake
172 * @subpackage    cake.tests.cases.libs
173 */
174class TestObject extends Object {
175
176/**
177 * firstName property
178 *
179 * @var string 'Joel'
180 * @access public
181 */
182        var $firstName = 'Joel';
183
184/**
185 * lastName property
186 *
187 * @var string 'Moss'
188 * @access public
189 */
190        var $lastName = 'Moss';
191
192/**
193 * methodCalls property
194 *
195 * @var array
196 * @access public
197 */
198        var $methodCalls = array();
199
200/**
201 * emptyMethod method
202 *
203 * @access public
204 * @return void
205 */
206        function emptyMethod() {
207                $this->methodCalls[] = 'emptyMethod';
208        }
209
210/**
211 * oneParamMethod method
212 *
213 * @param mixed $param
214 * @access public
215 * @return void
216 */
217        function oneParamMethod($param) {
218                $this->methodCalls[] = array('oneParamMethod' => array($param));
219        }
220
221/**
222 * twoParamMethod method
223 *
224 * @param mixed $param
225 * @param mixed $param2
226 * @access public
227 * @return void
228 */
229        function twoParamMethod($param, $param2) {
230                $this->methodCalls[] = array('twoParamMethod' => array($param, $param2));
231        }
232
233/**
234 * threeParamMethod method
235 *
236 * @param mixed $param
237 * @param mixed $param2
238 * @param mixed $param3
239 * @access public
240 * @return void
241 */
242        function threeParamMethod($param, $param2, $param3) {
243                $this->methodCalls[] = array('threeParamMethod' => array($param, $param2, $param3));
244        }
245        /**
246 * fourParamMethod method
247 *
248 * @param mixed $param
249 * @param mixed $param2
250 * @param mixed $param3
251 * @param mixed $param4
252 * @access public
253 * @return void
254 */
255        function fourParamMethod($param, $param2, $param3, $param4) {
256                $this->methodCalls[] = array('fourParamMethod' => array($param, $param2, $param3, $param4));
257        }
258        /**
259 * fiveParamMethod method
260 *
261 * @param mixed $param
262 * @param mixed $param2
263 * @param mixed $param3
264 * @param mixed $param4
265 * @param mixed $param5
266 * @access public
267 * @return void
268 */
269        function fiveParamMethod($param, $param2, $param3, $param4, $param5) {
270                $this->methodCalls[] = array('fiveParamMethod' => array($param, $param2, $param3, $param4, $param5));
271        }
272
273/**
274 * crazyMethod method
275 *
276 * @param mixed $param
277 * @param mixed $param2
278 * @param mixed $param3
279 * @param mixed $param4
280 * @param mixed $param5
281 * @param mixed $param6
282 * @param mixed $param7
283 * @access public
284 * @return void
285 */
286        function crazyMethod($param, $param2, $param3, $param4, $param5, $param6, $param7 = null) {
287                $this->methodCalls[] = array('crazyMethod' => array($param, $param2, $param3, $param4, $param5, $param6, $param7));
288        }
289
290/**
291 * methodWithOptionalParam method
292 *
293 * @param mixed $param
294 * @access public
295 * @return void
296 */
297        function methodWithOptionalParam($param = null) {
298                $this->methodCalls[] = array('methodWithOptionalParam' => array($param));
299        }
300
301/**
302 * testPersist
303 *
304 * @return void
305 */
306        function testPersist($name, $return = null, &$object, $type = null) {
307                return $this->_persist($name, $return, $object, $type);
308        }
309}
310
311/**
312 * ObjectTestModel class
313 *
314 * @package       cake
315 * @subpackage    cake.tests.cases.libs
316 */
317class ObjectTestModel extends CakeTestModel {
318        var $useTable = false;
319        var $name = 'ObjectTestModel';
320}
321
322/**
323 * Object Test class
324 *
325 * @package       cake
326 * @subpackage    cake.tests.cases.libs
327 */
328class ObjectTest extends CakeTestCase {
329
330/**
331 * fixtures
332 *
333 * @var string
334 */
335        var $fixtures = array('core.post', 'core.test_plugin_comment', 'core.comment');
336
337/**
338 * setUp method
339 *
340 * @access public
341 * @return void
342 */
343        function setUp() {
344                $this->object = new TestObject();
345        }
346
347/**
348 * tearDown method
349 *
350 * @access public
351 * @return void
352 */
353        function tearDown() {
354                unset($this->object);
355        }
356
357/**
358 * endTest
359 *
360 * @access public
361 * @return void
362 */
363        function endTest() {
364                App::build();
365        }
366
367/**
368 * testLog method
369 *
370 * @access public
371 * @return void
372 */
373        function testLog() {
374                @unlink(LOGS . 'error.log');
375                $this->assertTrue($this->object->log('Test warning 1'));
376                $this->assertTrue($this->object->log(array('Test' => 'warning 2')));
377                $result = file(LOGS . 'error.log');
378                $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Test warning 1$/', $result[0]);
379                $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Array$/', $result[1]);
380                $this->assertPattern('/^\($/', $result[2]);
381                $this->assertPattern('/\[Test\] => warning 2$/', $result[3]);
382                $this->assertPattern('/^\)$/', $result[4]);
383                unlink(LOGS . 'error.log');
384
385                @unlink(LOGS . 'error.log');
386                $this->assertTrue($this->object->log('Test warning 1', LOG_WARNING));
387                $this->assertTrue($this->object->log(array('Test' => 'warning 2'), LOG_WARNING));
388                $result = file(LOGS . 'error.log');
389                $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 1$/', $result[0]);
390                $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Array$/', $result[1]);
391                $this->assertPattern('/^\($/', $result[2]);
392                $this->assertPattern('/\[Test\] => warning 2$/', $result[3]);
393                $this->assertPattern('/^\)$/', $result[4]);
394                unlink(LOGS . 'error.log');
395        }
396
397/**
398 * testSet method
399 *
400 * @access public
401 * @return void
402 */
403        function testSet() {
404                $this->object->_set('a string');
405                $this->assertEqual($this->object->firstName, 'Joel');
406
407                $this->object->_set(array('firstName'));
408                $this->assertEqual($this->object->firstName, 'Joel');
409
410                $this->object->_set(array('firstName' => 'Ashley'));
411                $this->assertEqual($this->object->firstName, 'Ashley');
412
413                $this->object->_set(array('firstName' => 'Joel', 'lastName' => 'Moose'));
414                $this->assertEqual($this->object->firstName, 'Joel');
415                $this->assertEqual($this->object->lastName, 'Moose');
416        }
417
418/**
419 * testPersist method
420 *
421 * @access public
422 * @return void
423 */
424        function testPersist() {
425                ClassRegistry::flush();
426
427                $cacheDisable = Configure::read('Cache.disable');
428                Configure::write('Cache.disable', false);
429                @unlink(CACHE . 'persistent' . DS . 'testmodel.php');
430                $test = new stdClass;
431                $this->assertFalse($this->object->testPersist('TestModel', null, $test));
432                $this->assertFalse($this->object->testPersist('TestModel', true, $test));
433                $this->assertTrue($this->object->testPersist('TestModel', null, $test));
434                $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'testmodel.php'));
435                $this->assertTrue($this->object->testPersist('TestModel', true, $test));
436                $this->assertEqual($this->object->TestModel, $test);
437
438                @unlink(CACHE . 'persistent' . DS . 'testmodel.php');
439
440                $model =& new ObjectTestModel();
441                $expected = ClassRegistry::keys();
442
443                ClassRegistry::flush();
444                $data = array('object_test_model' => $model);
445                $this->assertFalse($this->object->testPersist('ObjectTestModel', true, $data));
446                $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'objecttestmodel.php'));
447
448                $this->object->testPersist('ObjectTestModel', true, $model, 'registry');
449
450                $result = ClassRegistry::keys();
451                $this->assertEqual($result, $expected);
452
453                $newModel = ClassRegistry::getObject('object_test_model');
454                $this->assertEqual('ObjectTestModel', $newModel->name);
455
456                @unlink(CACHE . 'persistent' . DS . 'objecttestmodel.php');
457
458                Configure::write('Cache.disable', $cacheDisable);
459        }
460
461/**
462 * testPersistWithRequestAction method
463 *
464 * @access public
465 * @return void
466 */
467        function testPersistWithBehavior() {
468                ClassRegistry::flush();
469
470                $cacheDisable = Configure::read('Cache.disable');
471                Configure::write('Cache.disable', false);
472
473                App::build(array(
474                        'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
475                        'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins'. DS),
476                        'behaviors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS),
477                ), true);
478
479                $this->assertFalse(class_exists('PersisterOneBehaviorBehavior'));
480                $this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
481                $this->assertFalse(class_exists('TestPluginPersisterBehavior'));
482                $this->assertFalse(class_exists('TestPluginAuthors'));
483
484                $Controller = new RequestActionPersistentController();
485                $Controller->persistModel = true;
486                $Controller->constructClasses();
487
488                $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
489                $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
490
491                $contents = file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
492                $contents = str_replace('"PersisterOne"', '"PersisterTwo"', $contents);
493                $contents = str_replace('persister_one', 'persister_two', $contents);
494                $contents = str_replace('test_plugin_comment', 'test_plugin_authors', $contents);
495                $result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents);
496
497                $this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
498                $this->assertTrue(class_exists('TestPluginPersisterOneBehavior'));
499                $this->assertTrue(class_exists('TestPluginComment'));
500                $this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
501                $this->assertFalse(class_exists('TestPluginPersisterTwoBehavior'));
502                $this->assertFalse(class_exists('TestPluginAuthors'));
503
504                $Controller = new RequestActionPersistentController();
505                $Controller->persistModel = true;
506                $Controller->constructClasses();
507
508                $this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
509                $this->assertTrue(class_exists('PersisterTwoBehaviorBehavior'));
510                $this->assertTrue(class_exists('TestPluginPersisterTwoBehavior'));
511                $this->assertTrue(class_exists('TestPluginAuthors'));
512
513                @unlink(CACHE . 'persistent' . DS . 'persisterone.php');
514                @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
515        }
516
517/**
518 * testPersistWithBehaviorAndRequestAction method
519 *
520 * @see testPersistWithBehavior
521 * @access public
522 * @return void
523 */
524        function testPersistWithBehaviorAndRequestAction() {
525                ClassRegistry::flush();
526
527                $cacheDisable = Configure::read('Cache.disable');
528                Configure::write('Cache.disable', false);
529
530                $this->assertFalse(class_exists('ContainableBehavior'));
531
532                App::build(array(
533                        'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
534                        'behaviors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS),
535                ), true);
536
537                $this->assertFalse(class_exists('PersistOneBehaviorBehavior'));
538                $this->assertFalse(class_exists('PersistTwoBehaviorBehavior'));
539
540                $Controller = new RequestActionPersistentController();
541                $Controller->persistModel = true;
542                $Controller->constructClasses();
543
544                $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
545                $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
546
547                $keys = ClassRegistry::keys();
548                $this->assertEqual($keys, array(
549                        'persister_one',
550                        'comment',
551                        'test_plugin_comment',
552                        'test_plugin.test_plugin_comment',
553                        'persister_one_behavior_behavior',
554                        'test_plugin_persister_one_behavior',
555                        'test_plugin.test_plugin_persister_one_behavior'
556                ));
557
558                ob_start();
559                $Controller->set('content_for_layout', 'cool');
560                $Controller->render('index', 'ajax', '/layouts/ajax');
561                $result = ob_get_clean();
562
563                $keys = ClassRegistry::keys();
564                $this->assertEqual($keys, array(
565                        'persister_one',
566                        'comment',
567                        'test_plugin_comment',
568                        'test_plugin.test_plugin_comment',
569                        'persister_one_behavior_behavior',
570                        'test_plugin_persister_one_behavior',
571                        'test_plugin.test_plugin_persister_one_behavior',
572                        'view'
573                ));
574                $result = $this->object->requestAction('/request_action_persistent/index');
575                $expected = 'This is a test';
576                $this->assertEqual($result, $expected);
577
578                @unlink(CACHE . 'persistent' . DS . 'persisterone.php');
579                @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
580
581                $Controller = new RequestActionPersistentController();
582                $Controller->persistModel = true;
583                $Controller->constructClasses();
584
585                @unlink(CACHE . 'persistent' . DS . 'persisterone.php');
586                @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
587
588                Configure::write('Cache.disable', $cacheDisable);
589        }
590
591/**
592 * testToString method
593 *
594 * @access public
595 * @return void
596 */
597        function testToString() {
598                $result = strtolower($this->object->toString());
599                $this->assertEqual($result, 'testobject');
600        }
601
602/**
603 * testMethodDispatching method
604 *
605 * @access public
606 * @return void
607 */
608        function testMethodDispatching() {
609                $this->object->emptyMethod();
610                $expected = array('emptyMethod');
611                $this->assertIdentical($this->object->methodCalls, $expected);
612
613                $this->object->oneParamMethod('Hello');
614                $expected[] = array('oneParamMethod' => array('Hello'));
615                $this->assertIdentical($this->object->methodCalls, $expected);
616
617                $this->object->twoParamMethod(true, false);
618                $expected[] = array('twoParamMethod' => array(true, false));
619                $this->assertIdentical($this->object->methodCalls, $expected);
620
621                $this->object->threeParamMethod(true, false, null);
622                $expected[] = array('threeParamMethod' => array(true, false, null));
623                $this->assertIdentical($this->object->methodCalls, $expected);
624
625                $this->object->crazyMethod(1, 2, 3, 4, 5, 6, 7);
626                $expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7));
627                $this->assertIdentical($this->object->methodCalls, $expected);
628
629                $this->object = new TestObject();
630                $this->assertIdentical($this->object->methodCalls, array());
631
632                $this->object->dispatchMethod('emptyMethod');
633                $expected = array('emptyMethod');
634                $this->assertIdentical($this->object->methodCalls, $expected);
635
636                $this->object->dispatchMethod('oneParamMethod', array('Hello'));
637                $expected[] = array('oneParamMethod' => array('Hello'));
638                $this->assertIdentical($this->object->methodCalls, $expected);
639
640                $this->object->dispatchMethod('twoParamMethod', array(true, false));
641                $expected[] = array('twoParamMethod' => array(true, false));
642                $this->assertIdentical($this->object->methodCalls, $expected);
643
644                $this->object->dispatchMethod('threeParamMethod', array(true, false, null));
645                $expected[] = array('threeParamMethod' => array(true, false, null));
646                $this->assertIdentical($this->object->methodCalls, $expected);
647
648                $this->object->dispatchMethod('fourParamMethod', array(1, 2, 3, 4));
649                $expected[] = array('fourParamMethod' => array(1, 2, 3, 4));
650                $this->assertIdentical($this->object->methodCalls, $expected);
651
652                $this->object->dispatchMethod('fiveParamMethod', array(1, 2, 3, 4, 5));
653                $expected[] = array('fiveParamMethod' => array(1, 2, 3, 4, 5));
654                $this->assertIdentical($this->object->methodCalls, $expected);
655
656                $this->object->dispatchMethod('crazyMethod', array(1, 2, 3, 4, 5, 6, 7));
657                $expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7));
658                $this->assertIdentical($this->object->methodCalls, $expected);
659
660                $this->object->dispatchMethod('methodWithOptionalParam', array('Hello'));
661                $expected[] = array('methodWithOptionalParam' => array("Hello"));
662                $this->assertIdentical($this->object->methodCalls, $expected);
663
664                $this->object->dispatchMethod('methodWithOptionalParam');
665                $expected[] = array('methodWithOptionalParam' => array(null));
666                $this->assertIdentical($this->object->methodCalls, $expected);
667        }
668
669/**
670 * testRequestAction method
671 *
672 * @access public
673 * @return void
674 */
675        function testRequestAction() {
676                App::build(array(
677                        'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
678                        'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
679                        'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
680                ));
681                $result = $this->object->requestAction('');
682                $this->assertFalse($result);
683
684                $result = $this->object->requestAction('/request_action/test_request_action');
685                $expected = 'This is a test';
686                $this->assertEqual($result, $expected);;
687
688                $result = $this->object->requestAction('/request_action/another_ra_test/2/5');
689                $expected = 7;
690                $this->assertEqual($result, $expected);
691
692                $result = $this->object->requestAction('/tests_apps/index', array('return'));
693                $expected = 'This is the TestsAppsController index view';
694                $this->assertEqual($result, $expected);
695
696                $result = $this->object->requestAction('/tests_apps/some_method');
697                $expected = 5;
698                $this->assertEqual($result, $expected);
699
700                $result = $this->object->requestAction('/request_action/paginate_request_action');
701                $this->assertTrue($result);
702
703                $result = $this->object->requestAction('/request_action/normal_request_action');
704                $expected = 'Hello World';
705                $this->assertEqual($result, $expected);
706               
707                App::build();
708        }
709
710/**
711 * test requestAction() and plugins.
712 *
713 * @return void
714 */
715        function testRequestActionPlugins() {
716                App::build(array(
717                        'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
718                ));
719                App::objects('plugin', null, false);
720                Router::reload();
721               
722                $result = $this->object->requestAction('/test_plugin/tests/index', array('return'));
723                $expected = 'test plugin index';
724                $this->assertEqual($result, $expected);
725
726                $result = $this->object->requestAction('/test_plugin/tests/index/some_param', array('return'));
727                $expected = 'test plugin index';
728                $this->assertEqual($result, $expected);
729
730                $result = $this->object->requestAction(
731                        array('controller' => 'tests', 'action' => 'index', 'plugin' => 'test_plugin'), array('return')
732                );
733                $expected = 'test plugin index';
734                $this->assertEqual($result, $expected);
735
736                $result = $this->object->requestAction('/test_plugin/tests/some_method');
737                $expected = 25;
738                $this->assertEqual($result, $expected);
739
740                $result = $this->object->requestAction(
741                        array('controller' => 'tests', 'action' => 'some_method', 'plugin' => 'test_plugin')
742                );
743                $expected = 25;
744                $this->assertEqual($result, $expected);
745               
746                App::build();
747                App::objects('plugin', null, false);
748        }
749
750/**
751 * test requestAction() with arrays.
752 *
753 * @return void
754 */
755        function testRequestActionArray() {
756                App::build(array(
757                        'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
758                        'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
759                        'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
760                ));
761       
762                $result = $this->object->requestAction(
763                        array('controller' => 'request_action', 'action' => 'test_request_action')
764                );
765                $expected = 'This is a test';
766                $this->assertEqual($result, $expected);
767
768                $result = $this->object->requestAction(
769                        array('controller' => 'request_action', 'action' => 'another_ra_test'),
770                        array('pass' => array('5', '7'))
771                );
772                $expected = 12;
773                $this->assertEqual($result, $expected);
774
775                $result = $this->object->requestAction(
776                        array('controller' => 'tests_apps', 'action' => 'index'), array('return')
777                );
778                $expected = 'This is the TestsAppsController index view';
779                $this->assertEqual($result, $expected);
780
781                $result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'some_method'));
782                $expected = 5;
783                $this->assertEqual($result, $expected);
784
785                $result = $this->object->requestAction(
786                        array('controller' => 'request_action', 'action' => 'normal_request_action')
787                );
788                $expected = 'Hello World';
789                $this->assertEqual($result, $expected);
790
791                $result = $this->object->requestAction(
792                        array('controller' => 'request_action', 'action' => 'paginate_request_action')
793                );
794                $this->assertTrue($result);
795
796                $result = $this->object->requestAction(
797                        array('controller' => 'request_action', 'action' => 'paginate_request_action'),
798                        array('pass' => array(5), 'named' => array('param' => 'value'))
799                );
800                $this->assertTrue($result);
801
802                App::build();
803        }
804
805/**
806 * Test that requestAction() is populating $this->params properly
807 *
808 * @access public
809 * @return void
810 */
811        function testRequestActionParamParseAndPass() {
812                $result = $this->object->requestAction('/request_action/params_pass');
813                $this->assertTrue(isset($result['url']['url']));
814                $this->assertEqual($result['url']['url'], '/request_action/params_pass');
815                $this->assertEqual($result['controller'], 'request_action');
816                $this->assertEqual($result['action'], 'params_pass');
817                $this->assertEqual($result['form'], array());
818                $this->assertEqual($result['plugin'], null);
819
820                $result = $this->object->requestAction('/request_action/params_pass/sort:desc/limit:5');
821                $expected = array('sort' => 'desc', 'limit' => 5,);
822                $this->assertEqual($result['named'], $expected);
823
824                $result = $this->object->requestAction(
825                        array('controller' => 'request_action', 'action' => 'params_pass'),
826                        array('named' => array('sort' => 'desc', 'limit' => 5))
827                );
828                $this->assertEqual($result['named'], $expected);
829        }
830
831/**
832 * test requestAction and POST parameter passing, and not passing when url is an array.
833 *
834 * @access public
835 * @return void
836 */
837        function testRequestActionPostPassing() {
838                $_tmp = $_POST;
839
840                $_POST = array('data' => array(
841                        'item' => 'value'
842                ));
843                $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
844                $expected = array();
845                $this->assertEqual($expected, $result);
846
847                $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'), array('data' => $_POST['data']));
848                $expected = $_POST['data'];
849                $this->assertEqual($expected, $result);
850
851                $result = $this->object->requestAction('/request_action/post_pass');
852                $expected = $_POST['data'];
853                $this->assertEqual($expected, $result);
854
855                $_POST = $_tmp;
856        }
857
858/**
859 * testCakeError
860 *
861 * @return void
862 */
863        function testCakeError() {
864
865        }
866}
Note: See TracBrowser for help on using the repository browser.