MediaWiki REL1_31
XMPValidateTest.php
Go to the documentation of this file.
1<?php
2
3use Psr\Log\NullLogger;
4
8class XMPValidateTest extends PHPUnit\Framework\TestCase {
9
10 use MediaWikiCoversValidator;
11
16 public function testValidateDate( $value, $expected ) {
17 // The method should modify $value.
18 $validate = new XMPValidate( new NullLogger() );
19 $validate->validateDate( [], $value, true );
20 $this->assertEquals( $expected, $value );
21 }
22
23 public static function provideDates() {
24 /* For reference valid date formats are:
25 * YYYY
26 * YYYY-MM
27 * YYYY-MM-DD
28 * YYYY-MM-DDThh:mmTZD
29 * YYYY-MM-DDThh:mm:ssTZD
30 * YYYY-MM-DDThh:mm:ss.sTZD
31 * (Time zone is optional)
32 */
33 return [
34 [ '1992', '1992' ],
35 [ '1992-04', '1992:04' ],
36 [ '1992-02-01', '1992:02:01' ],
37 [ '2011-09-29', '2011:09:29' ],
38 [ '1982-12-15T20:12', '1982:12:15 20:12' ],
39 [ '1982-12-15T20:12Z', '1982:12:15 20:12' ],
40 [ '1982-12-15T20:12+02:30', '1982:12:15 22:42' ],
41 [ '1982-12-15T01:12-02:30', '1982:12:14 22:42' ],
42 [ '1982-12-15T20:12:11', '1982:12:15 20:12:11' ],
43 [ '1982-12-15T20:12:11Z', '1982:12:15 20:12:11' ],
44 [ '1982-12-15T20:12:11+01:10', '1982:12:15 21:22:11' ],
45 [ '2045-12-15T20:12:11', '2045:12:15 20:12:11' ],
46 [ '1867-06-01T15:00:00', '1867:06:01 15:00:00' ],
47 /* some invalid ones */
48 [ '2001--12', null ],
49 [ '2001-5-12', null ],
50 [ '2001-5-12TZ', null ],
51 [ '2001-05-12T15', null ],
52 [ '2001-12T15:13', null ],
53 ];
54 }
55}
testValidateDate( $value, $expected)
provideDates XMPValidate::validateDate
This contains some static methods for validating XMP properties.