forked from sabre-io/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNegotiateTest.php
More file actions
141 lines (136 loc) · 4.4 KB
/
Copy pathNegotiateTest.php
File metadata and controls
141 lines (136 loc) · 4.4 KB
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
<?php
declare(strict_types=1);
namespace Sabre\HTTP;
use PHPUnit\Framework\Attributes\DataProvider;
class NegotiateTest extends \PHPUnit\Framework\TestCase
{
/**
* @param array<mixed, mixed> $available
*/
#[DataProvider('negotiateData')]
public function testNegotiate(?string $acceptHeader, array $available, ?string $expected): void
{
self::assertEquals(
$expected,
negotiateContentType($acceptHeader, $available)
);
}
/**
* @return array<int, array<int, mixed>>
*/
public static function negotiateData(): array
{
return [
[ // simple
'application/xml',
['application/xml'],
'application/xml',
],
[ // no header
null,
['application/xml'],
'application/xml',
],
[ // 2 options
'application/json',
['application/xml', 'application/json'],
'application/json',
],
[ // 2 choices
'application/json, application/xml',
['application/xml'],
'application/xml',
],
[ // quality
'application/xml;q=0.2, application/json',
['application/xml', 'application/json'],
'application/json',
],
[ // wildcard
'image/jpeg, image/png, */*',
['application/xml', 'application/json'],
'application/xml',
],
[ // wildcard + quality
'image/jpeg, image/png; q=0.5, */*',
['application/xml', 'application/json', 'image/png'],
'application/xml',
],
[ // no match
'image/jpeg',
['application/xml'],
null,
],
[ // This is used in sabre/dav
'text/vcard; version=4.0',
[
// Most often used mime-type. Version 3
'text/x-vcard',
// The correct standard mime-type. Defaults to version 3 as
// well.
'text/vcard',
// vCard 4
'text/vcard; version=4.0',
// vCard 3
'text/vcard; version=3.0',
// jCard
'application/vcard+json',
],
'text/vcard; version=4.0',
],
[ // rfc7231 example 1
'audio/*; q=0.2, audio/basic',
[
'audio/pcm',
'audio/basic',
],
'audio/basic',
],
[ // Lower quality after
'audio/pcm; q=0.2, audio/basic; q=0.1',
[
'audio/pcm',
'audio/basic',
],
'audio/pcm',
],
[ // Random parameter, should be ignored
'audio/pcm; hello; q=0.2, audio/basic; q=0.1',
[
'audio/pcm',
'audio/basic',
],
'audio/pcm',
],
[ // No whitespace after type, should pick the one that is the most specific.
'text/vcard;version=3.0, text/vcard',
[
'text/vcard',
'text/vcard; version=3.0',
],
'text/vcard; version=3.0',
],
[ // Same as last one, but order is different
'text/vcard, text/vcard;version=3.0',
[
'text/vcard; version=3.0',
'text/vcard',
],
'text/vcard; version=3.0',
],
[ // Charset should be ignored here.
'text/vcard; charset=utf-8; version=3.0, text/vcard',
[
'text/vcard',
'text/vcard; version=3.0',
],
'text/vcard; version=3.0',
],
[ // Undefined offset issue.
'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2',
['application/xml', 'application/json', 'image/png'],
'application/xml',
],
];
}
}