| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- /**
- * CakePHP(tm) Tests <https://book.cakephp.org/view/1196/Testing>
- * Copyright 2005-2011, Cake Software Foundation, Inc. (https://cakefoundation.org)
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (https://cakefoundation.org)
- * @link https://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
- * @since 3.0.0
- * @license https://opensource.org/licenses/mit-license.php MIT License
- */
- namespace TestApp\Controller;
- use Cake\Http\Exception\NotFoundException;
- use Cake\Utility\Hash;
- use Psr\Http\Message\UploadedFileInterface;
- /**
- * RequestActionController class
- */
- class RequestActionController extends AppController
- {
- /**
- * The default model to use.
- *
- * @var string
- */
- public $modelClass = 'Posts';
- /**
- * test_request_action method
- *
- * @return \Cake\Http\Response
- */
- public function test_request_action()
- {
- return $this->response->withStringBody('This is a test');
- }
- /**
- * another_ra_test method
- *
- * @param mixed $id
- * @param mixed $other
- * @return \Cake\Http\Response
- */
- public function another_ra_test($id, $other)
- {
- return $this->response->withStringBody($id + $other);
- }
- /**
- * normal_request_action method
- *
- * @return \Cake\Http\Response
- */
- public function normal_request_action()
- {
- return $this->response->withStringBody('Hello World');
- }
- /**
- * returns $this->here as body
- *
- * @return \Cake\Http\Response
- */
- public function return_here()
- {
- return $this->response->withStringBody($this->here);
- }
- /**
- * paginate_request_action method
- *
- * @return void
- */
- public function paginate_request_action()
- {
- $data = $this->paginate();
- $this->autoRender = false;
- }
- /**
- * post pass, testing post passing
- *
- * @return \Cake\Http\Response
- */
- public function post_pass()
- {
- return $this->response->withStringBody(json_encode($this->request->getData()));
- }
- /**
- * query pass, testing query passing
- *
- * @return \Cake\Http\Response
- */
- public function query_pass()
- {
- return $this->response->withStringBody(json_encode($this->request->getQueryParams()));
- }
- /**
- * cookie pass, testing cookie passing
- *
- * @return \Cake\Http\Response
- */
- public function cookie_pass()
- {
- return $this->response->withStringBody(json_encode($this->request->getCookieParams()));
- }
- /**
- * test param passing and parsing.
- *
- * @return \Cake\Http\Response
- */
- public function params_pass()
- {
- return $this->response->withStringBody(json_encode([
- 'params' => $this->request->getAttribute('params'),
- 'base' => $this->request->getAttribute('base'),
- 'here' => $this->request->getRequestTarget(),
- 'webroot' => $this->request->getAttribute('webroot'),
- 'query' => $this->request->getQueryParams(),
- 'url' => $this->request->getUri()->getPath(),
- 'contentType' => $this->request->contentType(),
- ]));
- }
- /**
- * param check method.
- *
- * @return \Cake\Http\Response
- */
- public function param_check()
- {
- $this->autoRender = false;
- $content = '';
- if ($this->request->getParam('0')) {
- $content = 'return found';
- }
- return $this->response->withStringBody($content);
- }
- /**
- * Tests session transmission
- *
- * @return \Cake\Http\Response
- */
- public function session_test()
- {
- return $this->response->withStringBody($this->request->getSession()->read('foo'));
- }
- /**
- * Tests input data transmission
- *
- * @return \Cake\Http\Response
- */
- public function input_test()
- {
- $text = $this->request->input('json_decode')->hello;
- return $this->response->withStringBody($text);
- }
- /**
- * Tests exception handling
- *
- * @throws \Cake\Http\Exception\NotFoundException
- * @return void
- */
- public function error_method()
- {
- throw new NotFoundException('Not there or here.');
- }
- /**
- * Tests uploaded files
- *
- * @return \Cake\Http\Response
- */
- public function uploaded_files()
- {
- $files = Hash::flatten($this->request->getUploadedFiles());
- $names = collection($files)->map(function (UploadedFileInterface $file) {
- return $file->getClientFilename();
- });
- return $this->response->withStringBody(json_encode($names));
- }
- }
|