File: HttpDateTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (71 lines) | stat: -rw-r--r-- 1,534 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

namespace MediaWiki\Tests\Rest\HeaderParser;

use MediaWiki\Rest\HeaderParser\HttpDate;
use MediaWikiUnitTestCase;

/**
 * @covers \MediaWiki\Rest\HeaderParser\HttpDate
 */
class HttpDateTest extends MediaWikiUnitTestCase {
	public static function provideParse() {
		return [
			'RFC 7231 example 1' => [
				'Sun, 06 Nov 1994 08:49:37 GMT',
				784111777
			],
			'RFC 7231 example 2' => [
				'Sunday, 06-Nov-94 08:49:37 GMT',
				784111777
			],
			'RFC 7231 example 3' => [
				'Sun Nov  6 08:49:37 1994',
				784111777
			],
			'asctime whitespace nitpick' => [
				'Sun Nov 6 08:49:37 1994',
				null
			],
			'PHP "r" format' => [
				'Sun, 06 Nov 1994 08:49:37 +0000',
				null
			],
			'RFC 7231 example 1 with trail' => [
				'Sun, 06 Nov 1994 08:49:37 GMT.',
				null
			],
			'RFC 7231 example 2 with trail' => [
				'Sunday, 06-Nov-94 08:49:37 GMT.',
				null
			],
			'RFC 7231 example 3 with trail' => [
				'Sun Nov  6 08:49:37 1994.',
				null
			],
		];
	}

	/**
	 * @dataProvider provideParse
	 * @param string $input
	 * @param string|null $expected
	 */
	public function testParse( $input, $expected ) {
		$result = HttpDate::parse( $input );
		$this->assertSame( $expected, $result );
	}

	public static function provideFormatRoundtrip() {
		for ( $ts = 1000000000; $ts < 2000000000; $ts += 100000000 ) {
			yield [ $ts ];
		}
	}

	/**
	 * @dataProvider provideFormatRoundtrip
	 */
	public function testFormatRoundtrip( $ts ) {
		$this->assertSame( $ts, HttpDate::parse( HttpDate::format( $ts ) ) );
	}
}