Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Rest\HeaderParser;
4
5 use MediaWiki\Rest\HeaderParser\HttpDate;
6 use MediaWikiUnitTestCase;
7
8 /**
9 * @covers \MediaWiki\Rest\HeaderParser\HttpDate
10 */
11 class HttpDateTest extends MediaWikiUnitTestCase {
12 public static function provideParse() {
13 return [
14 'RFC 7231 example 1' => [
15 'Sun, 06 Nov 1994 08:49:37 GMT',
16 784111777
17 ],
18 'RFC 7231 example 2' => [
19 'Sunday, 06-Nov-94 08:49:37 GMT',
20 784111777
21 ],
22 'RFC 7231 example 3' => [
23 'Sun Nov 6 08:49:37 1994',
24 784111777
25 ],
26 'asctime whitespace nitpick' => [
27 'Sun Nov 6 08:49:37 1994',
28 null
29 ],
30 'PHP "r" format' => [
31 'Sun, 06 Nov 1994 08:49:37 +0000',
32 null
33 ],
34 'RFC 7231 example 1 with trail' => [
35 'Sun, 06 Nov 1994 08:49:37 GMT.',
36 null
37 ],
38 'RFC 7231 example 2 with trail' => [
39 'Sunday, 06-Nov-94 08:49:37 GMT.',
40 null
41 ],
42 'RFC 7231 example 3 with trail' => [
43 'Sun Nov 6 08:49:37 1994.',
44 null
45 ],
46 ];
47 }
48
49 /**
50 * @dataProvider provideParse
51 * @param string $input
52 * @param string|null $expected
53 */
54 public function testParse( $input, $expected ) {
55 $result = HttpDate::parse( $input );
56 $this->assertSame( $expected, $result );
57 }
58
59 public static function provideFormatRoundtrip() {
60 for ( $ts = 1000000000; $ts < 2000000000; $ts += 100000000 ) {
61 yield [ $ts ];
62 }
63 }
64
65 /**
66 * @dataProvider provideFormatRoundtrip
67 */
68 public function testFormatRoundtrip( $ts ) {
69 $this->assertSame( $ts, HttpDate::parse( HttpDate::format( $ts ) ) );
70 }
71 }