TYPO3 CMS  TYPO3_7-6
ServerRequestTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
27 {
31  protected $request;
32 
33  protected function setUp()
34  {
35  $this->request = new ServerRequest();
36  }
37 
42  {
43  $this->assertEmpty($this->request->getServerParams());
44  }
45 
50  {
51  $this->assertEmpty($this->request->getQueryParams());
52  }
53 
58  {
59  $value = ['foo' => 'bar'];
60  $request = $this->request->withQueryParams($value);
61  $this->assertNotSame($this->request, $request);
62  $this->assertEquals($value, $request->getQueryParams());
63  }
64 
69  {
70  $this->assertEmpty($this->request->getCookieParams());
71  }
72 
77  {
78  $value = ['foo' => 'bar'];
79  $request = $this->request->withCookieParams($value);
80  $this->assertNotSame($this->request, $request);
81  $this->assertEquals($value, $request->getCookieParams());
82  }
83 
88  {
89  $this->assertEmpty($this->request->getUploadedFiles());
90  }
91 
96  {
97  $this->assertEmpty($this->request->getParsedBody());
98  }
99 
104  {
105  $value = ['foo' => 'bar'];
106  $request = $this->request->withParsedBody($value);
107  $this->assertNotSame($this->request, $request);
108  $this->assertEquals($value, $request->getParsedBody());
109  }
110 
115  {
116  $this->assertEmpty($this->request->getAttributes());
117  }
118 
124  {
125  $request = $this->request->withAttribute('foo', 'bar');
126  $this->assertNotSame($this->request, $request);
127  $this->assertEquals('bar', $request->getAttribute('foo'));
128 
129  return $request;
130  }
131 
137  {
138  $new = $request->withoutAttribute('foo');
139  $this->assertNotSame($request, $new);
140  $this->assertNull($new->getAttribute('foo', null));
141  }
142 
147  {
148  $server = [
149  'foo' => 'bar',
150  'baz' => 'bat',
151  ];
152 
153  $server['server'] = true;
154 
155  $files = [
156  'files' => new UploadedFile('php://temp', 0, 0),
157  ];
158 
159  $uri = new Uri('http://example.com');
160  $method = 'POST';
161  $headers = [
162  'host' => ['example.com'],
163  ];
164 
165  $request = new ServerRequest(
166  $uri,
167  $method,
168  'php://memory',
169  $headers,
170  $server,
171  $files
172  );
173 
174  $this->assertEquals($server, $request->getServerParams());
175  $this->assertEquals($files, $request->getUploadedFiles());
176 
177  $this->assertSame($uri, $request->getUri());
178  $this->assertEquals($method, $request->getMethod());
179  $this->assertEquals($headers, $request->getHeaders());
180 
181  $body = $request->getBody();
182  $r = new \ReflectionProperty($body, 'stream');
183  $r->setAccessible(true);
184  $stream = $r->getValue($body);
185  $this->assertEquals('php://memory', $stream);
186  }
187 }