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