4 * @covers Sabre_HTTP_Request
6 class Sabre_HTTP_RequestTest extends PHPUnit_Framework_TestCase {
9 * @var Sabre_HTTP_Request
16 'HTTP_HOST' => 'www.example.org',
17 'REQUEST_METHOD' => 'PUT',
18 'REQUEST_URI' => '/testuri/',
19 'CONTENT_TYPE' => 'text/xml',
22 $this->request = new Sabre_HTTP_Request($server);
26 function testGetHeader() {
28 $this->assertEquals('www.example.org', $this->request->getHeader('Host'));
29 $this->assertEquals('text/xml', $this->request->getHeader('Content-Type'));
33 function testGetNonExistantHeader() {
35 $this->assertNull($this->request->getHeader('doesntexist'));
36 $this->assertNull($this->request->getHeader('Content-Length'));
40 function testGetHeaders() {
43 'host' => 'www.example.org',
44 'content-type' => 'text/xml',
47 $this->assertEquals($expected, $this->request->getHeaders());
51 function testGetMethod() {
53 $this->assertEquals('PUT', $this->request->getMethod(), 'It seems as if we didn\'t get a valid HTTP Request method back');
57 function testGetUri() {
59 $this->assertEquals('/testuri/', $this->request->getUri(), 'We got an invalid uri back');
63 function testSetGetBody() {
65 $h = fopen('php://memory','r+');
68 $this->request->setBody($h);
69 $this->assertEquals('testing',$this->request->getBody(true),'We didn\'t get our testbody back');
73 function testSetGetBodyStream() {
75 $h = fopen('php://memory','r+');
78 $this->request->setBody($h);
79 $this->assertEquals('testing',stream_get_contents($this->request->getBody()),'We didn\'t get our testbody back');
84 function testDefaultInputStream() {
86 $h = fopen('php://memory','r+');
90 $previousValue = Sabre_HTTP_Request::$defaultInputStream;
91 Sabre_HTTP_Request::$defaultInputStream = $h;
93 $this->assertEquals('testing',$this->request->getBody(true),'We didn\'t get our testbody back');
94 Sabre_HTTP_Request::$defaultInputStream = $previousValue;
98 function testGetAbsoluteUri() {
101 'HTTP_HOST' => 'sabredav.org',
102 'REQUEST_URI' => '/foo'
105 $r = new Sabre_HTTP_Request($s);
107 $this->assertEquals('http://sabredav.org/foo', $r->getAbsoluteUri());
110 'HTTP_HOST' => 'sabredav.org',
111 'REQUEST_URI' => '/foo',
115 $r = new Sabre_HTTP_Request($s);
117 $this->assertEquals('https://sabredav.org/foo', $r->getAbsoluteUri());
121 function testGetQueryString() {
124 'QUERY_STRING' => 'bla',
127 $r = new Sabre_HTTP_Request($s);
128 $this->assertEquals('bla', $r->getQueryString());
132 $r = new Sabre_HTTP_Request($s);
133 $this->assertEquals('', $r->getQueryString());
137 function testGetPostVars() {
142 $r = new Sabre_HTTP_Request(array(),$post);
143 $this->assertEquals($post, $r->getPostVars('bla'));