forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpCheckdate.php
More file actions
67 lines (61 loc) · 2.04 KB
/
wpCheckdate.php
File metadata and controls
67 lines (61 loc) · 2.04 KB
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
<?php
/**
* Tests for the wp_checkdate() function.
*
* @group date
* @group datetime
* @group functions
*
* @covers ::wp_checkdate
*/
class Tests_Date_wpCheckdate extends WP_UnitTestCase {
/**
* @ticket 59825
*
* @dataProvider data_wp_checkdate
*
* @param int|string $month The month to check.
* @param int|string $day The day to check.
* @param int|string $year The year to check.
* @param string $source_date The date to pass to the wp_checkdate filter.
* @param bool $expected The expected result.
*/
public function test_wp_checkdate( $month, $day, $year, $source_date, $expected ) {
$this->assertSame( $expected, wp_checkdate( $month, $day, $year, $source_date ) );
}
/**
* Data provider for test_wp_checkdate().
*
* @return array
*/
public function data_wp_checkdate() {
return array(
'integers' => array( 1, 1, 1, '1-1-1', true ),
'strings' => array( '1', '1', '1', '1-1-1', true ),
'arbitrary source_date' => array( 1, 1, 1, 'arbitrary source_date', true ), // source_date is only used by the filter.
'valid day' => array( 2, 29, 2024, '2/29/2024', true ), // 2024 is a leap year.
'invalid day' => array( 2, 29, 2023, '2/29/2023', false ), // 2023 is not a leap year.
'invalid month' => array( 99, 1, 1, '1-1-1', false ), // Month must be between 1 and 12.
'invalid year' => array( 1, 1, 0, '1-1-0', false ), // Year must be between 1 and 32767.
);
}
/**
* Checks that the filter overrides the return value.
*/
public function test_wp_checkdate_filter() {
add_filter(
'wp_checkdate',
static function ( $is_valid_date, $source_date ) {
if ( '2/29/2023' === $source_date ) {
// Date is invalid, but return true anyway.
return true;
}
return $is_valid_date;
},
10,
2
);
// Test with an invalid date that the filter will return as valid.
$this->assertTrue( wp_checkdate( '2', '29', '2023', '2/29/2023' ) );
}
}