- Timestamp:
- 02/24/2017 10:02:48 PM (8 years ago)
- Location:
- branches/4.7
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7
-
branches/4.7/tests/phpunit/tests/rest-api/rest-posts-controller.php
r40114 r40115 1196 1196 1197 1197 $this->assertEquals( $results['date_gmt'], $data['date_gmt'] ); 1198 // TODO expect null here for drafts (see https://core.trac.wordpress.org/ticket/5698#comment:14)1199 1198 $post_date_gmt = str_replace( 'T', ' ', $results['date_gmt'] ); 1200 1199 $this->assertEquals( $post_date_gmt, $post->post_date_gmt ); … … 1295 1294 public function test_create_post_as_contributor() { 1296 1295 wp_set_current_user( self::$contributor_id ); 1297 1298 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1299 $params = $this->set_post_data(array( 1296 update_option( 'timezone_string', 'America/Chicago' ); 1297 1298 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1299 $params = $this->set_post_data( array( 1300 // This results in a special `post_date_gmt` value of 1301 // '0000-00-00 00:00:00'. See #38883. 1300 1302 'status' => 'pending', 1301 )); 1302 1303 $request->set_body_params( $params ); 1304 $response = $this->server->dispatch( $request ); 1303 ) ); 1304 1305 $request->set_body_params( $params ); 1306 $response = $this->server->dispatch( $request ); 1307 $this->assertEquals( 201, $response->get_status() ); 1308 1309 $data = $response->get_data(); 1310 $post = get_post( $data['id'] ); 1311 $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); 1312 $this->assertNotEquals( '0000-00-00T00:00:00', $data['date_gmt'] ); 1313 1305 1314 $this->check_create_post_response( $response ); 1315 1316 update_option( 'timezone_string', '' ); 1306 1317 } 1307 1318 … … 1376 1387 $this->assertEquals( 'draft', $data['status'] ); 1377 1388 $this->assertEquals( 'draft', $new_post->post_status ); 1378 // Confirm dates are null 1379 $this->assertNull( $data['date_gmt'] ); 1380 $this->assertNull( $data['modified_gmt'] ); 1389 // Confirm dates are shimmed for gmt_offset 1390 $post_modified_gmt = date( 'Y-m-d H:i:s', strtotime( $new_post->post_modified ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 1391 $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $new_post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 1392 1393 $this->assertEquals( mysql_to_rfc3339( $post_modified_gmt ), $data['modified_gmt'] ); 1394 $this->assertEquals( mysql_to_rfc3339( $post_date_gmt ), $data['date_gmt'] ); 1381 1395 } 1382 1396 … … 2063 2077 2064 2078 $this->assertEquals( $results['date_gmt'], $data['date_gmt'] ); 2065 // TODO expect null here for drafts (see https://core.trac.wordpress.org/ticket/5698#comment:14)2066 2079 $post_date_gmt = str_replace( 'T', ' ', $results['date_gmt'] ); 2067 2080 $this->assertEquals( $post_date_gmt, $post->post_date_gmt ); … … 2092 2105 2093 2106 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 2107 } 2108 2109 public function test_empty_post_date_gmt_shimmed_using_post_date() { 2110 global $wpdb; 2111 2112 wp_set_current_user( self::$editor_id ); 2113 update_option( 'timezone_string', 'America/Chicago' ); 2114 2115 // Need to set dates using wpdb directly because `wp_update_post` and 2116 // `wp_insert_post` have additional validation on dates. 2117 $post_id = $this->factory->post->create(); 2118 $wpdb->update( 2119 $wpdb->posts, 2120 array( 2121 'post_date' => '2016-02-23 12:00:00', 2122 'post_date_gmt' => '0000-00-00 00:00:00', 2123 ), 2124 array( 2125 'ID' => $post_id, 2126 ), 2127 array( '%s', '%s' ), 2128 array( '%d' ) 2129 ); 2130 wp_cache_delete( $post_id, 'posts' ); 2131 2132 $post = get_post( $post_id ); 2133 $this->assertEquals( $post->post_date, '2016-02-23 12:00:00' ); 2134 $this->assertEquals( $post->post_date_gmt, '0000-00-00 00:00:00' ); 2135 2136 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2137 $response = $this->server->dispatch( $request ); 2138 $this->assertEquals( 200, $response->get_status() ); 2139 $data = $response->get_data(); 2140 2141 $this->assertEquals( '2016-02-23T12:00:00', $data['date'] ); 2142 $this->assertEquals( '2016-02-23T18:00:00', $data['date_gmt'] ); 2143 2144 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2145 $request->set_param( 'date', '2016-02-23T13:00:00' ); 2146 $response = $this->server->dispatch( $request ); 2147 $this->assertEquals( 200, $response->get_status() ); 2148 $data = $response->get_data(); 2149 2150 $this->assertEquals( '2016-02-23T13:00:00', $data['date'] ); 2151 $this->assertEquals( '2016-02-23T19:00:00', $data['date_gmt'] ); 2152 2153 $post = get_post( $post_id ); 2154 $this->assertEquals( $post->post_date, '2016-02-23 13:00:00' ); 2155 $this->assertEquals( $post->post_date_gmt, '2016-02-23 19:00:00' ); 2156 2157 update_option( 'timezone_string', '' ); 2094 2158 } 2095 2159
Note: See TracChangeset
for help on using the changeset viewer.