Make WordPress Core

Ticket #39256: 39256.diff

File 39256.diff, 5.4 KB (added by jnylen0, 8 years ago)

Test cases for setting post dates during create and update (12/20 failing)

  • tests/phpunit/tests/rest-api/rest-posts-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
    index 62d2a62..639d0c4 100644
    a b class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    10691069                $this->check_create_post_response( $response );
    10701070        }
    10711071
     1072        public static function post_status_provider_for_dates() {
     1073                return array(
     1074                        array( 'draft' ),
     1075                        array( 'publish' ),
     1076                        array( 'future' ),
     1077                        array( 'pending' ),
     1078                        array( 'private' ),
     1079                );
     1080        }
     1081
     1082        /**
     1083         * @dataProvider post_status_provider_for_dates
     1084         */
     1085        public function test_create_post_date( $status ) {
     1086                wp_set_current_user( self::$editor_id );
     1087                update_option( 'timezone_string', 'America/New_York' );
     1088
     1089                $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     1090                $request->set_param( 'title', 'not empty' );
     1091                $request->set_param( 'date', '2016-12-12T14:00:00' );
     1092                $response = $this->server->dispatch( $request );
     1093
     1094                update_option( 'timezone_string', '' );
     1095
     1096                $this->assertEquals( 201, $response->get_status() );
     1097                $data = $response->get_data();
     1098                $post_id = $data['id'];
     1099                $post = get_post( $post_id );
     1100
     1101                $this->assertEquals( '2016-12-12T14:00:00', $data['date'] );
     1102                $time = gmmktime( 14, 0, 0, 12, 12, 2016 );
     1103                $this->assertEquals( $time, strtotime( $post->post_date ) );
     1104
     1105                $this->assertEquals( '2016-12-12T19:00:00', $data['date_gmt'] );
     1106                // TODO expect null here for drafts (see https://core.trac.wordpress.org/ticket/5698#comment:14)
     1107                $time_gmt = gmmktime( 19, 0, 0, 12, 12, 2016 );
     1108                $this->assertEquals( $time_gmt, strtotime( $post->post_date_gmt ) );
     1109        }
     1110
     1111        /**
     1112         * @dataProvider post_status_provider_for_dates
     1113         */
     1114        public function test_create_post_date_gmt( $status ) {
     1115                wp_set_current_user( self::$editor_id );
     1116                update_option( 'timezone_string', 'America/New_York' );
     1117
     1118                $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     1119                $request->set_param( 'title', 'not empty' );
     1120                $request->set_param( 'date_gmt', '2016-12-12T19:10:00' );
     1121                $response = $this->server->dispatch( $request );
     1122
     1123                update_option( 'timezone_string', '' );
     1124
     1125                $this->assertEquals( 201, $response->get_status() );
     1126                $data = $response->get_data();
     1127                $post_id = $data['id'];
     1128                $post = get_post( $post_id );
     1129
     1130                $this->assertEquals( '2016-12-12T14:10:00', $data['date'] );
     1131                $time = gmmktime( 14, 10, 0, 12, 12, 2016 );
     1132                $this->assertEquals( $time, strtotime( $post->post_date ) );
     1133
     1134                $this->assertEquals( '2016-12-12T19:10:00', $data['date_gmt'] );
     1135                // TODO expect null here for drafts (see https://core.trac.wordpress.org/ticket/5698#comment:14)
     1136                $time_gmt = gmmktime( 19, 10, 0, 12, 12, 2016 );
     1137                $this->assertEquals( $time_gmt, strtotime( $post->post_date_gmt ) );
     1138        }
     1139
    10721140        /**
    10731141         * @ticket 38698
    10741142         */
    class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    19051973                $this->assertEquals( date( 'Y-m-d', strtotime( $expected_modified ) ), date( 'Y-m-d', strtotime( $new_post->post_modified ) ) );
    19061974        }
    19071975
     1976        /**
     1977         * @dataProvider post_status_provider_for_dates
     1978         */
     1979        public function test_update_post_date( $status ) {
     1980                wp_set_current_user( self::$editor_id );
     1981                update_option( 'timezone_string', 'America/New_York' );
     1982
     1983                $post_id = $this->factory->post->create( array( 'post_status' => $status ) );
     1984
     1985                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) );
     1986                $request->set_param( 'date', '2016-12-12T14:00:00' );
     1987                $response = $this->server->dispatch( $request );
     1988
     1989                update_option( 'timezone_string', '' );
     1990
     1991                $this->assertEquals( 200, $response->get_status() );
     1992                $data = $response->get_data();
     1993                $post = get_post( $post_id );
     1994
     1995                $this->assertEquals( '2016-12-12T14:00:00', $data['date'] );
     1996                $time = gmmktime( 14, 0, 0, 12, 12, 2016 );
     1997                $this->assertEquals( $time, strtotime( $post->post_date ) );
     1998
     1999                $this->assertEquals( '2016-12-12T19:00:00', $data['date_gmt'] );
     2000                // TODO expect null here for drafts (see https://core.trac.wordpress.org/ticket/5698#comment:14)
     2001                $time_gmt = gmmktime( 19, 0, 0, 12, 12, 2016 );
     2002                $this->assertEquals( $time_gmt, strtotime( $post->post_date_gmt ) );
     2003        }
     2004
     2005        /**
     2006         * @dataProvider post_status_provider_for_dates
     2007         */
     2008        public function test_update_post_date_gmt( $status ) {
     2009                wp_set_current_user( self::$editor_id );
     2010                update_option( 'timezone_string', 'America/New_York' );
     2011
     2012                $post_id = $this->factory->post->create( array( 'post_status' => $status ) );
     2013
     2014                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) );
     2015                $request->set_param( 'date_gmt', '2016-12-12T19:10:00' );
     2016                $response = $this->server->dispatch( $request );
     2017
     2018                update_option( 'timezone_string', '' );
     2019
     2020                $this->assertEquals( 200, $response->get_status() );
     2021                $data = $response->get_data();
     2022                $post = get_post( $post_id );
     2023
     2024                $this->assertEquals( '2016-12-12T14:10:00', $data['date'] );
     2025                $time = gmmktime( 14, 10, 0, 12, 12, 2016 );
     2026                $this->assertEquals( $time, strtotime( $post->post_date ) );
     2027
     2028                $this->assertEquals( '2016-12-12T19:10:00', $data['date_gmt'] );
     2029                // TODO expect null here for drafts (see https://core.trac.wordpress.org/ticket/5698#comment:14)
     2030                $time_gmt = gmmktime( 19, 10, 0, 12, 12, 2016 );
     2031                $this->assertEquals( $time_gmt, strtotime( $post->post_date_gmt ) );
     2032        }
     2033
    19082034        public function test_update_post_with_invalid_date() {
    19092035                wp_set_current_user( self::$editor_id );
    19102036