Make WordPress Core

Ticket #15946: 15946.2.diff

File 15946.2.diff, 2.2 KB (added by oso96_2000, 12 years ago)

Refreshed patch with unit test

  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 5ef96b3..fe4c0e9 100644
    function wp_insert_post( $postarr, $wp_error = false ) { 
    28172817        }
    28182818
    28192819        // If the post date is empty (due to having been new or a draft) and status is not 'draft' or 'pending', set date to now
    2820         if ( empty($post_date) || '0000-00-00 00:00:00' == $post_date )
    2821                 $post_date = current_time('mysql');
     2820        if ( empty($post_date) || '0000-00-00 00:00:00' == $post_date ) {
     2821                if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt )
     2822                        $post_date = current_time('mysql');
     2823                else
     2824                        $post_date = get_date_from_gmt($post_date_gmt);
     2825        }
    28222826
    28232827                // validate the date
    28242828                $mm = substr( $post_date, 5, 2 );
    function wp_insert_post( $postarr, $wp_error = false ) { 
    28392843                        $post_date_gmt = '0000-00-00 00:00:00';
    28402844        }
    28412845
    2842         if ( $update || '0000-00-00 00:00:00' == $post_date ) {
     2846        if ( $update ) {
    28432847                $post_modified     = current_time( 'mysql' );
    28442848                $post_modified_gmt = current_time( 'mysql', 1 );
    28452849        } else {
  • tests/phpunit/tests/post.php

    diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
    index e8074e9..a675b03 100644
    class Tests_Post extends WP_UnitTestCase { 
    865865                $this->assertEquals( 9, $after_trash_counts->publish );
    866866                $this->assertNotEquals( $initial_counts->publish, $after_trash_counts->publish );
    867867        }
     868
     869        function test_wp_insert_post_should_respect_post_date_gmt() {
     870                $post = array(
     871                        'post_author' => $this->author_id,
     872                        'post_status' => 'publish',
     873                        'post_content' => rand_str(),
     874                        'post_title' => rand_str(),
     875                        'post_date_gmt' => '2014-01-01 12:00:00',
     876                );
     877
     878                // insert a post and make sure the ID is ok
     879                $id = wp_insert_post($post);
     880
     881                $out = get_post($id);
     882
     883                $this->assertEquals($post['post_content'], $out->post_content);
     884                $this->assertEquals($post['post_title'], $out->post_title);
     885                $this->assertEquals($post['post_author'], $out->post_author);
     886                $this->assertEquals(get_date_from_gmt($post['post_date_gmt']), $out->post_date);
     887                $this->assertEquals($post['post_date_gmt'], $out->post_date_gmt);
     888        }
    868889}