ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\HTTP\UtilTest Class Reference
+ Inheritance diagram for Sabre\HTTP\UtilTest:
+ Collaboration diagram for Sabre\HTTP\UtilTest:

Public Member Functions

 testParseHTTPDate ()
 
 testParseHTTPDateFail ()
 
 testTimezones ()
 
 testToHTTPDate ()
 
 testNegotiate ($acceptHeader, $available, $expected)
 @dataProvider negotiateData More...
 
 negotiateData ()
 

Detailed Description

Definition at line 5 of file UtilTest.php.

Member Function Documentation

◆ negotiateData()

Sabre\HTTP\UtilTest::negotiateData ( )

Definition at line 88 of file UtilTest.php.

88 {
89
90 return [
91 [ // simple
92 'application/xml',
93 ['application/xml'],
94 'application/xml',
95 ],
96 [ // no header
97 null,
98 ['application/xml'],
99 'application/xml',
100 ],
101 [ // 2 options
102 'application/json',
103 ['application/xml', 'application/json'],
104 'application/json',
105 ],
106 [ // 2 choices
107 'application/json, application/xml',
108 ['application/xml'],
109 'application/xml',
110 ],
111 [ // quality
112 'application/xml;q=0.2, application/json',
113 ['application/xml', 'application/json'],
114 'application/json',
115 ],
116 [ // wildcard
117 'image/jpeg, image/png, */*',
118 ['application/xml', 'application/json'],
119 'application/xml',
120 ],
121 [ // wildcard + quality
122 'image/jpeg, image/png; q=0.5, */*',
123 ['application/xml', 'application/json', 'image/png'],
124 'application/xml',
125 ],
126 [ // no match
127 'image/jpeg',
128 ['application/xml'],
129 null,
130 ],
131 [ // This is used in sabre/dav
132 'text/vcard; version=4.0',
133 [
134 // Most often used mime-type. Version 3
135 'text/x-vcard',
136 // The correct standard mime-type. Defaults to version 3 as
137 // well.
138 'text/vcard',
139 // vCard 4
140 'text/vcard; version=4.0',
141 // vCard 3
142 'text/vcard; version=3.0',
143 // jCard
144 'application/vcard+json',
145 ],
146 'text/vcard; version=4.0',
147
148 ],
149 [ // rfc7231 example 1
150 'audio/*; q=0.2, audio/basic',
151 [
152 'audio/pcm',
153 'audio/basic',
154 ],
155 'audio/basic',
156 ],
157 [ // Lower quality after
158 'audio/pcm; q=0.2, audio/basic; q=0.1',
159 [
160 'audio/pcm',
161 'audio/basic',
162 ],
163 'audio/pcm',
164 ],
165 [ // Random parameter, should be ignored
166 'audio/pcm; hello; q=0.2, audio/basic; q=0.1',
167 [
168 'audio/pcm',
169 'audio/basic',
170 ],
171 'audio/pcm',
172 ],
173 [ // No whitepace after type, should pick the one that is the most specific.
174 'text/vcard;version=3.0, text/vcard',
175 [
176 'text/vcard',
177 'text/vcard; version=3.0'
178 ],
179 'text/vcard; version=3.0',
180 ],
181 [ // Same as last one, but order is different
182 'text/vcard, text/vcard;version=3.0',
183 [
184 'text/vcard; version=3.0',
185 'text/vcard',
186 ],
187 'text/vcard; version=3.0',
188 ],
189 [ // Charset should be ignored here.
190 'text/vcard; charset=utf-8; version=3.0, text/vcard',
191 [
192 'text/vcard',
193 'text/vcard; version=3.0'
194 ],
195 'text/vcard; version=3.0',
196 ],
197 [ // Undefined offset issue.
198 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2',
199 ['application/xml', 'application/json', 'image/png'],
200 'application/xml',
201 ],
202
203 ];
204
205 }

◆ testNegotiate()

Sabre\HTTP\UtilTest::testNegotiate (   $acceptHeader,
  $available,
  $expected 
)

@dataProvider negotiateData

Definition at line 79 of file UtilTest.php.

79 {
80
81 $this->assertEquals(
82 $expected,
83 Util::negotiate($acceptHeader, $available)
84 );
85
86 }
static negotiate($acceptHeaderValue, array $availableOptions)
Deprecated! Use negotiateContentType.
Definition: Util.php:38

References Sabre\HTTP\Util\negotiate().

+ Here is the call graph for this function:

◆ testParseHTTPDate()

Sabre\HTTP\UtilTest::testParseHTTPDate ( )

Definition at line 7 of file UtilTest.php.

7 {
8
9 $times = [
10 'Wed, 13 Oct 2010 10:26:00 GMT',
11 'Wednesday, 13-Oct-10 10:26:00 GMT',
12 'Wed Oct 13 10:26:00 2010',
13 ];
14
15 $expected = 1286965560;
16
17 foreach ($times as $time) {
19 $this->assertEquals($expected, $result->format('U'));
20 }
21
22 $result = Util::parseHTTPDate('Wed Oct 6 10:26:00 2010');
23 $this->assertEquals(1286360760, $result->format('U'));
24
25 }
$result
static parseHTTPDate($dateHeader)
Parses a RFC2616-compatible date string.
Definition: Util.php:53
$time
Definition: cron.php:21

References $result, $time, and Sabre\HTTP\Util\parseHTTPDate().

Referenced by Sabre\HTTP\UtilTest\testTimezones().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testParseHTTPDateFail()

Sabre\HTTP\UtilTest::testParseHTTPDateFail ( )

Definition at line 27 of file UtilTest.php.

27 {
28
29 $times = [
30 //random string
31 'NOW',
32 // not-GMT timezone
33 'Wednesday, 13-Oct-10 10:26:00 UTC',
34 // No space before the 6
35 'Wed Oct 6 10:26:00 2010',
36 // Invalid day
37 'Wed Oct 0 10:26:00 2010',
38 'Wed Oct 32 10:26:00 2010',
39 'Wed, 0 Oct 2010 10:26:00 GMT',
40 'Wed, 32 Oct 2010 10:26:00 GMT',
41 'Wednesday, 32-Oct-10 10:26:00 GMT',
42 // Invalid hour
43 'Wed, 13 Oct 2010 24:26:00 GMT',
44 'Wednesday, 13-Oct-10 24:26:00 GMT',
45 'Wed Oct 13 24:26:00 2010',
46 ];
47
48 foreach ($times as $time) {
49 $this->assertFalse(Util::parseHTTPDate($time), 'We used the string: ' . $time);
50 }
51
52 }

References $time, and Sabre\HTTP\Util\parseHTTPDate().

+ Here is the call graph for this function:

◆ testTimezones()

Sabre\HTTP\UtilTest::testTimezones ( )

Definition at line 54 of file UtilTest.php.

54 {
55
56 $default = date_default_timezone_get();
57 date_default_timezone_set('Europe/Amsterdam');
58
59 $this->testParseHTTPDate();
60
61 date_default_timezone_set($default);
62
63 }
$default
Definition: build.php:20

References $default, and Sabre\HTTP\UtilTest\testParseHTTPDate().

+ Here is the call graph for this function:

◆ testToHTTPDate()

Sabre\HTTP\UtilTest::testToHTTPDate ( )

Definition at line 65 of file UtilTest.php.

65 {
66
67 $dt = new \DateTime('2011-12-10 12:00:00 +0200');
68
69 $this->assertEquals(
70 'Sat, 10 Dec 2011 10:00:00 GMT',
72 );
73
74 }
static toHTTPDate(\DateTime $dateTime)
Transforms a DateTime object to HTTP's most common date format.
Definition: Util.php:69

References Sabre\HTTP\Util\toHTTPDate().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: