ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
RequestTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\HTTP;
4 
6 
7  function testConstruct() {
8 
9  $request = new Request('GET', '/foo', [
10  'User-Agent' => 'Evert',
11  ]);
12  $this->assertEquals('GET', $request->getMethod());
13  $this->assertEquals('/foo', $request->getUrl());
14  $this->assertEquals([
15  'User-Agent' => ['Evert'],
16  ], $request->getHeaders());
17 
18  }
19 
21 
22  $request = new Request('GET', '/foo?a=b&c&d=e');
23  $this->assertEquals([
24  'a' => 'b',
25  'c' => null,
26  'd' => 'e',
27  ], $request->getQueryParameters());
28 
29  }
30 
32 
33  $request = new Request('GET', '/foo');
34  $this->assertEquals([], $request->getQueryParameters());
35 
36  }
37 
42 
43  $_SERVER['REQUEST_METHOD'] = 'PUT';
44 
46  $this->assertEquals('PUT', $request->getMethod());
47 
48  }
49 
50  function testGetAbsoluteUrl() {
51 
52  $s = [
53  'HTTP_HOST' => 'sabredav.org',
54  'REQUEST_URI' => '/foo'
55  ];
56 
58 
59  $this->assertEquals('http://sabredav.org/foo', $r->getAbsoluteUrl());
60 
61  $s = [
62  'HTTP_HOST' => 'sabredav.org',
63  'REQUEST_URI' => '/foo',
64  'HTTPS' => 'on',
65  ];
66 
68 
69  $this->assertEquals('https://sabredav.org/foo', $r->getAbsoluteUrl());
70 
71  }
72 
73  function testGetPostData() {
74 
75  $post = [
76  'bla' => 'foo',
77  ];
78  $r = new Request();
79  $r->setPostData($post);
80  $this->assertEquals($post, $r->getPostData());
81 
82  }
83 
84  function testGetPath() {
85 
86  $request = new Request();
87  $request->setBaseUrl('/foo');
88  $request->setUrl('/foo/bar/');
89 
90  $this->assertEquals('bar', $request->getPath());
91 
92  }
93 
95 
96  $request = new Request();
97  $request->setBaseUrl('/foo');
98  $request->setUrl('/foo/bar/?a=b');
99 
100  $this->assertEquals('bar', $request->getPath());
101 
102  }
103 
105 
106  $request = new Request();
107  $request->setBaseUrl('/foo/');
108  $request->setUrl('/foo');
109 
110  $this->assertEquals('', $request->getPath());
111 
112  }
113 
118 
119  $request = new Request();
120  $request->setBaseUrl('/foo/');
121  $request->setUrl('/bar/');
122 
123  $request->getPath();
124 
125  }
126 
127  function testToString() {
128 
129  $request = new Request('PUT', '/foo/bar', ['Content-Type' => 'text/xml']);
130  $request->setBody('foo');
131 
132  $expected = <<<HI
133 PUT /foo/bar HTTP/1.1\r
134 Content-Type: text/xml\r
135 \r
136 foo
137 HI;
138  $this->assertEquals($expected, (string)$request);
139 
140  }
141 
143 
144  $request = new Request('PUT', '/foo/bar', ['Content-Type' => 'text/xml', 'Authorization' => 'Basic foobar']);
145  $request->setBody('foo');
146 
147  $expected = <<<HI
148 PUT /foo/bar HTTP/1.1\r
149 Content-Type: text/xml\r
150 Authorization: Basic REDACTED\r
151 \r
152 foo
153 HI;
154  $this->assertEquals($expected, (string)$request);
155 
156  }
157 
162 
163  $request = new Request([]);
164 
165  }
166 
167 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
foreach($paths as $path) $request
Definition: asyncclient.php:32
The Request class represents a single HTTP request.
Definition: Request.php:18
static getRequest()
This static method will create a new Request object, based on the current PHP request.
Definition: Sapi.php:39
$s
Definition: pwgen.php:45
$r
Definition: example_031.php:79
$post
Definition: post.php:34
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107