RequestActionController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. */
  20. class RequestActionController extends AppController
  21. {
  22. /**
  23. * The default model to use.
  24. *
  25. * @var string
  26. */
  27. public $modelClass = 'Posts';
  28. /**
  29. * test_request_action method
  30. *
  31. * @return \Cake\Network\Response
  32. */
  33. public function test_request_action()
  34. {
  35. $this->response->body('This is a test');
  36. return $this->response;
  37. }
  38. /**
  39. * another_ra_test method
  40. *
  41. * @param mixed $id
  42. * @param mixed $other
  43. * @return \Cake\Network\Response
  44. */
  45. public function another_ra_test($id, $other)
  46. {
  47. $this->response->body($id + $other);
  48. return $this->response;
  49. }
  50. /**
  51. * normal_request_action method
  52. *
  53. * @return \Cake\Network\Response
  54. */
  55. public function normal_request_action()
  56. {
  57. $this->response->body('Hello World');
  58. return $this->response;
  59. }
  60. /**
  61. * returns $this->here as body
  62. *
  63. * @return \Cake\Network\Response
  64. */
  65. public function return_here()
  66. {
  67. $this->response->body($this->here);
  68. return $this->response;
  69. }
  70. /**
  71. * paginate_request_action method
  72. *
  73. * @return void
  74. */
  75. public function paginate_request_action()
  76. {
  77. $data = $this->paginate();
  78. $this->autoRender = false;
  79. }
  80. /**
  81. * post pass, testing post passing
  82. *
  83. * @return \Cake\Network\Response
  84. */
  85. public function post_pass()
  86. {
  87. $this->response->body(json_encode($this->request->data));
  88. return $this->response;
  89. }
  90. /**
  91. * query pass, testing query passing
  92. *
  93. * @return \Cake\Network\Response
  94. */
  95. public function query_pass()
  96. {
  97. $this->response->body(json_encode($this->request->query));
  98. return $this->response;
  99. }
  100. /**
  101. * test param passing and parsing.
  102. *
  103. * @return \Cake\Network\Response
  104. */
  105. public function params_pass()
  106. {
  107. $this->response->body(json_encode([
  108. 'params' => $this->request->params,
  109. 'base' => $this->request->base,
  110. 'here' => $this->request->here,
  111. 'webroot' => $this->request->webroot,
  112. 'params' => $this->request->params,
  113. 'query' => $this->request->query,
  114. 'url' => $this->request->url,
  115. 'contentType' => $this->request->env('CONTENT_TYPE'),
  116. ]));
  117. return $this->response;
  118. }
  119. /**
  120. * param check method.
  121. *
  122. * @return \Cake\Network\Response
  123. */
  124. public function param_check()
  125. {
  126. $this->autoRender = false;
  127. $content = '';
  128. if (isset($this->request->params[0])) {
  129. $content = 'return found';
  130. }
  131. $this->response->body($content);
  132. return $this->response;
  133. }
  134. /**
  135. * Tests session transmission
  136. *
  137. * @return \Cake\Network\Response
  138. */
  139. public function session_test()
  140. {
  141. $this->response->body($this->request->session()->read('foo'));
  142. return $this->response;
  143. }
  144. /**
  145. * Tests exception handling
  146. *
  147. * @throws \Cake\Network\Exception\NotFoundException
  148. * @return void
  149. */
  150. public function error_method()
  151. {
  152. throw new NotFoundException('Not there or here.');
  153. }
  154. }