RequestActionController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /**
  3. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  4. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice
  8. *
  9. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  11. * @since 3.0.0
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace TestApp\Controller;
  15. use Cake\Network\Exception\NotFoundException;
  16. /**
  17. * RequestActionController class
  18. */
  19. class RequestActionController extends AppController
  20. {
  21. /**
  22. * The default model to use.
  23. *
  24. * @var string
  25. */
  26. public $modelClass = 'Posts';
  27. /**
  28. * test_request_action method
  29. *
  30. * @return \Cake\Network\Response
  31. */
  32. public function test_request_action()
  33. {
  34. $this->response->body('This is a test');
  35. return $this->response;
  36. }
  37. /**
  38. * another_ra_test method
  39. *
  40. * @param mixed $id
  41. * @param mixed $other
  42. * @return \Cake\Network\Response
  43. */
  44. public function another_ra_test($id, $other)
  45. {
  46. $this->response->body($id + $other);
  47. return $this->response;
  48. }
  49. /**
  50. * normal_request_action method
  51. *
  52. * @return \Cake\Network\Response
  53. */
  54. public function normal_request_action()
  55. {
  56. $this->response->body('Hello World');
  57. return $this->response;
  58. }
  59. /**
  60. * returns $this->here as body
  61. *
  62. * @return \Cake\Network\Response
  63. */
  64. public function return_here()
  65. {
  66. $this->response->body($this->here);
  67. return $this->response;
  68. }
  69. /**
  70. * paginate_request_action method
  71. *
  72. * @return void
  73. */
  74. public function paginate_request_action()
  75. {
  76. $data = $this->paginate();
  77. $this->autoRender = false;
  78. }
  79. /**
  80. * post pass, testing post passing
  81. *
  82. * @return \Cake\Network\Response
  83. */
  84. public function post_pass()
  85. {
  86. $this->response->body(json_encode($this->request->data));
  87. return $this->response;
  88. }
  89. /**
  90. * query pass, testing query passing
  91. *
  92. * @return \Cake\Network\Response
  93. */
  94. public function query_pass()
  95. {
  96. $this->response->body(json_encode($this->request->query));
  97. return $this->response;
  98. }
  99. /**
  100. * cookie pass, testing cookie passing
  101. *
  102. * @return \Cake\Network\Response
  103. */
  104. public function cookie_pass()
  105. {
  106. $this->response->body(json_encode($this->request->cookies));
  107. return $this->response;
  108. }
  109. /**
  110. * test param passing and parsing.
  111. *
  112. * @return \Cake\Network\Response
  113. */
  114. public function params_pass()
  115. {
  116. $this->response->body(json_encode([
  117. 'params' => $this->request->params,
  118. 'base' => $this->request->base,
  119. 'here' => $this->request->here,
  120. 'webroot' => $this->request->webroot,
  121. 'params' => $this->request->params,
  122. 'query' => $this->request->query,
  123. 'url' => $this->request->url,
  124. 'contentType' => $this->request->contentType(),
  125. ]));
  126. return $this->response;
  127. }
  128. /**
  129. * param check method.
  130. *
  131. * @return \Cake\Network\Response
  132. */
  133. public function param_check()
  134. {
  135. $this->autoRender = false;
  136. $content = '';
  137. if (isset($this->request->params[0])) {
  138. $content = 'return found';
  139. }
  140. $this->response->body($content);
  141. return $this->response;
  142. }
  143. /**
  144. * Tests session transmission
  145. *
  146. * @return \Cake\Network\Response
  147. */
  148. public function session_test()
  149. {
  150. $this->response->body($this->request->session()->read('foo'));
  151. return $this->response;
  152. }
  153. /**
  154. * Tests input data transmission
  155. *
  156. * @return \Cake\Network\Response
  157. */
  158. public function input_test()
  159. {
  160. $this->response->body($this->request->input('json_decode')->hello);
  161. return $this->response;
  162. }
  163. /**
  164. * Tests exception handling
  165. *
  166. * @throws \Cake\Network\Exception\NotFoundException
  167. * @return void
  168. */
  169. public function error_method()
  170. {
  171. throw new NotFoundException('Not there or here.');
  172. }
  173. }