- Timestamp:
- 02/24/2017 09:58:07 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
r39957 r40114 1097 1097 } 1098 1098 1099 public function post_dates_provider() { 1100 $all_statuses = array( 1101 'draft', 1102 'publish', 1103 'future', 1104 'pending', 1105 'private', 1106 ); 1107 1108 $cases_short = array( 1109 'set date without timezone' => array( 1110 'statuses' => $all_statuses, 1111 'params' => array( 1112 'timezone_string' => 'America/New_York', 1113 'date' => '2016-12-12T14:00:00', 1114 ), 1115 'results' => array( 1116 'date' => '2016-12-12T14:00:00', 1117 'date_gmt' => '2016-12-12T19:00:00', 1118 ), 1119 ), 1120 'set date_gmt without timezone' => array( 1121 'statuses' => $all_statuses, 1122 'params' => array( 1123 'timezone_string' => 'America/New_York', 1124 'date_gmt' => '2016-12-12T19:00:00', 1125 ), 1126 'results' => array( 1127 'date' => '2016-12-12T14:00:00', 1128 'date_gmt' => '2016-12-12T19:00:00', 1129 ), 1130 ), 1131 'set date with timezone' => array( 1132 'statuses' => array( 'draft', 'publish' ), 1133 'params' => array( 1134 'timezone_string' => 'America/New_York', 1135 'date' => '2016-12-12T18:00:00-01:00', 1136 ), 1137 'results' => array( 1138 'date' => '2016-12-12T14:00:00', 1139 'date_gmt' => '2016-12-12T19:00:00', 1140 ), 1141 ), 1142 'set date_gmt with timezone' => array( 1143 'statuses' => array( 'draft', 'publish' ), 1144 'params' => array( 1145 'timezone_string' => 'America/New_York', 1146 'date_gmt' => '2016-12-12T18:00:00-01:00', 1147 ), 1148 'results' => array( 1149 'date' => '2016-12-12T14:00:00', 1150 'date_gmt' => '2016-12-12T19:00:00', 1151 ), 1152 ), 1153 ); 1154 1155 $cases = array(); 1156 foreach ( $cases_short as $description => $case ) { 1157 foreach ( $case['statuses'] as $status ) { 1158 $cases[ $description . ', status=' . $status ] = array( 1159 $status, 1160 $case['params'], 1161 $case['results'], 1162 ); 1163 } 1164 } 1165 1166 return $cases; 1167 } 1168 1169 /** 1170 * @dataProvider post_dates_provider 1171 */ 1172 public function test_create_post_date( $status, $params, $results ) { 1173 wp_set_current_user( self::$editor_id ); 1174 update_option( 'timezone_string', $params['timezone_string'] ); 1175 1176 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1177 $request->set_param( 'status', $status ); 1178 $request->set_param( 'title', 'not empty' ); 1179 if ( isset( $params['date'] ) ) { 1180 $request->set_param( 'date', $params['date'] ); 1181 } 1182 if ( isset( $params['date_gmt'] ) ) { 1183 $request->set_param( 'date_gmt', $params['date_gmt'] ); 1184 } 1185 $response = $this->server->dispatch( $request ); 1186 1187 update_option( 'timezone_string', '' ); 1188 1189 $this->assertEquals( 201, $response->get_status() ); 1190 $data = $response->get_data(); 1191 $post = get_post( $data['id'] ); 1192 1193 $this->assertEquals( $results['date'], $data['date'] ); 1194 $post_date = str_replace( 'T', ' ', $results['date'] ); 1195 $this->assertEquals( $post_date, $post->post_date ); 1196 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 $post_date_gmt = str_replace( 'T', ' ', $results['date_gmt'] ); 1200 $this->assertEquals( $post_date_gmt, $post->post_date_gmt ); 1201 } 1202 1099 1203 /** 1100 1204 * @ticket 38698 … … 1928 2032 $this->assertEquals( date( 'Y-m-d', strtotime( mysql_to_rfc3339( $expected_modified ) ) ), date( 'Y-m-d', strtotime( $data['modified'] ) ) ); 1929 2033 $this->assertEquals( date( 'Y-m-d', strtotime( $expected_modified ) ), date( 'Y-m-d', strtotime( $new_post->post_modified ) ) ); 2034 } 2035 2036 /** 2037 * @dataProvider post_dates_provider 2038 */ 2039 public function test_update_post_date( $status, $params, $results ) { 2040 wp_set_current_user( self::$editor_id ); 2041 update_option( 'timezone_string', $params['timezone_string'] ); 2042 2043 $post_id = $this->factory->post->create( array( 'post_status' => $status ) ); 2044 2045 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2046 if ( isset( $params['date'] ) ) { 2047 $request->set_param( 'date', $params['date'] ); 2048 } 2049 if ( isset( $params['date_gmt'] ) ) { 2050 $request->set_param( 'date_gmt', $params['date_gmt'] ); 2051 } 2052 $response = $this->server->dispatch( $request ); 2053 2054 update_option( 'timezone_string', '' ); 2055 2056 $this->assertEquals( 200, $response->get_status() ); 2057 $data = $response->get_data(); 2058 $post = get_post( $data['id'] ); 2059 2060 $this->assertEquals( $results['date'], $data['date'] ); 2061 $post_date = str_replace( 'T', ' ', $results['date'] ); 2062 $this->assertEquals( $post_date, $post->post_date ); 2063 2064 $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 $post_date_gmt = str_replace( 'T', ' ', $results['date_gmt'] ); 2067 $this->assertEquals( $post_date_gmt, $post->post_date_gmt ); 1930 2068 } 1931 2069
Note: See TracChangeset
for help on using the changeset viewer.