Move HttpAcceptNegotiator and HttpAcceptParser from Wikibase to core
[lhc/web/wiklou.git] / tests / phpunit / includes / http / HttpAcceptParserTest.php
1 <?php
2
3 use MediaWiki\Http\HttpAcceptParser;
4
5 /**
6 * @covers MediaWiki\Http\HttpAcceptParser
7 *
8 * @license GPL-2.0+
9 * @author Daniel Kinzler
10 */
11 class HttpAcceptParserTest extends \PHPUnit_Framework_TestCase {
12
13 public function provideParseWeights() {
14 return [
15 [ // #0
16 '',
17 []
18 ],
19 [ // #1
20 'Foo/Bar',
21 [ 'foo/bar' => 1 ]
22 ],
23 [ // #2
24 'Accept: text/plain',
25 [ 'text/plain' => 1 ]
26 ],
27 [ // #3
28 'Accept: application/vnd.php.serialized, application/rdf+xml',
29 [ 'application/vnd.php.serialized' => 1, 'application/rdf+xml' => 1 ]
30 ],
31 [ // #4
32 'foo; q=0.2, xoo; q=0,text/n3',
33 [ 'text/n3' => 1, 'foo' => 0.2 ]
34 ],
35 [ // #5
36 '*; q=0.2, */*; q=0.1,text/*',
37 [ 'text/*' => 1, '*' => 0.2, '*/*' => 0.1 ]
38 ],
39 // TODO: nicely ignore additional type paramerters
40 //[ // #6
41 // 'Foo; q=0.2, Xoo; level=3, Bar; charset=xyz; q=0.4',
42 // [ 'xoo' => 1, 'bar' => 0.4, 'foo' => 0.1 ]
43 //],
44 ];
45 }
46
47 /**
48 * @dataProvider provideParseWeights
49 */
50 public function testParseWeights( $header, $expected ) {
51 $parser = new HttpAcceptParser();
52 $actual = $parser->parseWeights( $header );
53
54 $this->assertEquals( $expected, $actual ); // shouldn't be sensitive to order
55 }
56
57 }