1<?php
2
3namespace Sabre\HTTP;
4
5class FunctionsTest extends \PHPUnit_Framework_TestCase {
6
7    /**
8     * @dataProvider getHeaderValuesData
9     */
10    function testGetHeaderValues($input, $output) {
11
12        $this->assertEquals(
13            $output,
14            getHeaderValues($input)
15        );
16
17    }
18
19    function getHeaderValuesData() {
20
21        return [
22            [
23                "a",
24                ["a"]
25            ],
26            [
27                "a,b",
28                ["a", "b"]
29            ],
30            [
31                "a, b",
32                ["a", "b"]
33            ],
34            [
35                ["a, b"],
36                ["a", "b"]
37            ],
38            [
39                ["a, b", "c", "d,e"],
40                ["a", "b", "c", "d", "e"]
41            ],
42        ];
43
44    }
45
46    /**
47     * @dataProvider preferData
48     */
49    function testPrefer($input, $output) {
50
51        $this->assertEquals(
52            $output,
53            parsePrefer($input)
54        );
55
56    }
57
58    function preferData() {
59
60        return [
61            [
62                'foo; bar',
63                ['foo' => true]
64            ],
65            [
66                'foo; bar=""',
67                ['foo' => true]
68            ],
69            [
70                'foo=""; bar',
71                ['foo' => true]
72            ],
73            [
74                'FOO',
75                ['foo' => true]
76            ],
77            [
78                'respond-async',
79                ['respond-async' => true]
80            ],
81            [
82
83                ['respond-async, wait=100', 'handling=lenient'],
84                ['respond-async' => true, 'wait' => 100, 'handling' => 'lenient']
85            ],
86            [
87
88                ['respond-async, wait=100, handling=lenient'],
89                ['respond-async' => true, 'wait' => 100, 'handling' => 'lenient']
90            ],
91            // Old values
92            [
93
94                'return-asynch, return-representation',
95                ['respond-async' => true, 'return' => 'representation'],
96            ],
97            [
98
99                'return-minimal',
100                ['return' => 'minimal'],
101            ],
102            [
103
104                'strict',
105                ['handling' => 'strict'],
106            ],
107            [
108
109                'lenient',
110                ['handling' => 'lenient'],
111            ],
112            // Invalid token
113            [
114                ['foo=%bar%'],
115                [],
116            ]
117        ];
118
119    }
120
121}
122