Make WordPress Core


Ignore:
Timestamp:
11/07/2025 02:59:09 AM (3 months ago)
Author:
wildworks
Message:

Tests: Fix failing malformed date test

Dates without leading zeros (e.g., 2012-1-08, 2012-01-8) are now correctly recognized as valid dates. This change fixes the test cases to correctly reflect that these formats are valid and fixes an undefined variable reference.

Follow-up to [61172].

Props wildworks, westonruter.
Fixes #26798.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r61172 r61173  
    827827    public function test_wp_insert_post_handle_malformed_post_date( $input, $expected ) {
    828828        $post = array(
    829             'post_author'  => self::$editor_id,
     829            'post_author'  => self::$user_ids['editor'],
    830830            'post_status'  => 'publish',
    831831            'post_content' => 'content',
     
    894894                true,
    895895            ),
     896            // Dates without leading zeros (valid but malformed format).
     897            array(
     898                '2012-08-1',
     899                true,
     900            ),
     901            array(
     902                '2012-1-08 00:00:00',
     903                true,
     904            ),
     905            array(
     906                '2012-01-8 00:00:00',
     907                true,
     908            ),
    896909            // Failures.
    897910            array(
     
    900913            ),
    901914            array(
    902                 '2012-08-1',
    903                 false,
    904             ),
    905             array(
    906915                '201-01-08 00:00:00',
    907916                false,
     
    916925            ),
    917926            array(
    918                 '2012-1-08 00:00:00',
    919                 false,
    920             ),
    921             array(
    922927                '2012-31-08 00:00:00',
    923                 false,
    924             ),
    925             array(
    926                 '2012-01-8 00:00:00',
    927928                false,
    928929            ),
     
    10171018                '2012-01-01 00:00:60',
    10181019            ),
     1020            // Dates without leading zeros (valid but malformed format).
     1021            array(
     1022                '2012-1-08',
     1023                '2012-1-08',
     1024            ),
     1025            array(
     1026                '2012-01-8',
     1027                '2012-01-8',
     1028            ),
    10191029            array(
    10201030                '201-01-08',
     
    10261036            ),
    10271037            array(
    1028                 '2012-1-08',
    1029                 false,
    1030             ),
    1031             array(
    10321038                '2012-31-08',
    1033                 false,
    1034             ),
    1035             array(
    1036                 '2012-01-8',
    10371039                false,
    10381040            ),
Note: See TracChangeset for help on using the changeset viewer.