RequestActionController.php 3.7 KB

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