RequestActionController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /**
  16. * RequestActionController class
  17. *
  18. */
  19. class RequestActionController extends AppController {
  20. /**
  21. * modelClass property
  22. *
  23. * @var string
  24. */
  25. public $modelClass = 'Posts';
  26. /**
  27. * test_request_action method
  28. *
  29. * @return \Cake\Network\Response
  30. */
  31. public function test_request_action() {
  32. $this->response->body('This is a test');
  33. return $this->response;
  34. }
  35. /**
  36. * another_ra_test method
  37. *
  38. * @param mixed $id
  39. * @param mixed $other
  40. * @return \Cake\Network\Response
  41. */
  42. public function another_ra_test($id, $other) {
  43. $this->response->body($id + $other);
  44. return $this->response;
  45. }
  46. /**
  47. * normal_request_action method
  48. *
  49. * @return \Cake\Network\Response
  50. */
  51. public function normal_request_action() {
  52. $this->response->body('Hello World');
  53. return $this->response;
  54. }
  55. /**
  56. * returns $this->here as body
  57. *
  58. * @return \Cake\Network\Response
  59. */
  60. public function return_here() {
  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. $data = $this->paginate();
  71. }
  72. /**
  73. * post pass, testing post passing
  74. *
  75. * @return array
  76. */
  77. public function post_pass() {
  78. $this->response->body(json_encode($this->request->data));
  79. }
  80. /**
  81. * query pass, testing query passing
  82. *
  83. * @return array
  84. */
  85. public function query_pass() {
  86. $this->response->body(json_encode($this->request->query));
  87. }
  88. /**
  89. * test param passing and parsing.
  90. *
  91. * @return void
  92. */
  93. public function params_pass() {
  94. $this->response->body(json_encode([
  95. 'params' => $this->request->params,
  96. 'query' => $this->request->query,
  97. 'url' => $this->request->url,
  98. 'contentType' => $this->request->env('CONTENT_TYPE'),
  99. ]));
  100. }
  101. /**
  102. * param check method.
  103. *
  104. * @return void
  105. */
  106. public function param_check() {
  107. $this->autoRender = false;
  108. $content = '';
  109. if (isset($this->request->params[0])) {
  110. $content = 'return found';
  111. }
  112. $this->response->body($content);
  113. }
  114. /**
  115. * Tests session transmission
  116. *
  117. * @return void
  118. */
  119. public function session_test() {
  120. $this->response->body($this->request->session()->read('foo'));
  121. return $this->response;
  122. }
  123. }