Debian Codegraph @

tests/phpunit/unit/includes/Rest/HeaderParser/IfNoneMatchTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Rest\HeaderParser;
4
5 use MediaWiki\Rest\HeaderParser\IfNoneMatch;
6 use MediaWikiUnitTestCase;
7
8 /**
9 * @covers \MediaWiki\Rest\HeaderParser\IfNoneMatch
10 */
11 class IfNoneMatchTest extends MediaWikiUnitTestCase {
12 public static function provideParseHeaderList() {
13 return [
14 'empty array' => [
15 [],
16 []
17 ],
18 'star' => [
19 [ '*' ],
20 [ [ 'weak' => true, 'contents' => null, 'whole' => '*' ] ]
21 ],
22 'etag' => [
23 [ '"x"' ],
24 [ [ 'weak' => false, 'contents' => 'x', 'whole' => '"x"' ] ]
25 ],
26 'star etag' => [
27 [ '*, "x"' ],
28 []
29 ],
30 'etag star' => [
31 [ '"x", *' ],
32 []
33 ],
34 'two in a string' => [
35 [ '"x","y"' ],
36 [
37 [ 'weak' => false, 'contents' => 'x', 'whole' => '"x"' ],
38 [ 'weak' => false, 'contents' => 'y', 'whole' => '"y"' ]
39 ]
40 ],
41 'two with whitespace' => [
42 [ "\"x\"\t, \"y\"" ],
43 [
44 [ 'weak' => false, 'contents' => 'x', 'whole' => '"x"' ],
45 [ 'weak' => false, 'contents' => 'y', 'whole' => '"y"' ]
46 ]
47 ],
48 'two separate headers' => [
49 [ '"x"', '"y"' ],
50 [
51 [ 'weak' => false, 'contents' => 'x', 'whole' => '"x"' ],
52 [ 'weak' => false, 'contents' => 'y', 'whole' => '"y"' ]
53 ]
54 ],
55 'trailing comma' => [
56 [ '"x",' ],
57 []
58 ],
59 'trailing garbage' => [
60 [ '"x",asdfg' ],
61 []
62 ]
63 ];
64 }
65
66 /**
67 * @dataProvider provideParseHeaderList
68 * @param array $input
69 * @param array $expected
70 */
71 public function testParseHeaderList( $input, $expected ) {
72 $parser = new IfNoneMatch;
73 $actual = $parser->parseHeaderList( $input );
74 $this->assertSame( $expected, $actual );
75 }
76
77 public static function provideParseETag() {
78 return [
79 'empty' => [
80 '',
81 null
82 ],
83 'strong' => [
84 '"x"',
85 [ 'weak' => false, 'contents' => 'x', 'whole' => '"x"' ]
86 ],
87 'weak' => [
88 'W/"x"',
89 [ 'weak' => true, 'contents' => 'x', 'whole' => 'W/"x"' ]
90 ],
91 'weak with lowercase w' => [
92 'w/"x"',
93 null
94 ],
95 'quoted character outside valid range' => [
96 '" "',
97 null
98 ],
99 'trailing garbage' => [
100 '"x"a',
101 null
102 ]
103 ];
104 }
105
106 /**
107 * @dataProvider provideParseETag
108 */
109 public function testParseETag( $input, $expected ) {
110 $parser = new IfNoneMatch;
111 $actual = $parser->parseETag( $input );
112 $this->assertSame( $expected, $actual );
113 }
114 }