1<?php
2
3namespace Sabre\HTTP;
4
5class RequestDecoratorTest extends \PHPUnit_Framework_TestCase {
6
7    protected $inner;
8    protected $outer;
9
10    function setUp() {
11
12        $this->inner = new Request();
13        $this->outer = new RequestDecorator($this->inner);
14
15    }
16
17    function testMethod() {
18
19        $this->outer->setMethod('FOO');
20        $this->assertEquals('FOO', $this->inner->getMethod());
21        $this->assertEquals('FOO', $this->outer->getMethod());
22
23    }
24
25    function testUrl() {
26
27        $this->outer->setUrl('/foo');
28        $this->assertEquals('/foo', $this->inner->getUrl());
29        $this->assertEquals('/foo', $this->outer->getUrl());
30
31    }
32
33    function testAbsoluteUrl() {
34
35        $this->outer->setAbsoluteUrl('http://example.org/foo');
36        $this->assertEquals('http://example.org/foo', $this->inner->getAbsoluteUrl());
37        $this->assertEquals('http://example.org/foo', $this->outer->getAbsoluteUrl());
38
39    }
40
41    function testBaseUrl() {
42
43        $this->outer->setBaseUrl('/foo');
44        $this->assertEquals('/foo', $this->inner->getBaseUrl());
45        $this->assertEquals('/foo', $this->outer->getBaseUrl());
46
47    }
48
49    function testPath() {
50
51        $this->outer->setBaseUrl('/foo');
52        $this->outer->setUrl('/foo/bar');
53        $this->assertEquals('bar', $this->inner->getPath());
54        $this->assertEquals('bar', $this->outer->getPath());
55
56    }
57
58    function testQueryParams() {
59
60        $this->outer->setUrl('/foo?a=b&c=d&e');
61        $expected = [
62            'a' => 'b',
63            'c' => 'd',
64            'e' => null,
65        ];
66
67        $this->assertEquals($expected, $this->inner->getQueryParameters());
68        $this->assertEquals($expected, $this->outer->getQueryParameters());
69
70    }
71
72    function testPostData() {
73
74        $postData = [
75            'a' => 'b',
76            'c' => 'd',
77            'e' => null,
78        ];
79
80        $this->outer->setPostData($postData);
81        $this->assertEquals($postData, $this->inner->getPostData());
82        $this->assertEquals($postData, $this->outer->getPostData());
83
84    }
85
86
87    function testServerData() {
88
89        $serverData = [
90            'HTTPS' => 'On',
91        ];
92
93        $this->outer->setRawServerData($serverData);
94        $this->assertEquals('On', $this->inner->getRawServerValue('HTTPS'));
95        $this->assertEquals('On', $this->outer->getRawServerValue('HTTPS'));
96
97        $this->assertNull($this->inner->getRawServerValue('FOO'));
98        $this->assertNull($this->outer->getRawServerValue('FOO'));
99    }
100
101    function testToString() {
102
103        $this->inner->setMethod('POST');
104        $this->inner->setUrl('/foo/bar/');
105        $this->inner->setBody('foo');
106        $this->inner->setHeader('foo', 'bar');
107
108        $this->assertEquals((string)$this->inner, (string)$this->outer);
109
110    }
111
112}
113