ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SapiTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\HTTP;
4
6
8
10 'REQUEST_URI' => '/foo',
11 'REQUEST_METHOD' => 'GET',
12 'HTTP_USER_AGENT' => 'Evert',
13 'CONTENT_TYPE' => 'text/xml',
14 'CONTENT_LENGTH' => '400',
15 'SERVER_PROTOCOL' => 'HTTP/1.0',
16 ]);
17
18 $this->assertEquals('GET', $request->getMethod());
19 $this->assertEquals('/foo', $request->getUrl());
20 $this->assertEquals([
21 'User-Agent' => ['Evert'],
22 'Content-Type' => ['text/xml'],
23 'Content-Length' => ['400'],
24 ], $request->getHeaders());
25
26 $this->assertEquals('1.0', $request->getHttpVersion());
27
28 $this->assertEquals('400', $request->getRawServerValue('CONTENT_LENGTH'));
29 $this->assertNull($request->getRawServerValue('FOO'));
30
31 }
32
34
36 'REQUEST_URI' => '/foo',
37 'REQUEST_METHOD' => 'GET',
38 'PHP_AUTH_USER' => 'user',
39 'PHP_AUTH_PW' => 'pass',
40 ]);
41
42 $this->assertEquals('GET', $request->getMethod());
43 $this->assertEquals('/foo', $request->getUrl());
44 $this->assertEquals([
45 'Authorization' => ['Basic ' . base64_encode('user:pass')],
46 ], $request->getHeaders());
47
48 }
49
51
53 'REQUEST_URI' => '/foo',
54 'REQUEST_METHOD' => 'GET',
55 'PHP_AUTH_DIGEST' => 'blabla',
56 ]);
57
58 $this->assertEquals('GET', $request->getMethod());
59 $this->assertEquals('/foo', $request->getUrl());
60 $this->assertEquals([
61 'Authorization' => ['Digest blabla'],
62 ], $request->getHeaders());
63
64 }
65
67
69 'REQUEST_URI' => '/foo',
70 'REQUEST_METHOD' => 'GET',
71 'REDIRECT_HTTP_AUTHORIZATION' => 'Basic bla',
72 ]);
73
74 $this->assertEquals('GET', $request->getMethod());
75 $this->assertEquals('/foo', $request->getUrl());
76 $this->assertEquals([
77 'Authorization' => ['Basic bla'],
78 ], $request->getHeaders());
79
80 }
81
88 function testSend() {
89
90 if (!function_exists('xdebug_get_headers')) {
91 $this->markTestSkipped('XDebug needs to be installed for this test to run');
92 }
93
94 $response = new Response(204, ['Content-Type' => 'text/xml;charset=UTF-8']);
95
96 // Second Content-Type header. Normally this doesn't make sense.
97 $response->addHeader('Content-Type', 'application/xml');
98 $response->setBody('foo');
99
100 ob_start();
101
103 $headers = xdebug_get_headers();
104
105 $result = ob_get_clean();
106 header_remove();
107
108 $this->assertEquals(
109 [
110 "Content-Type: text/xml;charset=UTF-8",
111 "Content-Type: application/xml",
112 ],
113 $headers
114 );
115
116 $this->assertEquals('foo', $result);
117
118 }
119
125
126 $response = new Response(200);
127
128 $response->addHeader('Content-Length', 19);
129 $response->setBody('Send this sentence. Ignore this one.');
130
131 ob_start();
132
134
135 $result = ob_get_clean();
136 header_remove();
137
138 $this->assertEquals('Send this sentence.', $result);
139
140 }
141
147
148 $response = new Response(200, ['Content-Length' => 19]);
149
150 $body = fopen('php://memory', 'w');
151 fwrite($body, 'Ignore this. Send this sentence. Ignore this too.');
152 rewind($body);
153 fread($body, 13);
154 $response->setBody($body);
155
156 ob_start();
157
159
160 $result = ob_get_clean();
161 header_remove();
162
163 $this->assertEquals('Send this sentence.', $result);
164
165 }
166
167}
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
An exception for terminatinating execution or to throw for unit testing.
This class represents a single HTTP response.
Definition: Response.php:12
testSend()
@runInSeparateProcess
Definition: SapiTest.php:88
testSendLimitedByContentLengthString()
@runInSeparateProcess @depends testSend
Definition: SapiTest.php:124
testConstructFromServerArray()
Definition: SapiTest.php:7
testSendLimitedByContentLengthStream()
@runInSeparateProcess @depends testSend
Definition: SapiTest.php:146
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
static sendResponse(ResponseInterface $response)
Sends the HTTP response back to a HTTP client.
Definition: Sapi.php:56
$response