PageRenderTime 42ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/Datawalke/Coordino
PHP | 866 lines | 419 code | 124 blank | 323 comment | 0 complexity | 6cd4ff4721f217d50c0310a24d768e92 MD5 | raw file
  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-2012, 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-2012, 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. */
  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. * returns $this->here
  88. *
  89. * @return void
  90. */
  91. function return_here() {
  92. return $this->here;
  93. }
  94. /**
  95. * paginate_request_action method
  96. *
  97. * @access public
  98. * @return void
  99. */
  100. function paginate_request_action() {
  101. $data = $this->paginate();
  102. return true;
  103. }
  104. /**
  105. * post pass, testing post passing
  106. *
  107. * @return array
  108. */
  109. function post_pass() {
  110. return $this->data;
  111. }
  112. /**
  113. * test param passing and parsing.
  114. *
  115. * @return array
  116. */
  117. function params_pass() {
  118. return $this->params;
  119. }
  120. }
  121. /**
  122. * RequestActionPersistentController class
  123. *
  124. * @package cake
  125. * @subpackage cake.tests.cases.libs
  126. */
  127. class RequestActionPersistentController extends Controller {
  128. /**
  129. * uses property
  130. *
  131. * @var array
  132. * @access public
  133. */
  134. var $uses = array('PersisterOne');
  135. /**
  136. * persistModel property
  137. *
  138. * @var array
  139. * @access public
  140. */
  141. var $persistModel = true;
  142. /**
  143. * post pass, testing post passing
  144. *
  145. * @return array
  146. */
  147. function index() {
  148. return 'This is a test';
  149. }
  150. }
  151. /**
  152. * TestObject class
  153. *
  154. * @package cake
  155. * @subpackage cake.tests.cases.libs
  156. */
  157. class TestObject extends Object {
  158. /**
  159. * firstName property
  160. *
  161. * @var string 'Joel'
  162. * @access public
  163. */
  164. var $firstName = 'Joel';
  165. /**
  166. * lastName property
  167. *
  168. * @var string 'Moss'
  169. * @access public
  170. */
  171. var $lastName = 'Moss';
  172. /**
  173. * methodCalls property
  174. *
  175. * @var array
  176. * @access public
  177. */
  178. var $methodCalls = array();
  179. /**
  180. * emptyMethod method
  181. *
  182. * @access public
  183. * @return void
  184. */
  185. function emptyMethod() {
  186. $this->methodCalls[] = 'emptyMethod';
  187. }
  188. /**
  189. * oneParamMethod method
  190. *
  191. * @param mixed $param
  192. * @access public
  193. * @return void
  194. */
  195. function oneParamMethod($param) {
  196. $this->methodCalls[] = array('oneParamMethod' => array($param));
  197. }
  198. /**
  199. * twoParamMethod method
  200. *
  201. * @param mixed $param
  202. * @param mixed $param2
  203. * @access public
  204. * @return void
  205. */
  206. function twoParamMethod($param, $param2) {
  207. $this->methodCalls[] = array('twoParamMethod' => array($param, $param2));
  208. }
  209. /**
  210. * threeParamMethod method
  211. *
  212. * @param mixed $param
  213. * @param mixed $param2
  214. * @param mixed $param3
  215. * @access public
  216. * @return void
  217. */
  218. function threeParamMethod($param, $param2, $param3) {
  219. $this->methodCalls[] = array('threeParamMethod' => array($param, $param2, $param3));
  220. }
  221. /**
  222. * fourParamMethod method
  223. *
  224. * @param mixed $param
  225. * @param mixed $param2
  226. * @param mixed $param3
  227. * @param mixed $param4
  228. * @access public
  229. * @return void
  230. */
  231. function fourParamMethod($param, $param2, $param3, $param4) {
  232. $this->methodCalls[] = array('fourParamMethod' => array($param, $param2, $param3, $param4));
  233. }
  234. /**
  235. * fiveParamMethod method
  236. *
  237. * @param mixed $param
  238. * @param mixed $param2
  239. * @param mixed $param3
  240. * @param mixed $param4
  241. * @param mixed $param5
  242. * @access public
  243. * @return void
  244. */
  245. function fiveParamMethod($param, $param2, $param3, $param4, $param5) {
  246. $this->methodCalls[] = array('fiveParamMethod' => array($param, $param2, $param3, $param4, $param5));
  247. }
  248. /**
  249. * crazyMethod method
  250. *
  251. * @param mixed $param
  252. * @param mixed $param2
  253. * @param mixed $param3
  254. * @param mixed $param4
  255. * @param mixed $param5
  256. * @param mixed $param6
  257. * @param mixed $param7
  258. * @access public
  259. * @return void
  260. */
  261. function crazyMethod($param, $param2, $param3, $param4, $param5, $param6, $param7 = null) {
  262. $this->methodCalls[] = array('crazyMethod' => array($param, $param2, $param3, $param4, $param5, $param6, $param7));
  263. }
  264. /**
  265. * methodWithOptionalParam method
  266. *
  267. * @param mixed $param
  268. * @access public
  269. * @return void
  270. */
  271. function methodWithOptionalParam($param = null) {
  272. $this->methodCalls[] = array('methodWithOptionalParam' => array($param));
  273. }
  274. /**
  275. * testPersist
  276. *
  277. * @return void
  278. */
  279. function testPersist($name, $return = null, &$object, $type = null) {
  280. return $this->_persist($name, $return, $object, $type);
  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.test_plugin_comment', '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->_set('a string');
  369. $this->assertEqual($this->object->firstName, 'Joel');
  370. $this->object->_set(array('firstName'));
  371. $this->assertEqual($this->object->firstName, 'Joel');
  372. $this->object->_set(array('firstName' => 'Ashley'));
  373. $this->assertEqual($this->object->firstName, 'Ashley');
  374. $this->object->_set(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. 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins'. DS),
  424. 'behaviors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS),
  425. ), true);
  426. $this->assertFalse(class_exists('PersisterOneBehaviorBehavior'));
  427. $this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
  428. $this->assertFalse(class_exists('TestPluginPersisterBehavior'));
  429. $this->assertFalse(class_exists('TestPluginAuthors'));
  430. $Controller = new RequestActionPersistentController();
  431. $Controller->persistModel = true;
  432. $Controller->constructClasses();
  433. $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
  434. $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
  435. $contents = file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
  436. $contents = str_replace('"PersisterOne"', '"PersisterTwo"', $contents);
  437. $contents = str_replace('persister_one', 'persister_two', $contents);
  438. $contents = str_replace('test_plugin_comment', 'test_plugin_authors', $contents);
  439. $result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents);
  440. $this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
  441. $this->assertTrue(class_exists('TestPluginPersisterOneBehavior'));
  442. $this->assertTrue(class_exists('TestPluginComment'));
  443. $this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
  444. $this->assertFalse(class_exists('TestPluginPersisterTwoBehavior'));
  445. $this->assertFalse(class_exists('TestPluginAuthors'));
  446. $Controller = new RequestActionPersistentController();
  447. $Controller->persistModel = true;
  448. $Controller->constructClasses();
  449. $this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
  450. $this->assertTrue(class_exists('PersisterTwoBehaviorBehavior'));
  451. $this->assertTrue(class_exists('TestPluginPersisterTwoBehavior'));
  452. $this->assertTrue(class_exists('TestPluginAuthors'));
  453. @unlink(CACHE . 'persistent' . DS . 'persisterone.php');
  454. @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
  455. }
  456. /**
  457. * testPersistWithBehaviorAndRequestAction method
  458. *
  459. * @see testPersistWithBehavior
  460. * @access public
  461. * @return void
  462. */
  463. function testPersistWithBehaviorAndRequestAction() {
  464. ClassRegistry::flush();
  465. $cacheDisable = Configure::read('Cache.disable');
  466. Configure::write('Cache.disable', false);
  467. $this->assertFalse(class_exists('ContainableBehavior'));
  468. App::build(array(
  469. 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
  470. 'behaviors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS),
  471. ), true);
  472. $this->assertFalse(class_exists('PersistOneBehaviorBehavior'));
  473. $this->assertFalse(class_exists('PersistTwoBehaviorBehavior'));
  474. $Controller = new RequestActionPersistentController();
  475. $Controller->persistModel = true;
  476. $Controller->constructClasses();
  477. $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
  478. $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
  479. $keys = ClassRegistry::keys();
  480. $this->assertEqual($keys, array(
  481. 'persister_one',
  482. 'comment',
  483. 'test_plugin_comment',
  484. 'test_plugin.test_plugin_comment',
  485. 'persister_one_behavior_behavior',
  486. 'test_plugin_persister_one_behavior',
  487. 'test_plugin.test_plugin_persister_one_behavior'
  488. ));
  489. ob_start();
  490. $Controller->set('content_for_layout', 'cool');
  491. $Controller->render('index', 'ajax', '/layouts/ajax');
  492. $result = ob_get_clean();
  493. $keys = ClassRegistry::keys();
  494. $this->assertEqual($keys, array(
  495. 'persister_one',
  496. 'comment',
  497. 'test_plugin_comment',
  498. 'test_plugin.test_plugin_comment',
  499. 'persister_one_behavior_behavior',
  500. 'test_plugin_persister_one_behavior',
  501. 'test_plugin.test_plugin_persister_one_behavior',
  502. 'view'
  503. ));
  504. $result = $this->object->requestAction('/request_action_persistent/index');
  505. $expected = 'This is a test';
  506. $this->assertEqual($result, $expected);
  507. @unlink(CACHE . 'persistent' . DS . 'persisterone.php');
  508. @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
  509. $Controller = new RequestActionPersistentController();
  510. $Controller->persistModel = true;
  511. $Controller->constructClasses();
  512. @unlink(CACHE . 'persistent' . DS . 'persisterone.php');
  513. @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
  514. Configure::write('Cache.disable', $cacheDisable);
  515. }
  516. /**
  517. * testToString method
  518. *
  519. * @access public
  520. * @return void
  521. */
  522. function testToString() {
  523. $result = strtolower($this->object->toString());
  524. $this->assertEqual($result, 'testobject');
  525. }
  526. /**
  527. * testMethodDispatching method
  528. *
  529. * @access public
  530. * @return void
  531. */
  532. function testMethodDispatching() {
  533. $this->object->emptyMethod();
  534. $expected = array('emptyMethod');
  535. $this->assertIdentical($this->object->methodCalls, $expected);
  536. $this->object->oneParamMethod('Hello');
  537. $expected[] = array('oneParamMethod' => array('Hello'));
  538. $this->assertIdentical($this->object->methodCalls, $expected);
  539. $this->object->twoParamMethod(true, false);
  540. $expected[] = array('twoParamMethod' => array(true, false));
  541. $this->assertIdentical($this->object->methodCalls, $expected);
  542. $this->object->threeParamMethod(true, false, null);
  543. $expected[] = array('threeParamMethod' => array(true, false, null));
  544. $this->assertIdentical($this->object->methodCalls, $expected);
  545. $this->object->crazyMethod(1, 2, 3, 4, 5, 6, 7);
  546. $expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7));
  547. $this->assertIdentical($this->object->methodCalls, $expected);
  548. $this->object = new TestObject();
  549. $this->assertIdentical($this->object->methodCalls, array());
  550. $this->object->dispatchMethod('emptyMethod');
  551. $expected = array('emptyMethod');
  552. $this->assertIdentical($this->object->methodCalls, $expected);
  553. $this->object->dispatchMethod('oneParamMethod', array('Hello'));
  554. $expected[] = array('oneParamMethod' => array('Hello'));
  555. $this->assertIdentical($this->object->methodCalls, $expected);
  556. $this->object->dispatchMethod('twoParamMethod', array(true, false));
  557. $expected[] = array('twoParamMethod' => array(true, false));
  558. $this->assertIdentical($this->object->methodCalls, $expected);
  559. $this->object->dispatchMethod('threeParamMethod', array(true, false, null));
  560. $expected[] = array('threeParamMethod' => array(true, false, null));
  561. $this->assertIdentical($this->object->methodCalls, $expected);
  562. $this->object->dispatchMethod('fourParamMethod', array(1, 2, 3, 4));
  563. $expected[] = array('fourParamMethod' => array(1, 2, 3, 4));
  564. $this->assertIdentical($this->object->methodCalls, $expected);
  565. $this->object->dispatchMethod('fiveParamMethod', array(1, 2, 3, 4, 5));
  566. $expected[] = array('fiveParamMethod' => array(1, 2, 3, 4, 5));
  567. $this->assertIdentical($this->object->methodCalls, $expected);
  568. $this->object->dispatchMethod('crazyMethod', array(1, 2, 3, 4, 5, 6, 7));
  569. $expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7));
  570. $this->assertIdentical($this->object->methodCalls, $expected);
  571. $this->object->dispatchMethod('methodWithOptionalParam', array('Hello'));
  572. $expected[] = array('methodWithOptionalParam' => array("Hello"));
  573. $this->assertIdentical($this->object->methodCalls, $expected);
  574. $this->object->dispatchMethod('methodWithOptionalParam');
  575. $expected[] = array('methodWithOptionalParam' => array(null));
  576. $this->assertIdentical($this->object->methodCalls, $expected);
  577. }
  578. /**
  579. * testRequestAction method
  580. *
  581. * @access public
  582. * @return void
  583. */
  584. function testRequestAction() {
  585. App::build(array(
  586. 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
  587. 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
  588. 'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
  589. ));
  590. $result = $this->object->requestAction('');
  591. $this->assertFalse($result);
  592. $result = $this->object->requestAction('/request_action/test_request_action');
  593. $expected = 'This is a test';
  594. $this->assertEqual($result, $expected);;
  595. $result = $this->object->requestAction('/request_action/another_ra_test/2/5');
  596. $expected = 7;
  597. $this->assertEqual($result, $expected);
  598. $result = $this->object->requestAction('/tests_apps/index', array('return'));
  599. $expected = 'This is the TestsAppsController index view';
  600. $this->assertEqual($result, $expected);
  601. $result = $this->object->requestAction('/tests_apps/some_method');
  602. $expected = 5;
  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. App::build();
  610. }
  611. /**
  612. * test requestAction() and plugins.
  613. *
  614. * @return void
  615. */
  616. function testRequestActionPlugins() {
  617. App::build(array(
  618. 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
  619. ));
  620. App::objects('plugin', null, false);
  621. Router::reload();
  622. $result = $this->object->requestAction('/test_plugin/tests/index', array('return'));
  623. $expected = 'test plugin index';
  624. $this->assertEqual($result, $expected);
  625. $result = $this->object->requestAction('/test_plugin/tests/index/some_param', array('return'));
  626. $expected = 'test plugin index';
  627. $this->assertEqual($result, $expected);
  628. $result = $this->object->requestAction(
  629. array('controller' => 'tests', 'action' => 'index', 'plugin' => 'test_plugin'), array('return')
  630. );
  631. $expected = 'test plugin index';
  632. $this->assertEqual($result, $expected);
  633. $result = $this->object->requestAction('/test_plugin/tests/some_method');
  634. $expected = 25;
  635. $this->assertEqual($result, $expected);
  636. $result = $this->object->requestAction(
  637. array('controller' => 'tests', 'action' => 'some_method', 'plugin' => 'test_plugin')
  638. );
  639. $expected = 25;
  640. $this->assertEqual($result, $expected);
  641. App::build();
  642. App::objects('plugin', null, false);
  643. }
  644. /**
  645. * test requestAction() with arrays.
  646. *
  647. * @return void
  648. */
  649. function testRequestActionArray() {
  650. App::build(array(
  651. 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
  652. 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
  653. 'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
  654. ));
  655. $result = $this->object->requestAction(
  656. array('controller' => 'request_action', 'action' => 'test_request_action')
  657. );
  658. $expected = 'This is a test';
  659. $this->assertEqual($result, $expected);
  660. $result = $this->object->requestAction(
  661. array('controller' => 'request_action', 'action' => 'another_ra_test'),
  662. array('pass' => array('5', '7'))
  663. );
  664. $expected = 12;
  665. $this->assertEqual($result, $expected);
  666. $result = $this->object->requestAction(
  667. array('controller' => 'tests_apps', 'action' => 'index'), array('return')
  668. );
  669. $expected = 'This is the TestsAppsController index view';
  670. $this->assertEqual($result, $expected);
  671. $result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'some_method'));
  672. $expected = 5;
  673. $this->assertEqual($result, $expected);
  674. $result = $this->object->requestAction(
  675. array('controller' => 'request_action', 'action' => 'normal_request_action')
  676. );
  677. $expected = 'Hello World';
  678. $this->assertEqual($result, $expected);
  679. $result = $this->object->requestAction(
  680. array('controller' => 'request_action', 'action' => 'paginate_request_action')
  681. );
  682. $this->assertTrue($result);
  683. $result = $this->object->requestAction(
  684. array('controller' => 'request_action', 'action' => 'paginate_request_action'),
  685. array('pass' => array(5), 'named' => array('param' => 'value'))
  686. );
  687. $this->assertTrue($result);
  688. App::build();
  689. }
  690. /**
  691. * Test that requestAction() is populating $this->params properly
  692. *
  693. * @access public
  694. * @return void
  695. */
  696. function testRequestActionParamParseAndPass() {
  697. $result = $this->object->requestAction('/request_action/params_pass');
  698. $this->assertTrue(isset($result['url']['url']));
  699. $this->assertEqual($result['url']['url'], '/request_action/params_pass');
  700. $this->assertEqual($result['controller'], 'request_action');
  701. $this->assertEqual($result['action'], 'params_pass');
  702. $this->assertEqual($result['form'], array());
  703. $this->assertEqual($result['plugin'], null);
  704. $result = $this->object->requestAction('/request_action/params_pass/sort:desc/limit:5');
  705. $expected = array('sort' => 'desc', 'limit' => 5,);
  706. $this->assertEqual($result['named'], $expected);
  707. $result = $this->object->requestAction(
  708. array('controller' => 'request_action', 'action' => 'params_pass'),
  709. array('named' => array('sort' => 'desc', 'limit' => 5))
  710. );
  711. $this->assertEqual($result['named'], $expected);
  712. }
  713. /**
  714. * test requestAction and POST parameter passing, and not passing when url is an array.
  715. *
  716. * @access public
  717. * @return void
  718. */
  719. function testRequestActionPostPassing() {
  720. $_tmp = $_POST;
  721. $_POST = array('data' => array(
  722. 'item' => 'value'
  723. ));
  724. $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
  725. $expected = array();
  726. $this->assertEqual($expected, $result);
  727. $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'), array('data' => $_POST['data']));
  728. $expected = $_POST['data'];
  729. $this->assertEqual($expected, $result);
  730. $result = $this->object->requestAction('/request_action/post_pass');
  731. $expected = $_POST['data'];
  732. $this->assertEqual($expected, $result);
  733. $_POST = $_tmp;
  734. }
  735. /**
  736. * testCakeError
  737. *
  738. * @return void
  739. */
  740. function testCakeError() {
  741. }
  742. }