aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/HTTP/RequestTest.php
blob: c52ce351dab54c6002b7c3c8b03858ff1ad5ad33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php

namespace Sabre\HTTP;

/**
 * @covers Sabre\HTTP\Request
 */
class RequestTest extends \PHPUnit_Framework_TestCase {

    /**
     * @var Sabre\HTTP\Request
     */
    private $request;

    function setUp() {

        $server = array(
            'HTTP_HOST'      => 'www.example.org',
            'REQUEST_METHOD' => 'PUT',
            'REQUEST_URI'    => '/testuri/',
            'CONTENT_TYPE'   => 'text/xml',
        );

        $this->request = new Request($server);

    }

    function testGetHeader() {

        $this->assertEquals('www.example.org', $this->request->getHeader('Host'));
        $this->assertEquals('text/xml', $this->request->getHeader('Content-Type'));

    }

    function testGetNonExistantHeader() {

        $this->assertNull($this->request->getHeader('doesntexist'));
        $this->assertNull($this->request->getHeader('Content-Length'));

    }

    function testGetHeaders() {

        $expected = array(
            'host' => 'www.example.org',
            'content-type' => 'text/xml',
        );

        $this->assertEquals($expected, $this->request->getHeaders());

    }

    function testGetMethod() {

        $this->assertEquals('PUT', $this->request->getMethod(), 'It seems as if we didn\'t get a valid HTTP Request method back');

    }

    function testGetUri() {

        $this->assertEquals('/testuri/', $this->request->getUri(), 'We got an invalid uri back');

    }

    function testSetGetBody() {

        $h = fopen('php://memory','r+');
        fwrite($h,'testing');
        rewind($h);
        $this->request->setBody($h);
        $this->assertEquals('testing',$this->request->getBody(true),'We didn\'t get our testbody back');

    }

    function testSetGetBodyStream() {

        $h = fopen('php://memory','r+');
        fwrite($h,'testing');
        rewind($h);
        $this->request->setBody($h);
        $this->assertEquals('testing',stream_get_contents($this->request->getBody()),'We didn\'t get our testbody back');

    }


    function testDefaultInputStream() {

        $h = fopen('php://memory','r+');
        fwrite($h,'testing');
        rewind($h);

        $previousValue = Request::$defaultInputStream;
        Request::$defaultInputStream = $h;

        $this->assertEquals('testing',$this->request->getBody(true),'We didn\'t get our testbody back');
        Request::$defaultInputStream = $previousValue;

    }

    function testGetAbsoluteUri() {

        $s = array(
            'HTTP_HOST' => 'sabredav.org',
            'REQUEST_URI' => '/foo'
        );

        $r = new Request($s);

        $this->assertEquals('http://sabredav.org/foo', $r->getAbsoluteUri());

        $s = array(
            'HTTP_HOST'   => 'sabredav.org',
            'REQUEST_URI' => '/foo',
            'HTTPS'       => 'on',
        );

        $r = new Request($s);

        $this->assertEquals('https://sabredav.org/foo', $r->getAbsoluteUri());

    }

    function testGetQueryString() {

        $s = array(
            'QUERY_STRING' => 'bla',
        );

        $r = new Request($s);
        $this->assertEquals('bla', $r->getQueryString());

        $s = array();

        $r = new Request($s);
        $this->assertEquals('', $r->getQueryString());

    }

    function testGetPostVars() {

        $post = array(
            'bla' => 'foo',
        );
        $r = new Request(array(),$post);
        $this->assertEquals($post, $r->getPostVars('bla'));

    }


}