summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/libs/http/HttpAcceptParserTest.php
blob: e4b47b46d57f826f40a594efec7304a38b57d55d (plain)
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
<?php

use Wikimedia\Http\HttpAcceptParser;

/**
 * @covers Wikimedia\Http\HttpAcceptParser
 *
 * @author Daniel Kinzler
 */
class HttpAcceptParserTest extends \PHPUnit\Framework\TestCase {

	public function provideParseWeights() {
		return [
			[ // #0
				'',
				[]
			],
			[ // #1
				'Foo/Bar',
				[ 'foo/bar' => 1 ]
			],
			[ // #2
				'Accept: text/plain',
				[ 'text/plain' => 1 ]
			],
			[ // #3
				'Accept: application/vnd.php.serialized, application/rdf+xml',
				[ 'application/vnd.php.serialized' => 1, 'application/rdf+xml' => 1 ]
			],
			[ // #4
				'foo; q=0.2, xoo; q=0,text/n3',
				[ 'text/n3' => 1, 'foo' => 0.2 ]
			],
			[ // #5
				'*; q=0.2, */*; q=0.1,text/*',
				[ 'text/*' => 1, '*' => 0.2, '*/*' => 0.1 ]
			],
			// TODO: nicely ignore additional type paramerters
			//[ // #6
			//	'Foo; q=0.2, Xoo; level=3, Bar; charset=xyz; q=0.4',
			//	[ 'xoo' => 1, 'bar' => 0.4, 'foo' => 0.1 ]
			//],
		];
	}

	/**
	 * @dataProvider provideParseWeights
	 */
	public function testParseWeights( $header, $expected ) {
		$parser = new HttpAcceptParser();
		$actual = $parser->parseWeights( $header );

		$this->assertEquals( $expected, $actual ); // shouldn't be sensitive to order
	}

}