RequestActionController.php 3.1 KB

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