Make WordPress Core

Ticket #46627: 46627.patch

File 46627.patch, 1.4 KB (added by pbearne, 6 years ago)

patch with unit test

  • src/wp-includes/functions.php

     
    797797 */
    798798function is_new_day() {
    799799        global $currentday, $previousday;
    800         if ( $currentday != $previousday ) {
     800        if ( $currentday !== $previousday ) {
    801801                return 1;
    802802        } else {
    803803                return 0;
  • tests/phpunit/tests/functions/isNewDay.php

     
     1<?php
     2/**
     3 * Tests is_new_date function
     4 *
     5 * @since 5.2.0
     6 *
     7 * @group functions.php
     8 */
     9class Tests_Functions_is_new_date extends WP_UnitTestCase {
     10
     11        public function _date_strings(){
     12
     13                return array(
     14                        array( 'same', 'same', true ),
     15                        array( 'same', 'diff', false ),
     16                        array( 'false', false, false ), // this should not be true
     17                );
     18        }
     19
     20
     21        /**
     22         * @dataProvider _date_strings
     23         *
     24         * @param string $currentday
     25         * @param string $previousday
     26         * @param bool $expected
     27         */
     28        public function test_is_new_date( $currentday_string,$previousday_string , $expected ) {
     29                global $currentday, $previousday;
     30
     31                $currentday = $currentday_string;
     32                $previousday = $previousday_string;
     33
     34                $this->assertSame( is_new_day(), $expected );
     35        }
     36
     37}