Date/Time: Use strict comparison in `is_new_day()`, add a unit test.

Props pbearne.
Fixes #46627.

git-svn-id: https://develop.svn.wordpress.org/trunk@45375 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-05-22 17:52:22 +00:00
parent f9e4f60577
commit 6491746559
2 changed files with 38 additions and 1 deletions

View File

@ -797,7 +797,8 @@ function wp_get_http_headers( $url, $deprecated = false ) {
*/
function is_new_day() {
global $currentday, $previousday;
if ( $currentday != $previousday ) {
if ( $currentday !== $previousday ) {
return 1;
} else {
return 0;

View File

@ -0,0 +1,36 @@
<?php
/**
* Test is_new_date() function.
*
* @since 5.2.0
*
* @group functions.php
*/
class Tests_Functions_is_new_date extends WP_UnitTestCase {
/**
* @ticket 46627
* @dataProvider _data_is_new_date
*
* @param string $currentday_string The day of the current post in the loop.
* @param string $previousday_string The day of the previous post in the loop.
* @param bool $expected Expected result.
*/
public function test_is_new_date( $currentday_string, $previousday_string, $expected ) {
global $currentday, $previousday;
$currentday = $currentday_string;
$previousday = $previousday_string;
$this->assertSame( $expected, is_new_day() );
}
public function _data_is_new_date() {
return array(
array( '21.05.19', '21.05.19', 0 ),
array( '21.05.19', '20.05.19', 1 ),
array( '21.05.19', false, 1 ),
);
}
}