]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/HTTP/RequestTest.php
ef2326e09c5441a5573814f4be8459c8d0533d13
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / HTTP / RequestTest.php
1 <?php
2
3 /**
4  * @covers Sabre_HTTP_Request
5  */
6 class Sabre_HTTP_RequestTest extends PHPUnit_Framework_TestCase {
7
8     /**
9      * @var Sabre_HTTP_Request
10      */
11     private $request;
12
13     function setUp() {
14
15         $server = array(
16             'HTTP_HOST'      => 'www.example.org',
17             'REQUEST_METHOD' => 'PUT',
18             'REQUEST_URI'    => '/testuri/',
19             'CONTENT_TYPE'   => 'text/xml',
20         );
21
22         $this->request = new Sabre_HTTP_Request($server);
23
24     }
25
26     function testGetHeader() {
27
28         $this->assertEquals('www.example.org', $this->request->getHeader('Host'));
29         $this->assertEquals('text/xml', $this->request->getHeader('Content-Type'));
30
31     }
32
33     function testGetNonExistantHeader() {
34
35         $this->assertNull($this->request->getHeader('doesntexist'));
36         $this->assertNull($this->request->getHeader('Content-Length'));
37
38     }
39
40     function testGetHeaders() {
41
42         $expected = array(
43             'host' => 'www.example.org',
44             'content-type' => 'text/xml',
45         );
46
47         $this->assertEquals($expected, $this->request->getHeaders());
48
49     }
50
51     function testGetMethod() {
52
53         $this->assertEquals('PUT', $this->request->getMethod(), 'It seems as if we didn\'t get a valid HTTP Request method back');
54
55     }
56
57     function testGetUri() {
58
59         $this->assertEquals('/testuri/', $this->request->getUri(), 'We got an invalid uri back');
60
61     }
62
63     function testSetGetBody() {
64
65         $h = fopen('php://memory','r+');
66         fwrite($h,'testing');
67         rewind($h);
68         $this->request->setBody($h);
69         $this->assertEquals('testing',$this->request->getBody(true),'We didn\'t get our testbody back');
70
71     }
72
73     function testSetGetBodyStream() {
74
75         $h = fopen('php://memory','r+');
76         fwrite($h,'testing');
77         rewind($h);
78         $this->request->setBody($h);
79         $this->assertEquals('testing',stream_get_contents($this->request->getBody()),'We didn\'t get our testbody back');
80
81     }
82
83
84     function testDefaultInputStream() {
85
86         $h = fopen('php://memory','r+');
87         fwrite($h,'testing');
88         rewind($h);
89
90         $previousValue = Sabre_HTTP_Request::$defaultInputStream;
91         Sabre_HTTP_Request::$defaultInputStream = $h;
92
93         $this->assertEquals('testing',$this->request->getBody(true),'We didn\'t get our testbody back');
94         Sabre_HTTP_Request::$defaultInputStream = $previousValue;
95
96     }
97
98     function testGetAbsoluteUri() {
99
100         $s = array(
101             'HTTP_HOST' => 'sabredav.org',
102             'REQUEST_URI' => '/foo'
103         );
104
105         $r = new Sabre_HTTP_Request($s);
106
107         $this->assertEquals('http://sabredav.org/foo', $r->getAbsoluteUri());
108
109         $s = array(
110             'HTTP_HOST'   => 'sabredav.org',
111             'REQUEST_URI' => '/foo',
112             'HTTPS'       => 'on',
113         );
114
115         $r = new Sabre_HTTP_Request($s);
116
117         $this->assertEquals('https://sabredav.org/foo', $r->getAbsoluteUri());
118
119     }
120
121     function testGetQueryString() {
122
123         $s = array(
124             'QUERY_STRING' => 'bla',
125         );
126
127         $r = new Sabre_HTTP_Request($s);
128         $this->assertEquals('bla', $r->getQueryString());
129
130         $s = array();
131
132         $r = new Sabre_HTTP_Request($s);
133         $this->assertEquals('', $r->getQueryString());
134
135     }
136
137     function testGetPostVars() {
138
139         $post = array(
140             'bla' => 'foo',
141         );
142         $r = new Sabre_HTTP_Request(array(),$post);
143         $this->assertEquals($post, $r->getPostVars('bla'));
144
145     }
146
147
148 }