PageRenderTime 55ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/tests/cases/libs/object.test.php

https://github.com/Forbin/cakephp2x
PHP | 788 lines | 354 code | 121 blank | 313 comment | 0 complexity | 5bad47f396dda47edca31c55d3f92d1c MD5 | raw file
  1. <?php
  2. /**
  3. * ObjectTest file
  4. *
  5. * PHP Version 5.x
  6. *
  7. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  8. * Copyright 2005-2009, 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-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link https://trac.cakephp.org/wiki/Developement/TestSuite 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. */
  20. App::import('Core', array('Object', 'Controller', 'Model'));
  21. /**
  22. * RequestActionPost class
  23. *
  24. * @package cake
  25. * @subpackage cake.tests.cases.libs.object
  26. */
  27. class RequestActionPost extends CakeTestModel {
  28. /**
  29. * name property
  30. *
  31. * @var string 'ControllerPost'
  32. * @access public
  33. */
  34. var $name = 'RequestActionPost';
  35. /**
  36. * useTable property
  37. *
  38. * @var string 'posts'
  39. * @access public
  40. */
  41. var $useTable = 'posts';
  42. }
  43. /**
  44. * RequestActionController class
  45. *
  46. * @package cake
  47. * @subpackage cake.tests.cases.libs
  48. */
  49. class RequestActionController extends Controller {
  50. /**
  51. * uses property
  52. *
  53. * @var array
  54. * @access public
  55. */
  56. var $uses = array('RequestActionPost');
  57. /**
  58. * test_request_action method
  59. *
  60. * @access public
  61. * @return void
  62. */
  63. function test_request_action() {
  64. return 'This is a test';
  65. }
  66. /**
  67. * another_ra_test method
  68. *
  69. * @param mixed $id
  70. * @param mixed $other
  71. * @access public
  72. * @return void
  73. */
  74. function another_ra_test($id, $other) {
  75. return $id + $other;
  76. }
  77. /**
  78. * normal_request_action method
  79. *
  80. * @access public
  81. * @return void
  82. */
  83. function normal_request_action() {
  84. return 'Hello World';
  85. }
  86. /**
  87. * paginate_request_action method
  88. *
  89. * @access public
  90. * @return void
  91. */
  92. function paginate_request_action() {
  93. $data = $this->paginate();
  94. return true;
  95. }
  96. /**
  97. * post pass, testing post passing
  98. *
  99. * @return array
  100. */
  101. function post_pass() {
  102. return $this->data;
  103. }
  104. /**
  105. * test param passing and parsing.
  106. *
  107. * @return array
  108. */
  109. function params_pass() {
  110. return $this->params;
  111. }
  112. }
  113. /**
  114. * RequestActionPersistentController class
  115. *
  116. * @package cake
  117. * @subpackage cake.tests.cases.libs
  118. */
  119. class RequestActionPersistentController extends Controller {
  120. /**
  121. * uses property
  122. *
  123. * @var array
  124. * @access public
  125. */
  126. var $uses = array('PersisterOne');
  127. /**
  128. * persistModel property
  129. *
  130. * @var array
  131. * @access public
  132. */
  133. var $persistModel = true;
  134. /**
  135. * post pass, testing post passing
  136. *
  137. * @return array
  138. */
  139. function index() {
  140. return 'This is a test';
  141. }
  142. }
  143. /**
  144. * TestObject class
  145. *
  146. * @package cake
  147. * @subpackage cake.tests.cases.libs
  148. */
  149. class TestObject extends Object {
  150. /**
  151. * firstName property
  152. *
  153. * @var string 'Joel'
  154. * @access public
  155. */
  156. var $firstName = 'Joel';
  157. /**
  158. * lastName property
  159. *
  160. * @var string 'Moss'
  161. * @access public
  162. */
  163. var $lastName = 'Moss';
  164. /**
  165. * methodCalls property
  166. *
  167. * @var array
  168. * @access public
  169. */
  170. var $methodCalls = array();
  171. /**
  172. * emptyMethod method
  173. *
  174. * @access public
  175. * @return void
  176. */
  177. function emptyMethod() {
  178. $this->methodCalls[] = 'emptyMethod';
  179. }
  180. /**
  181. * oneParamMethod method
  182. *
  183. * @param mixed $param
  184. * @access public
  185. * @return void
  186. */
  187. function oneParamMethod($param) {
  188. $this->methodCalls[] = array('oneParamMethod' => array($param));
  189. }
  190. /**
  191. * twoParamMethod method
  192. *
  193. * @param mixed $param
  194. * @param mixed $param2
  195. * @access public
  196. * @return void
  197. */
  198. function twoParamMethod($param, $param2) {
  199. $this->methodCalls[] = array('twoParamMethod' => array($param, $param2));
  200. }
  201. /**
  202. * threeParamMethod method
  203. *
  204. * @param mixed $param
  205. * @param mixed $param2
  206. * @param mixed $param3
  207. * @access public
  208. * @return void
  209. */
  210. function threeParamMethod($param, $param2, $param3) {
  211. $this->methodCalls[] = array('threeParamMethod' => array($param, $param2, $param3));
  212. }
  213. /**
  214. * fourParamMethod method
  215. *
  216. * @param mixed $param
  217. * @param mixed $param2
  218. * @param mixed $param3
  219. * @param mixed $param4
  220. * @access public
  221. * @return void
  222. */
  223. function fourParamMethod($param, $param2, $param3, $param4) {
  224. $this->methodCalls[] = array('fourParamMethod' => array($param, $param2, $param3, $param4));
  225. }
  226. /**
  227. * fiveParamMethod method
  228. *
  229. * @param mixed $param
  230. * @param mixed $param2
  231. * @param mixed $param3
  232. * @param mixed $param4
  233. * @param mixed $param5
  234. * @access public
  235. * @return void
  236. */
  237. function fiveParamMethod($param, $param2, $param3, $param4, $param5) {
  238. $this->methodCalls[] = array('fiveParamMethod' => array($param, $param2, $param3, $param4, $param5));
  239. }
  240. /**
  241. * crazyMethod method
  242. *
  243. * @param mixed $param
  244. * @param mixed $param2
  245. * @param mixed $param3
  246. * @param mixed $param4
  247. * @param mixed $param5
  248. * @param mixed $param6
  249. * @param mixed $param7
  250. * @access public
  251. * @return void
  252. */
  253. function crazyMethod($param, $param2, $param3, $param4, $param5, $param6, $param7 = null) {
  254. $this->methodCalls[] = array('crazyMethod' => array($param, $param2, $param3, $param4, $param5, $param6, $param7));
  255. }
  256. /**
  257. * methodWithOptionalParam method
  258. *
  259. * @param mixed $param
  260. * @access public
  261. * @return void
  262. */
  263. function methodWithOptionalParam($param = null) {
  264. $this->methodCalls[] = array('methodWithOptionalParam' => array($param));
  265. }
  266. /**
  267. * testPersist
  268. *
  269. * @return void
  270. */
  271. function testPersist($name, $return = null, &$object, $type = null) {
  272. return $this->_persist($name, $return, $object, $type);
  273. }
  274. /**
  275. * testPersist
  276. *
  277. * @return void
  278. **/
  279. function testSet($properties = array()) {
  280. return $this->_set($properties);
  281. }
  282. }
  283. /**
  284. * ObjectTestModel class
  285. *
  286. * @package cake
  287. * @subpackage cake.tests.cases.libs
  288. */
  289. class ObjectTestModel extends CakeTestModel {
  290. var $useTable = false;
  291. var $name = 'ObjectTestModel';
  292. }
  293. /**
  294. * Object Test class
  295. *
  296. * @package cake
  297. * @subpackage cake.tests.cases.libs
  298. */
  299. class ObjectTest extends CakeTestCase {
  300. /**
  301. * fixtures
  302. *
  303. * @var string
  304. */
  305. var $fixtures = array('core.post', 'core.comment');
  306. /**
  307. * setUp method
  308. *
  309. * @access public
  310. * @return void
  311. */
  312. function setUp() {
  313. $this->object = new TestObject();
  314. }
  315. /**
  316. * tearDown method
  317. *
  318. * @access public
  319. * @return void
  320. */
  321. function tearDown() {
  322. unset($this->object);
  323. }
  324. /**
  325. * endTest
  326. *
  327. * @access public
  328. * @return void
  329. */
  330. function endTest() {
  331. App::build();
  332. }
  333. /**
  334. * testLog method
  335. *
  336. * @access public
  337. * @return void
  338. */
  339. function testLog() {
  340. @unlink(LOGS . 'error.log');
  341. $this->assertTrue($this->object->log('Test warning 1'));
  342. $this->assertTrue($this->object->log(array('Test' => 'warning 2')));
  343. $result = file(LOGS . 'error.log');
  344. $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Test warning 1$/', $result[0]);
  345. $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Array$/', $result[1]);
  346. $this->assertPattern('/^\($/', $result[2]);
  347. $this->assertPattern('/\[Test\] => warning 2$/', $result[3]);
  348. $this->assertPattern('/^\)$/', $result[4]);
  349. unlink(LOGS . 'error.log');
  350. @unlink(LOGS . 'error.log');
  351. $this->assertTrue($this->object->log('Test warning 1', LOG_WARNING));
  352. $this->assertTrue($this->object->log(array('Test' => 'warning 2'), LOG_WARNING));
  353. $result = file(LOGS . 'error.log');
  354. $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 1$/', $result[0]);
  355. $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Array$/', $result[1]);
  356. $this->assertPattern('/^\($/', $result[2]);
  357. $this->assertPattern('/\[Test\] => warning 2$/', $result[3]);
  358. $this->assertPattern('/^\)$/', $result[4]);
  359. unlink(LOGS . 'error.log');
  360. }
  361. /**
  362. * testSet method
  363. *
  364. * @access public
  365. * @return void
  366. */
  367. function testSet() {
  368. $this->object->testSet('a string');
  369. $this->assertEqual($this->object->firstName, 'Joel');
  370. $this->object->testSet(array('firstName'));
  371. $this->assertEqual($this->object->firstName, 'Joel');
  372. $this->object->testSet(array('firstName' => 'Ashley'));
  373. $this->assertEqual($this->object->firstName, 'Ashley');
  374. $this->object->testSet(array('firstName' => 'Joel', 'lastName' => 'Moose'));
  375. $this->assertEqual($this->object->firstName, 'Joel');
  376. $this->assertEqual($this->object->lastName, 'Moose');
  377. }
  378. /**
  379. * testPersist method
  380. *
  381. * @access public
  382. * @return void
  383. */
  384. function testPersist() {
  385. ClassRegistry::flush();
  386. $cacheDisable = Configure::read('Cache.disable');
  387. Configure::write('Cache.disable', false);
  388. @unlink(CACHE . 'persistent' . DS . 'testmodel.php');
  389. $test = new stdClass;
  390. $this->assertFalse($this->object->testPersist('TestModel', null, $test));
  391. $this->assertFalse($this->object->testPersist('TestModel', true, $test));
  392. $this->assertTrue($this->object->testPersist('TestModel', null, $test));
  393. $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'testmodel.php'));
  394. $this->assertTrue($this->object->testPersist('TestModel', true, $test));
  395. $this->assertEqual($this->object->TestModel, $test);
  396. @unlink(CACHE . 'persistent' . DS . 'testmodel.php');
  397. $model = new ObjectTestModel();
  398. $expected = ClassRegistry::keys();
  399. ClassRegistry::flush();
  400. $data = array('object_test_model' => $model);
  401. $this->assertFalse($this->object->testPersist('ObjectTestModel', true, $data));
  402. $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'objecttestmodel.php'));
  403. $this->object->testPersist('ObjectTestModel', true, $model, 'registry');
  404. $result = ClassRegistry::keys();
  405. $this->assertEqual($result, $expected);
  406. $newModel = ClassRegistry::getObject('object_test_model');
  407. $this->assertEqual('ObjectTestModel', $newModel->name);
  408. @unlink(CACHE . 'persistent' . DS . 'objecttestmodel.php');
  409. Configure::write('Cache.disable', $cacheDisable);
  410. }
  411. /**
  412. * testPersistWithRequestAction method
  413. *
  414. * @access public
  415. * @return void
  416. */
  417. function testPersistWithBehavior() {
  418. ClassRegistry::flush();
  419. $cacheDisable = Configure::read('Cache.disable');
  420. Configure::write('Cache.disable', false);
  421. App::build(array(
  422. 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
  423. 'behaviors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS),
  424. ), true);
  425. $this->assertFalse(class_exists('PersisterOneBehaviorBehavior'));
  426. $this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
  427. $Controller = new RequestActionPersistentController();
  428. $Controller->persistModel = true;
  429. $Controller->constructClasses();
  430. $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
  431. $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
  432. $contents = str_replace('"PersisterOne"', '"PersisterTwo"', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
  433. $contents = str_replace('persister_one_', 'persister_two_', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
  434. $result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents);
  435. $this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
  436. $this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
  437. $Controller = new RequestActionPersistentController();
  438. $Controller->persistModel = true;
  439. $Controller->constructClasses();
  440. $this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
  441. $this->assertTrue(class_exists('PersisterTwoBehaviorBehavior'));
  442. @unlink(CACHE . 'persistent' . DS . 'persisterone.php');
  443. @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
  444. }
  445. /**
  446. * testPersistWithBehaviorAndRequestAction method
  447. *
  448. * @see testPersistWithBehavior
  449. * @access public
  450. * @return void
  451. */
  452. function testPersistWithBehaviorAndRequestAction() {
  453. ClassRegistry::flush();
  454. $cacheDisable = Configure::read('Cache.disable');
  455. Configure::write('Cache.disable', false);
  456. $this->assertFalse(class_exists('ContainableBehavior'));
  457. App::build(array(
  458. 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
  459. 'behaviors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS),
  460. ), true);
  461. $this->assertFalse(class_exists('PersistOneBehaviorBehavior'));
  462. $this->assertFalse(class_exists('PersistTwoBehaviorBehavior'));
  463. $Controller = new RequestActionPersistentController();
  464. $Controller->persistModel = true;
  465. $Controller->constructClasses();
  466. $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
  467. $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
  468. $keys = ClassRegistry::keys();
  469. $this->assertEqual($keys, array('persister_one', 'comment', 'persister_one_behavior_behavior'));
  470. ob_start();
  471. $Controller->set('content_for_layout', 'cool');
  472. $Controller->render('index', 'ajax', '/layouts/ajax');
  473. $result = ob_get_clean();
  474. $keys = ClassRegistry::keys();
  475. $this->assertEqual($keys, array('persister_one', 'comment', 'persister_one_behavior_behavior', 'view'));
  476. $result = $this->object->requestAction('/request_action_persistent/index');
  477. $expected = 'This is a test';
  478. $this->assertEqual($result, $expected);
  479. @unlink(CACHE . 'persistent' . DS . 'persisterone.php');
  480. @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
  481. $Controller = new RequestActionPersistentController();
  482. $Controller->persistModel = true;
  483. $Controller->constructClasses();
  484. @unlink(CACHE . 'persistent' . DS . 'persisterone.php');
  485. @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
  486. Configure::write('Cache.disable', $cacheDisable);
  487. }
  488. /**
  489. * testToString method
  490. *
  491. * @access public
  492. * @return void
  493. */
  494. function testToString() {
  495. $result = strtolower($this->object->toString());
  496. $this->assertEqual($result, 'testobject');
  497. }
  498. /**
  499. * testMethodDispatching method
  500. *
  501. * @access public
  502. * @return void
  503. */
  504. function testMethodDispatching() {
  505. $this->object->emptyMethod();
  506. $expected = array('emptyMethod');
  507. $this->assertIdentical($this->object->methodCalls, $expected);
  508. $this->object->oneParamMethod('Hello');
  509. $expected[] = array('oneParamMethod' => array('Hello'));
  510. $this->assertIdentical($this->object->methodCalls, $expected);
  511. $this->object->twoParamMethod(true, false);
  512. $expected[] = array('twoParamMethod' => array(true, false));
  513. $this->assertIdentical($this->object->methodCalls, $expected);
  514. $this->object->threeParamMethod(true, false, null);
  515. $expected[] = array('threeParamMethod' => array(true, false, null));
  516. $this->assertIdentical($this->object->methodCalls, $expected);
  517. $this->object->crazyMethod(1, 2, 3, 4, 5, 6, 7);
  518. $expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7));
  519. $this->assertIdentical($this->object->methodCalls, $expected);
  520. $this->object = new TestObject();
  521. $this->assertIdentical($this->object->methodCalls, array());
  522. $this->object->dispatchMethod('emptyMethod');
  523. $expected = array('emptyMethod');
  524. $this->assertIdentical($this->object->methodCalls, $expected);
  525. $this->object->dispatchMethod('oneParamMethod', array('Hello'));
  526. $expected[] = array('oneParamMethod' => array('Hello'));
  527. $this->assertIdentical($this->object->methodCalls, $expected);
  528. $this->object->dispatchMethod('twoParamMethod', array(true, false));
  529. $expected[] = array('twoParamMethod' => array(true, false));
  530. $this->assertIdentical($this->object->methodCalls, $expected);
  531. $this->object->dispatchMethod('threeParamMethod', array(true, false, null));
  532. $expected[] = array('threeParamMethod' => array(true, false, null));
  533. $this->assertIdentical($this->object->methodCalls, $expected);
  534. $this->object->dispatchMethod('fourParamMethod', array(1, 2, 3, 4));
  535. $expected[] = array('fourParamMethod' => array(1, 2, 3, 4));
  536. $this->assertIdentical($this->object->methodCalls, $expected);
  537. $this->object->dispatchMethod('fiveParamMethod', array(1, 2, 3, 4, 5));
  538. $expected[] = array('fiveParamMethod' => array(1, 2, 3, 4, 5));
  539. $this->assertIdentical($this->object->methodCalls, $expected);
  540. $this->object->dispatchMethod('crazyMethod', array(1, 2, 3, 4, 5, 6, 7));
  541. $expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7));
  542. $this->assertIdentical($this->object->methodCalls, $expected);
  543. $this->object->dispatchMethod('methodWithOptionalParam', array('Hello'));
  544. $expected[] = array('methodWithOptionalParam' => array("Hello"));
  545. $this->assertIdentical($this->object->methodCalls, $expected);
  546. $this->object->dispatchMethod('methodWithOptionalParam');
  547. $expected[] = array('methodWithOptionalParam' => array(null));
  548. $this->assertIdentical($this->object->methodCalls, $expected);
  549. }
  550. /**
  551. * testRequestAction method
  552. *
  553. * @access public
  554. * @return void
  555. */
  556. function testRequestAction() {
  557. $result = $this->object->requestAction('');
  558. $this->assertFalse($result);
  559. $result = $this->object->requestAction('/request_action/test_request_action');
  560. $expected = 'This is a test';
  561. $this->assertEqual($result, $expected);
  562. $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'test_request_action'));
  563. $expected = 'This is a test';
  564. $this->assertEqual($result, $expected);
  565. $result = $this->object->requestAction('/request_action/another_ra_test/2/5');
  566. $expected = 7;
  567. $this->assertEqual($result, $expected);
  568. $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'another_ra_test'), array('pass' => array('5', '7')));
  569. $expected = 12;
  570. $this->assertEqual($result, $expected);
  571. App::build(array(
  572. 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
  573. 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
  574. 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
  575. 'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
  576. ), true);
  577. $result = $this->object->requestAction('/tests_apps/index', array('return'));
  578. $expected = 'This is the TestsAppsController index view';
  579. $this->assertEqual($result, $expected);
  580. $result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'index'), array('return'));
  581. $expected = 'This is the TestsAppsController index view';
  582. $this->assertEqual($result, $expected);
  583. $result = $this->object->requestAction('/tests_apps/some_method');
  584. $expected = 5;
  585. $this->assertEqual($result, $expected);
  586. $result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'some_method'));
  587. $expected = 5;
  588. $this->assertEqual($result, $expected);
  589. $result = $this->object->requestAction('/test_plugin/tests/index', array('return'));
  590. $expected = 'test plugin index';
  591. $this->assertEqual($result, $expected);
  592. $result = $this->object->requestAction('/test_plugin/tests/index/some_param', array('return'));
  593. $expected = 'test plugin index';
  594. $this->assertEqual($result, $expected);
  595. $result = $this->object->requestAction(array('controller' => 'tests', 'action' => 'index', 'plugin' => 'test_plugin'), array('return'));
  596. $expected = 'test plugin index';
  597. $this->assertEqual($result, $expected);
  598. $result = $this->object->requestAction('/test_plugin/tests/some_method');
  599. $expected = 25;
  600. $this->assertEqual($result, $expected);
  601. $result = $this->object->requestAction(array('controller' => 'tests', 'action' => 'some_method', 'plugin' => 'test_plugin'));
  602. $expected = 25;
  603. $this->assertEqual($result, $expected);
  604. $result = $this->object->requestAction('/request_action/paginate_request_action');
  605. $this->assertTrue($result);
  606. $result = $this->object->requestAction('/request_action/normal_request_action');
  607. $expected = 'Hello World';
  608. $this->assertEqual($result, $expected);
  609. $result = $this->object->requestAction(array('controller'=>'request_action', 'action'=>'normal_request_action'));
  610. $expected = 'Hello World';
  611. $this->assertEqual($result, $expected);
  612. $result = $this->object->requestAction(array('controller'=>'request_action', 'action'=>'paginate_request_action'));
  613. $this->assertTrue($result);
  614. $result = $this->object->requestAction(array('controller'=>'request_action', 'action'=>'paginate_request_action'), array('pass' => array(5), 'named' => array('param' => 'value')));
  615. $this->assertTrue($result);
  616. }
  617. /**
  618. * Test that requestAction() is populating $this->params properly
  619. *
  620. * @access public
  621. * @return void
  622. */
  623. function testRequestActionParamParseAndPass() {
  624. $result = $this->object->requestAction('/request_action/params_pass');
  625. $this->assertTrue(isset($result['url']['url']));
  626. $this->assertEqual($result['url']['url'], '/request_action/params_pass');
  627. $this->assertEqual($result['controller'], 'request_action');
  628. $this->assertEqual($result['action'], 'params_pass');
  629. $this->assertEqual($result['form'], array());
  630. $this->assertEqual($result['plugin'], null);
  631. $result = $this->object->requestAction('/request_action/params_pass/sort:desc/limit:5');
  632. $expected = array('sort' => 'desc', 'limit' => 5,);
  633. $this->assertEqual($result['named'], $expected);
  634. $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'params_pass'), array('named' => array('sort' => 'desc', 'limit' => 5)));
  635. $this->assertEqual($result['named'], $expected);
  636. }
  637. /**
  638. * test requestAction and POST parameter passing, and not passing when url is an array.
  639. *
  640. * @access public
  641. * @return void
  642. */
  643. function testRequestActionPostPassing() {
  644. $_tmp = $_POST;
  645. $_POST = array('data' => array(
  646. 'item' => 'value'
  647. ));
  648. $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
  649. $expected = array();
  650. $this->assertEqual($expected, $result);
  651. $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'), array('data' => $_POST['data']));
  652. $expected = $_POST['data'];
  653. $this->assertEqual($expected, $result);
  654. $result = $this->object->requestAction('/request_action/post_pass');
  655. $expected = $_POST['data'];
  656. $this->assertEqual($expected, $result);
  657. $_POST = $_tmp;
  658. }
  659. /**
  660. * testCakeError
  661. *
  662. * @return void
  663. */
  664. function testCakeError() {
  665. }
  666. }
  667. ?>