Changeset 42343 for trunk/tests/phpunit/tests/post.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/post.php (modified) (53 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post.php
r40816 r42343 13 13 self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); 14 14 15 add_role( 'grammarian', 'Grammarian', array( 16 'read' => true, 17 'edit_posts' => true, 18 'edit_others_posts' => true, 19 'edit_published_posts' => true, 20 ) ); 15 add_role( 16 'grammarian', 'Grammarian', array( 17 'read' => true, 18 'edit_posts' => true, 19 'edit_others_posts' => true, 20 'edit_published_posts' => true, 21 ) 22 ); 21 23 22 24 self::$grammarian_id = $factory->user->create( array( 'role' => 'grammarian' ) ); … … 37 39 38 40 // helper function: return the timestamp(s) of cron jobs for the specified hook and post 39 function _next_schedule_for_post( $hook, $id) {40 return wp_next_scheduled( 'publish_future_post', array(0=>intval($id)));41 function _next_schedule_for_post( $hook, $id ) { 42 return wp_next_scheduled( 'publish_future_post', array( 0 => intval( $id ) ) ); 41 43 } 42 44 … … 56 58 foreach ( $post_types as $post_type ) { 57 59 $post = array( 58 'post_author' => self::$editor_id,59 'post_status' => 'publish',60 'post_author' => self::$editor_id, 61 'post_status' => 'publish', 60 62 'post_content' => rand_str(), 61 'post_title' => rand_str(), 62 'tax_input' => array( 'post_tag' => 'tag1,tag2', 'ctax' => 'cterm1,cterm2' ), 63 'post_type' => $post_type 63 'post_title' => rand_str(), 64 'tax_input' => array( 65 'post_tag' => 'tag1,tag2', 66 'ctax' => 'cterm1,cterm2', 67 ), 68 'post_type' => $post_type, 64 69 ); 65 70 66 71 // insert a post and make sure the ID is ok 67 $id = wp_insert_post( $post);68 $this->assertTrue( is_numeric($id));69 $this->assertTrue( $id > 0);72 $id = wp_insert_post( $post ); 73 $this->assertTrue( is_numeric( $id ) ); 74 $this->assertTrue( $id > 0 ); 70 75 71 76 // fetch the post and make sure it matches 72 $out = get_post( $id);73 74 $this->assertEquals( $post['post_content'], $out->post_content);75 $this->assertEquals( $post['post_title'], $out->post_title);76 $this->assertEquals( $post['post_status'], $out->post_status);77 $this->assertEquals( $post['post_author'], $out->post_author);77 $out = get_post( $id ); 78 79 $this->assertEquals( $post['post_content'], $out->post_content ); 80 $this->assertEquals( $post['post_title'], $out->post_title ); 81 $this->assertEquals( $post['post_status'], $out->post_status ); 82 $this->assertEquals( $post['post_author'], $out->post_author ); 78 83 79 84 // test cache state … … 83 88 84 89 update_object_term_cache( $id, $post_type ); 85 $tcache = wp_cache_get( $id, "post_tag_relationships");90 $tcache = wp_cache_get( $id, 'post_tag_relationships' ); 86 91 $this->assertInternalType( 'array', $tcache ); 87 92 $this->assertEquals( 2, count( $tcache ) ); 88 93 89 $tcache = wp_cache_get( $id, "ctax_relationships");94 $tcache = wp_cache_get( $id, 'ctax_relationships' ); 90 95 if ( 'cpt' == $post_type ) { 91 96 $this->assertInternalType( 'array', $tcache ); … … 97 102 wp_delete_post( $id, true ); 98 103 $this->assertFalse( wp_cache_get( $id, 'posts' ) ); 99 $this->assertFalse( wp_cache_get( $id, "post_tag_relationships") );100 $this->assertFalse( wp_cache_get( $id, "ctax_relationships") );104 $this->assertFalse( wp_cache_get( $id, 'post_tag_relationships' ) ); 105 $this->assertFalse( wp_cache_get( $id, 'ctax_relationships' ) ); 101 106 } 102 107 … … 107 112 // insert a post with a future date, and make sure the status and cron schedule are correct 108 113 109 $future_date = strtotime( '+1 day');114 $future_date = strtotime( '+1 day' ); 110 115 111 116 $post = array( 112 'post_author' => self::$editor_id,113 'post_status' => 'publish',117 'post_author' => self::$editor_id, 118 'post_status' => 'publish', 114 119 'post_content' => rand_str(), 115 'post_title' => rand_str(),116 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $future_date),120 'post_title' => rand_str(), 121 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date ), 117 122 ); 118 123 119 124 // insert a post and make sure the ID is ok 120 $id = $this->post_ids[] = wp_insert_post( $post);125 $id = $this->post_ids[] = wp_insert_post( $post ); 121 126 #dmp(_get_cron_array()); 122 $this->assertTrue( is_numeric($id));123 $this->assertTrue( $id > 0);127 $this->assertTrue( is_numeric( $id ) ); 128 $this->assertTrue( $id > 0 ); 124 129 125 130 // fetch the post and make sure it matches 126 $out = get_post( $id);127 128 $this->assertEquals( $post['post_content'], $out->post_content);129 $this->assertEquals( $post['post_title'], $out->post_title);130 $this->assertEquals( 'future', $out->post_status);131 $this->assertEquals( $post['post_author'], $out->post_author);132 $this->assertEquals( $post['post_date'], $out->post_date);131 $out = get_post( $id ); 132 133 $this->assertEquals( $post['post_content'], $out->post_content ); 134 $this->assertEquals( $post['post_title'], $out->post_title ); 135 $this->assertEquals( 'future', $out->post_status ); 136 $this->assertEquals( $post['post_author'], $out->post_author ); 137 $this->assertEquals( $post['post_date'], $out->post_date ); 133 138 134 139 // there should be a publish_future_post hook scheduled on the future date 135 $this->assertEquals( $future_date, $this->_next_schedule_for_post('publish_future_post', $id));140 $this->assertEquals( $future_date, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 136 141 } 137 142 … … 140 145 141 146 // Some magic days - one dst one not 142 $future_date_1 = strtotime('June 21st +1 year'); 143 $future_date_2 = strtotime('Jan 11th +1 year'); 144 147 $future_date_1 = strtotime( 'June 21st +1 year' ); 148 $future_date_2 = strtotime( 'Jan 11th +1 year' ); 145 149 146 150 $post = array( 147 'post_author' => self::$editor_id,148 'post_status' => 'publish',151 'post_author' => self::$editor_id, 152 'post_status' => 'publish', 149 153 'post_content' => rand_str(), 150 'post_title' => rand_str(),151 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $future_date_1),154 'post_title' => rand_str(), 155 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date_1 ), 152 156 ); 153 157 154 158 // insert a post and make sure the ID is ok 155 $id = $this->post_ids[] = wp_insert_post( $post);159 $id = $this->post_ids[] = wp_insert_post( $post ); 156 160 157 161 // fetch the post and make sure has the correct date and status 158 $out = get_post( $id);159 $this->assertEquals( 'future', $out->post_status);160 $this->assertEquals( $post['post_date'], $out->post_date);162 $out = get_post( $id ); 163 $this->assertEquals( 'future', $out->post_status ); 164 $this->assertEquals( $post['post_date'], $out->post_date ); 161 165 162 166 // check that there's a publish_future_post job scheduled at the right time 163 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post('publish_future_post', $id));167 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 164 168 165 169 // now save it again with a date further in the future 166 170 167 $post['ID'] = $id;168 $post['post_date'] = strftime("%Y-%m-%d %H:%M:%S", $future_date_2);169 $post['post_date_gmt'] = NULL;170 wp_update_post( $post);171 $post['ID'] = $id; 172 $post['post_date'] = strftime( '%Y-%m-%d %H:%M:%S', $future_date_2 ); 173 $post['post_date_gmt'] = null; 174 wp_update_post( $post ); 171 175 172 176 // fetch the post again and make sure it has the new post_date 173 $out = get_post( $id);174 $this->assertEquals( 'future', $out->post_status);175 $this->assertEquals( $post['post_date'], $out->post_date);177 $out = get_post( $id ); 178 $this->assertEquals( 'future', $out->post_status ); 179 $this->assertEquals( $post['post_date'], $out->post_date ); 176 180 177 181 // and the correct date on the cron job 178 $this->assertEquals( $future_date_2, $this->_next_schedule_for_post('publish_future_post', $id));182 $this->assertEquals( $future_date_2, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 179 183 } 180 184 … … 183 187 // https://core.trac.wordpress.org/ticket/4710 184 188 185 $future_date_1 = strtotime( '+1 day');186 $future_date_2 = strtotime( '+2 day');189 $future_date_1 = strtotime( '+1 day' ); 190 $future_date_2 = strtotime( '+2 day' ); 187 191 188 192 $post = array( 189 'post_author' => self::$editor_id,190 'post_status' => 'publish',193 'post_author' => self::$editor_id, 194 'post_status' => 'publish', 191 195 'post_content' => rand_str(), 192 'post_title' => rand_str(),193 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $future_date_1),196 'post_title' => rand_str(), 197 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date_1 ), 194 198 ); 195 199 196 200 // insert a post and make sure the ID is ok 197 $id = $this->post_ids[] = wp_insert_post( $post);201 $id = $this->post_ids[] = wp_insert_post( $post ); 198 202 199 203 // fetch the post and make sure has the correct date and status 200 $out = get_post( $id);201 $this->assertEquals( 'future', $out->post_status);202 $this->assertEquals( $post['post_date'], $out->post_date);204 $out = get_post( $id ); 205 $this->assertEquals( 'future', $out->post_status ); 206 $this->assertEquals( $post['post_date'], $out->post_date ); 203 207 204 208 // check that there's a publish_future_post job scheduled at the right time 205 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post('publish_future_post', $id));209 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 206 210 207 211 // now save it again with a date further in the future 208 212 209 $post['ID'] = $id;210 $post['post_date'] = strftime("%Y-%m-%d %H:%M:%S", $future_date_2);211 $post['post_date_gmt'] = NULL;212 wp_update_post( $post);213 $post['ID'] = $id; 214 $post['post_date'] = strftime( '%Y-%m-%d %H:%M:%S', $future_date_2 ); 215 $post['post_date_gmt'] = null; 216 wp_update_post( $post ); 213 217 214 218 // fetch the post again and make sure it has the new post_date 215 $out = get_post( $id);216 $this->assertEquals( 'future', $out->post_status);217 $this->assertEquals( $post['post_date'], $out->post_date);219 $out = get_post( $id ); 220 $this->assertEquals( 'future', $out->post_status ); 221 $this->assertEquals( $post['post_date'], $out->post_date ); 218 222 219 223 // and the correct date on the cron job 220 $this->assertEquals( $future_date_2, $this->_next_schedule_for_post('publish_future_post', $id));224 $this->assertEquals( $future_date_2, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 221 225 } 222 226 … … 224 228 // insert a draft post with a future date, and make sure no cron schedule is set 225 229 226 $future_date = strtotime( '+1 day');230 $future_date = strtotime( '+1 day' ); 227 231 228 232 $post = array( 229 'post_author' => self::$editor_id,230 'post_status' => 'draft',233 'post_author' => self::$editor_id, 234 'post_status' => 'draft', 231 235 'post_content' => rand_str(), 232 'post_title' => rand_str(),233 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $future_date),236 'post_title' => rand_str(), 237 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date ), 234 238 ); 235 239 236 240 // insert a post and make sure the ID is ok 237 $id = $this->post_ids[] = wp_insert_post( $post);241 $id = $this->post_ids[] = wp_insert_post( $post ); 238 242 #dmp(_get_cron_array()); 239 $this->assertTrue( is_numeric($id));240 $this->assertTrue( $id > 0);243 $this->assertTrue( is_numeric( $id ) ); 244 $this->assertTrue( $id > 0 ); 241 245 242 246 // fetch the post and make sure it matches 243 $out = get_post( $id);244 245 $this->assertEquals( $post['post_content'], $out->post_content);246 $this->assertEquals( $post['post_title'], $out->post_title);247 $this->assertEquals( 'draft', $out->post_status);248 $this->assertEquals( $post['post_author'], $out->post_author);249 $this->assertEquals( $post['post_date'], $out->post_date);247 $out = get_post( $id ); 248 249 $this->assertEquals( $post['post_content'], $out->post_content ); 250 $this->assertEquals( $post['post_title'], $out->post_title ); 251 $this->assertEquals( 'draft', $out->post_status ); 252 $this->assertEquals( $post['post_author'], $out->post_author ); 253 $this->assertEquals( $post['post_date'], $out->post_date ); 250 254 251 255 // there should be a publish_future_post hook scheduled on the future date 252 $this->assertEquals( false, $this->_next_schedule_for_post('publish_future_post', $id));256 $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 253 257 254 258 } … … 256 260 function test_vb_insert_future_change_to_draft() { 257 261 // insert a future post, then edit and change it to draft, and make sure cron gets it right 258 $future_date_1 = strtotime( '+1 day');262 $future_date_1 = strtotime( '+1 day' ); 259 263 260 264 $post = array( 261 'post_author' => self::$editor_id,262 'post_status' => 'publish',265 'post_author' => self::$editor_id, 266 'post_status' => 'publish', 263 267 'post_content' => rand_str(), 264 'post_title' => rand_str(),265 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $future_date_1),268 'post_title' => rand_str(), 269 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date_1 ), 266 270 ); 267 271 268 272 // insert a post and make sure the ID is ok 269 $id = $this->post_ids[] = wp_insert_post( $post);273 $id = $this->post_ids[] = wp_insert_post( $post ); 270 274 271 275 // fetch the post and make sure has the correct date and status 272 $out = get_post( $id);273 $this->assertEquals( 'future', $out->post_status);274 $this->assertEquals( $post['post_date'], $out->post_date);276 $out = get_post( $id ); 277 $this->assertEquals( 'future', $out->post_status ); 278 $this->assertEquals( $post['post_date'], $out->post_date ); 275 279 276 280 // check that there's a publish_future_post job scheduled at the right time 277 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post('publish_future_post', $id));281 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 278 282 279 283 // now save it again with status set to draft 280 284 281 $post['ID'] = $id;285 $post['ID'] = $id; 282 286 $post['post_status'] = 'draft'; 283 wp_update_post( $post);287 wp_update_post( $post ); 284 288 285 289 // fetch the post again and make sure it has the new post_date 286 $out = get_post( $id);287 $this->assertEquals( 'draft', $out->post_status);288 $this->assertEquals( $post['post_date'], $out->post_date);290 $out = get_post( $id ); 291 $this->assertEquals( 'draft', $out->post_status ); 292 $this->assertEquals( $post['post_date'], $out->post_date ); 289 293 290 294 // and the correct date on the cron job 291 $this->assertEquals( false, $this->_next_schedule_for_post('publish_future_post', $id));295 $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 292 296 } 293 297 294 298 function test_vb_insert_future_change_status() { 295 299 // insert a future post, then edit and change the status, and make sure cron gets it right 296 $future_date_1 = strtotime( '+1 day');297 298 $statuses = array( 'draft', 'static', 'object', 'attachment', 'inherit', 'pending');299 300 foreach ( $statuses as $status) {300 $future_date_1 = strtotime( '+1 day' ); 301 302 $statuses = array( 'draft', 'static', 'object', 'attachment', 'inherit', 'pending' ); 303 304 foreach ( $statuses as $status ) { 301 305 $post = array( 302 'post_author' => self::$editor_id,303 'post_status' => 'publish',306 'post_author' => self::$editor_id, 307 'post_status' => 'publish', 304 308 'post_content' => rand_str(), 305 'post_title' => rand_str(),306 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $future_date_1),309 'post_title' => rand_str(), 310 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date_1 ), 307 311 ); 308 312 309 313 // insert a post and make sure the ID is ok 310 $id = $this->post_ids[] = wp_insert_post( $post);314 $id = $this->post_ids[] = wp_insert_post( $post ); 311 315 312 316 // fetch the post and make sure has the correct date and status 313 $out = get_post( $id);314 $this->assertEquals( 'future', $out->post_status);315 $this->assertEquals( $post['post_date'], $out->post_date);317 $out = get_post( $id ); 318 $this->assertEquals( 'future', $out->post_status ); 319 $this->assertEquals( $post['post_date'], $out->post_date ); 316 320 317 321 // check that there's a publish_future_post job scheduled at the right time 318 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post('publish_future_post', $id));322 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 319 323 320 324 // now save it again with status changed 321 325 322 $post['ID'] = $id;326 $post['ID'] = $id; 323 327 $post['post_status'] = $status; 324 wp_update_post( $post);328 wp_update_post( $post ); 325 329 326 330 // fetch the post again and make sure it has the new post_date 327 $out = get_post( $id);328 $this->assertEquals( $status, $out->post_status);329 $this->assertEquals( $post['post_date'], $out->post_date);331 $out = get_post( $id ); 332 $this->assertEquals( $status, $out->post_status ); 333 $this->assertEquals( $post['post_date'], $out->post_date ); 330 334 331 335 // and the correct date on the cron job 332 $this->assertEquals( false, $this->_next_schedule_for_post('publish_future_post', $id));336 $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 333 337 } 334 338 } … … 337 341 // insert a draft post with a future date, and make sure no cron schedule is set 338 342 339 $future_date = strtotime( '+1 day');343 $future_date = strtotime( '+1 day' ); 340 344 341 345 $post = array( 342 'post_author' => self::$editor_id,343 'post_status' => 'private',346 'post_author' => self::$editor_id, 347 'post_status' => 'private', 344 348 'post_content' => rand_str(), 345 'post_title' => rand_str(),346 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $future_date),349 'post_title' => rand_str(), 350 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date ), 347 351 ); 348 352 349 353 // insert a post and make sure the ID is ok 350 $id = $this->post_ids[] = wp_insert_post( $post);354 $id = $this->post_ids[] = wp_insert_post( $post ); 351 355 #dmp(_get_cron_array()); 352 $this->assertTrue( is_numeric($id));353 $this->assertTrue( $id > 0);356 $this->assertTrue( is_numeric( $id ) ); 357 $this->assertTrue( $id > 0 ); 354 358 355 359 // fetch the post and make sure it matches 356 $out = get_post( $id);357 358 $this->assertEquals( $post['post_content'], $out->post_content);359 $this->assertEquals( $post['post_title'], $out->post_title);360 $this->assertEquals( 'private', $out->post_status);361 $this->assertEquals( $post['post_author'], $out->post_author);362 $this->assertEquals( $post['post_date'], $out->post_date);360 $out = get_post( $id ); 361 362 $this->assertEquals( $post['post_content'], $out->post_content ); 363 $this->assertEquals( $post['post_title'], $out->post_title ); 364 $this->assertEquals( 'private', $out->post_status ); 365 $this->assertEquals( $post['post_author'], $out->post_author ); 366 $this->assertEquals( $post['post_date'], $out->post_date ); 363 367 364 368 // there should be a publish_future_post hook scheduled on the future date 365 $this->assertEquals( false, $this->_next_schedule_for_post('publish_future_post', $id));369 $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 366 370 } 367 371 … … 373 377 374 378 $post = array( 375 'post_author' => self::$editor_id,376 'post_status' => 'public',379 'post_author' => self::$editor_id, 380 'post_status' => 'public', 377 381 'post_content' => rand_str(), 378 'post_title' => rand_str(),379 'post_date' => '2012-02-30 00:00:00',382 'post_title' => rand_str(), 383 'post_date' => '2012-02-30 00:00:00', 380 384 ); 381 385 … … 391 395 function test_vb_insert_future_change_to_private() { 392 396 // insert a future post, then edit and change it to private, and make sure cron gets it right 393 $future_date_1 = strtotime( '+1 day');397 $future_date_1 = strtotime( '+1 day' ); 394 398 395 399 $post = array( 396 'post_author' => self::$editor_id,397 'post_status' => 'publish',400 'post_author' => self::$editor_id, 401 'post_status' => 'publish', 398 402 'post_content' => rand_str(), 399 'post_title' => rand_str(),400 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $future_date_1),403 'post_title' => rand_str(), 404 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date_1 ), 401 405 ); 402 406 403 407 // insert a post and make sure the ID is ok 404 $id = $this->post_ids[] = wp_insert_post( $post);408 $id = $this->post_ids[] = wp_insert_post( $post ); 405 409 406 410 // fetch the post and make sure has the correct date and status 407 $out = get_post( $id);408 $this->assertEquals( 'future', $out->post_status);409 $this->assertEquals( $post['post_date'], $out->post_date);411 $out = get_post( $id ); 412 $this->assertEquals( 'future', $out->post_status ); 413 $this->assertEquals( $post['post_date'], $out->post_date ); 410 414 411 415 // check that there's a publish_future_post job scheduled at the right time 412 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post('publish_future_post', $id));416 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 413 417 414 418 // now save it again with status set to draft 415 419 416 $post['ID'] = $id;420 $post['ID'] = $id; 417 421 $post['post_status'] = 'private'; 418 wp_update_post( $post);422 wp_update_post( $post ); 419 423 420 424 // fetch the post again and make sure it has the new post_date 421 $out = get_post( $id);422 $this->assertEquals( 'private', $out->post_status);423 $this->assertEquals( $post['post_date'], $out->post_date);425 $out = get_post( $id ); 426 $this->assertEquals( 'private', $out->post_status ); 427 $this->assertEquals( $post['post_date'], $out->post_date ); 424 428 425 429 // and the correct date on the cron job 426 $this->assertEquals( false, $this->_next_schedule_for_post('publish_future_post', $id));430 $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 427 431 } 428 432 … … 433 437 $this->set_permalink_structure( '/%postname%/' ); 434 438 435 $p = wp_insert_post( array( 436 'post_title' => '', 437 'post_content' => 'test', 438 'post_status' => 'publish', 439 'post_type' => 'post', 440 ) ); 439 $p = wp_insert_post( 440 array( 441 'post_title' => '', 442 'post_content' => 'test', 443 'post_status' => 'publish', 444 'post_type' => 'post', 445 ) 446 ); 441 447 442 448 $post = get_post( $p ); … … 451 457 * @ticket 33392 452 458 */ 453 public function test_wp_insert_post_should_invalidate_post_cache_before_generating_guid_when_post_name_is_empty_and_is_generated_from_the_post_ID() {459 public function test_wp_insert_post_should_invalidate_post_cache_before_generating_guid_when_post_name_is_empty_and_is_generated_from_the_post_ID() { 454 460 register_post_type( 'wptests_pt' ); 455 461 456 $p = wp_insert_post( array( 457 'post_title' => '', 458 'post_type' => 'wptests_pt', 459 'post_status' => 'publish', 460 ) ); 462 $p = wp_insert_post( 463 array( 464 'post_title' => '', 465 'post_type' => 'wptests_pt', 466 'post_status' => 'publish', 467 ) 468 ); 461 469 462 470 $post = get_post( $p ); … … 469 477 */ 470 478 public function test_wp_insert_post_with_meta_input() { 471 $post_id = wp_insert_post( array( 472 'post_title' => '', 473 'post_content' => 'test', 474 'post_status' => 'publish', 475 'post_type' => 'post', 476 'meta_input' => array( 477 'hello' => 'world', 478 'foo' => 'bar' 479 ) 480 ) ); 479 $post_id = wp_insert_post( 480 array( 481 'post_title' => '', 482 'post_content' => 'test', 483 'post_status' => 'publish', 484 'post_type' => 'post', 485 'meta_input' => array( 486 'hello' => 'world', 487 'foo' => 'bar', 488 ), 489 ) 490 ); 481 491 482 492 $this->assertEquals( 'world', get_post_meta( $post_id, 'hello', true ) ); … … 489 499 function test_delete_future_post_cron() { 490 500 // "When I delete a future post using wp_delete_post($post->ID) it does not update the cron correctly." 491 $future_date = strtotime( '+1 day');501 $future_date = strtotime( '+1 day' ); 492 502 493 503 $post = array( 494 'post_author' => self::$editor_id,495 'post_status' => 'publish',504 'post_author' => self::$editor_id, 505 'post_status' => 'publish', 496 506 'post_content' => rand_str(), 497 'post_title' => rand_str(),498 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $future_date),507 'post_title' => rand_str(), 508 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date ), 499 509 ); 500 510 501 511 // insert a post and make sure the ID is ok 502 $id = $this->post_ids[] = wp_insert_post( $post);512 $id = $this->post_ids[] = wp_insert_post( $post ); 503 513 504 514 // check that there's a publish_future_post job scheduled at the right time 505 $this->assertEquals( $future_date, $this->_next_schedule_for_post('publish_future_post', $id));515 $this->assertEquals( $future_date, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 506 516 507 517 // now delete the post and make sure the cron entry is removed 508 518 wp_delete_post( $id ); 509 519 510 $this->assertFalse( $this->_next_schedule_for_post('publish_future_post', $id));520 $this->assertFalse( $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 511 521 } 512 522 … … 518 528 // might only fail if the post ID is greater than four characters 519 529 520 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/');530 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 521 531 522 532 $post = array( 523 'post_author' => self::$editor_id,524 'post_status' => 'publish',533 'post_author' => self::$editor_id, 534 'post_status' => 'publish', 525 535 'post_content' => rand_str(), 526 'post_title' => '',527 'post_date' => '2007-10-31 06:15:00',536 'post_title' => '', 537 'post_date' => '2007-10-31 06:15:00', 528 538 ); 529 539 530 540 // insert a post and make sure the ID is ok 531 $id = $this->post_ids[] = wp_insert_post( $post);532 533 $plink = get_permalink( $id);541 $id = $this->post_ids[] = wp_insert_post( $post ); 542 543 $plink = get_permalink( $id ); 534 544 535 545 // permalink should include the post ID at the end 536 $this->assertEquals( get_option('siteurl').'/2007/10/31/'.$id.'/', $plink);546 $this->assertEquals( get_option( 'siteurl' ) . '/2007/10/31/' . $id . '/', $plink ); 537 547 } 538 548 … … 543 553 global $wpdb; 544 554 545 $attachment = self::factory()->post->create_and_get( array( 'post_title' => 'some-page', 'post_type' => 'attachment' ) ); 546 $page = self::factory()->post->create_and_get( array( 'post_title' => 'some-page', 'post_type' => 'page' ) ); 547 $other_att = self::factory()->post->create_and_get( array( 'post_title' => 'some-other-page', 'post_type' => 'attachment' ) ); 555 $attachment = self::factory()->post->create_and_get( 556 array( 557 'post_title' => 'some-page', 558 'post_type' => 'attachment', 559 ) 560 ); 561 $page = self::factory()->post->create_and_get( 562 array( 563 'post_title' => 'some-page', 564 'post_type' => 'page', 565 ) 566 ); 567 $other_att = self::factory()->post->create_and_get( 568 array( 569 'post_title' => 'some-other-page', 570 'post_type' => 'attachment', 571 ) 572 ); 548 573 549 574 $wpdb->update( $wpdb->posts, array( 'post_name' => 'some-page' ), array( 'ID' => $page->ID ) ); … … 579 604 function test_wp_insert_post_and_wp_publish_post_with_future_date() { 580 605 $future_date = gmdate( 'Y-m-d H:i:s', time() + 10000000 ); 581 $post_id = self::factory()->post->create( array( 582 'post_status' => 'publish', 583 'post_date' => $future_date, 584 ) ); 606 $post_id = self::factory()->post->create( 607 array( 608 'post_status' => 'publish', 609 'post_date' => $future_date, 610 ) 611 ); 585 612 586 613 $post = get_post( $post_id ); … … 602 629 603 630 $post_id = wp_insert_post( array( 'post_title' => '<script>Test</script>' ) ); 604 $post = get_post( $post_id );631 $post = get_post( $post_id ); 605 632 $this->assertEquals( '<script>Test</script>', $post->post_title ); 606 633 $this->assertEquals( 'draft', $post->post_status ); … … 608 635 kses_init_filters(); 609 636 610 wp_update_post( array( 'ID' => $post->ID, 'post_status' => 'publish' ) ); 637 wp_update_post( 638 array( 639 'ID' => $post->ID, 640 'post_status' => 'publish', 641 ) 642 ); 611 643 $post = get_post( $post->ID ); 612 644 $this->assertEquals( 'Test', $post->post_title ); … … 622 654 623 655 $post_id = wp_insert_post( array( 'post_title' => '<script>Test</script>' ) ); 624 $post = get_post( $post_id );656 $post = get_post( $post_id ); 625 657 $this->assertEquals( '<script>Test</script>', $post->post_title ); 626 658 $this->assertEquals( 'draft', $post->post_status ); … … 641 673 global $post; 642 674 $parent_id = self::factory()->post->create(); 643 $post = self::factory()->post->create_and_get( array( 'post_parent' => $parent_id ) );675 $post = self::factory()->post->create_and_get( array( 'post_parent' => $parent_id ) ); 644 676 $this->assertEquals( array( $parent_id ), get_post_ancestors( 0 ) ); 645 677 } … … 650 682 function test_update_invalid_post_id() { 651 683 $post_id = self::factory()->post->create( array( 'post_name' => 'get-page-uri-post-name' ) ); 652 $post = get_post( $post_id, ARRAY_A );684 $post = get_post( $post_id, ARRAY_A ); 653 685 654 686 $post['ID'] = 123456789; … … 665 697 global $multipage, $pages, $numpages; 666 698 $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0' ) ); 667 $post = get_post( $post_id );699 $post = get_post( $post_id ); 668 700 setup_postdata( $post ); 669 701 $this->assertEquals( 0, $multipage ); 670 $this->assertCount( 1, $pages );702 $this->assertCount( 1, $pages ); 671 703 $this->assertEquals( 1, $numpages ); 672 704 $this->assertEquals( array( 'Page 0' ), $pages ); … … 676 708 global $multipage, $pages, $numpages; 677 709 $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3' ) ); 678 $post = get_post( $post_id );710 $post = get_post( $post_id ); 679 711 setup_postdata( $post ); 680 712 $this->assertEquals( 1, $multipage ); 681 $this->assertCount( 4, $pages );713 $this->assertCount( 4, $pages ); 682 714 $this->assertEquals( 4, $numpages ); 683 715 $this->assertEquals( array( 'Page 0', 'Page 1', 'Page 2', 'Page 3' ), $pages ); … … 687 719 global $multipage, $pages, $numpages; 688 720 $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0' ) ); 689 $post = get_post( $post_id );721 $post = get_post( $post_id ); 690 722 setup_postdata( $post ); 691 723 $this->assertEquals( 0, $multipage ); 692 $this->assertCount( 1, $pages );724 $this->assertCount( 1, $pages ); 693 725 $this->assertEquals( 1, $numpages ); 694 726 $this->assertEquals( array( 'Page 0' ), $pages ); … … 698 730 global $multipage, $pages, $numpages; 699 731 $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3' ) ); 700 $post = get_post( $post_id );732 $post = get_post( $post_id ); 701 733 setup_postdata( $post ); 702 734 $this->assertEquals( 1, $multipage ); 703 $this->assertCount( 4, $pages );735 $this->assertCount( 4, $pages ); 704 736 $this->assertEquals( 4, $numpages ); 705 737 $this->assertEquals( array( 'Page 0', 'Page 1', 'Page 2', 'Page 3' ), $pages ); … … 712 744 global $multipage, $pages, $numpages; 713 745 $post_id = self::factory()->post->create( array( 'post_content' => '<!--nextpage-->Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3' ) ); 714 $post = get_post( $post_id );746 $post = get_post( $post_id ); 715 747 setup_postdata( $post ); 716 748 $this->assertEquals( 1, $multipage ); 717 $this->assertCount( 4, $pages );749 $this->assertCount( 4, $pages ); 718 750 $this->assertEquals( 4, $numpages ); 719 751 $this->assertEquals( array( 'Page 0', 'Page 1', 'Page 2', 'Page 3' ), $pages ); … … 726 758 global $multipage, $pages, $numpages; 727 759 $post_id = self::factory()->post->create( array( 'post_content' => '<!--nextpage-->Page 0' ) ); 728 $post = get_post( $post_id );760 $post = get_post( $post_id ); 729 761 setup_postdata( $post ); 730 762 $this->assertEquals( 0, $multipage ); 731 $this->assertCount( 1, $pages );763 $this->assertCount( 1, $pages ); 732 764 $this->assertEquals( 1, $numpages ); 733 765 $this->assertEquals( array( 'Page 0' ), $pages ); … … 742 774 register_taxonomy( 'test_tax', 'post' ); 743 775 744 $title = rand_str();745 $post_data = array(746 'post_author' => self::$editor_id,747 'post_status' => 'public',776 $title = rand_str(); 777 $post_data = array( 778 'post_author' => self::$editor_id, 779 'post_status' => 'public', 748 780 'post_content' => rand_str(), 749 'post_title' => $title,750 'tax_input' => array(751 'test_tax' => array( 'term', 'term2', 'term3' ) 752 ) 781 'post_title' => $title, 782 'tax_input' => array( 783 'test_tax' => array( 'term', 'term2', 'term3' ), 784 ), 753 785 ); 754 786 $insert_post_id = wp_insert_post( $post_data, true, true ); 755 $this->assertTrue( ( is_int( $insert_post_id) && $insert_post_id > 0 ) );787 $this->assertTrue( ( is_int( $insert_post_id ) && $insert_post_id > 0 ) ); 756 788 757 789 $post = get_post( $insert_post_id ); … … 764 796 */ 765 797 function test_wp_count_posts() { 766 $post_type = rand_str( 20);798 $post_type = rand_str( 20 ); 767 799 register_post_type( $post_type ); 768 self::factory()->post->create( array( 769 'post_type' => $post_type, 770 'post_author' => self::$editor_id 771 ) ); 800 self::factory()->post->create( 801 array( 802 'post_type' => $post_type, 803 'post_author' => self::$editor_id, 804 ) 805 ); 772 806 $count = wp_count_posts( $post_type, 'readable' ); 773 807 $this->assertEquals( 1, $count->publish ); … … 777 811 778 812 function test_wp_count_posts_filtered() { 779 $post_type = rand_str( 20);813 $post_type = rand_str( 20 ); 780 814 register_post_type( $post_type ); 781 self::factory()->post->create_many( 3, array( 782 'post_type' => $post_type, 783 'post_author' => self::$editor_id 784 ) ); 815 self::factory()->post->create_many( 816 3, array( 817 'post_type' => $post_type, 818 'post_author' => self::$editor_id, 819 ) 820 ); 785 821 $count1 = wp_count_posts( $post_type, 'readable' ); 786 822 $this->assertEquals( 3, $count1->publish ); … … 799 835 800 836 function test_wp_count_posts_insert_invalidation() { 801 $post_ids = self::factory()->post->create_many( 3 );837 $post_ids = self::factory()->post->create_many( 3 ); 802 838 $initial_counts = wp_count_posts(); 803 839 804 $key = array_rand( $post_ids );805 $_post = get_post( $post_ids[$key], ARRAY_A );840 $key = array_rand( $post_ids ); 841 $_post = get_post( $post_ids[ $key ], ARRAY_A ); 806 842 $_post['post_status'] = 'draft'; 807 843 wp_insert_post( $_post ); 808 $post = get_post( $post_ids[ $key] );844 $post = get_post( $post_ids[ $key ] ); 809 845 $this->assertEquals( 'draft', $post->post_status ); 810 846 $this->assertNotEquals( 'publish', $post->post_status ); … … 817 853 818 854 function test_wp_count_posts_trash_invalidation() { 819 $post_ids = self::factory()->post->create_many( 3 );855 $post_ids = self::factory()->post->create_many( 3 ); 820 856 $initial_counts = wp_count_posts(); 821 857 822 858 $key = array_rand( $post_ids ); 823 859 824 wp_trash_post( $post_ids[ $key] );825 826 $post = get_post( $post_ids[ $key] );860 wp_trash_post( $post_ids[ $key ] ); 861 862 $post = get_post( $post_ids[ $key ] ); 827 863 $this->assertEquals( 'trash', $post->post_status ); 828 864 $this->assertNotEquals( 'publish', $post->post_status ); … … 926 962 function test_wp_tag_cloud_link_with_post_type() { 927 963 $post_type = 'new_post_type'; 928 $tax = 'new_tag';964 $tax = 'new_tag'; 929 965 register_post_type( $post_type, array( 'taxonomies' => array( 'post_tag', $tax ) ) ); 930 966 register_taxonomy( $tax, $post_type ); … … 933 969 wp_set_object_terms( $post, rand_str(), $tax ); 934 970 935 $wp_tag_cloud = wp_tag_cloud( array( 936 'post_type' => $post_type, 937 'taxonomy' => $tax, 938 'echo' => false, 939 'link' => 'edit' 940 ) ); 971 $wp_tag_cloud = wp_tag_cloud( 972 array( 973 'post_type' => $post_type, 974 'taxonomy' => $tax, 975 'echo' => false, 976 'link' => 'edit', 977 ) 978 ); 941 979 942 980 preg_match_all( '|href="([^"]+)"|', $wp_tag_cloud, $matches ); … … 944 982 945 983 $terms = get_terms( $tax ); 946 $term = reset( $terms );984 $term = reset( $terms ); 947 985 948 986 foreach ( $matches[1] as $url ) { … … 971 1009 'post_title' => "foo\xf0\x9f\x98\x88bar", 972 1010 'post_content' => "foo\xf0\x9f\x98\x8ebaz", 973 'post_excerpt' => "foo\xf0\x9f\x98\x90bat" 1011 'post_excerpt' => "foo\xf0\x9f\x98\x90bat", 974 1012 ); 975 1013 976 1014 $expected = array( 977 'post_title' => "foo😈bar",978 'post_content' => "foo😎baz",979 'post_excerpt' => "foo😐bat"1015 'post_title' => 'foo😈bar', 1016 'post_content' => 'foo😎baz', 1017 'post_excerpt' => 'foo😐bat', 980 1018 ); 981 1019 … … 984 1022 $post = get_post( $post_id ); 985 1023 986 foreach ( $expected as $field => $value ) {1024 foreach ( $expected as $field => $value ) { 987 1025 $this->assertEquals( $value, $post->$field ); 988 1026 } … … 993 1031 */ 994 1032 function test_wp_insert_post_default_comment_ping_status_open() { 995 $post_id = self::factory()->post->create( array( 996 'post_author' => self::$editor_id, 997 'post_status' => 'public', 998 'post_content' => rand_str(), 999 'post_title' => rand_str(), 1000 ) ); 1001 $post = get_post( $post_id ); 1033 $post_id = self::factory()->post->create( 1034 array( 1035 'post_author' => self::$editor_id, 1036 'post_status' => 'public', 1037 'post_content' => rand_str(), 1038 'post_title' => rand_str(), 1039 ) 1040 ); 1041 $post = get_post( $post_id ); 1002 1042 1003 1043 $this->assertEquals( 'open', $post->comment_status ); … … 1009 1049 */ 1010 1050 function test_wp_insert_post_page_default_comment_ping_status_closed() { 1011 $post_id = self::factory()->post->create( array( 1012 'post_author' => self::$editor_id, 1013 'post_status' => 'public', 1014 'post_content' => rand_str(), 1015 'post_title' => rand_str(), 1016 'post_type' => 'page', 1017 ) ); 1018 $post = get_post( $post_id ); 1051 $post_id = self::factory()->post->create( 1052 array( 1053 'post_author' => self::$editor_id, 1054 'post_status' => 'public', 1055 'post_content' => rand_str(), 1056 'post_title' => rand_str(), 1057 'post_type' => 'page', 1058 ) 1059 ); 1060 $post = get_post( $post_id ); 1019 1061 1020 1062 $this->assertEquals( 'closed', $post->comment_status ); … … 1026 1068 */ 1027 1069 function test_wp_insert_post_cpt_default_comment_ping_status_open() { 1028 $post_type = rand_str( 20);1070 $post_type = rand_str( 20 ); 1029 1071 register_post_type( $post_type, array( 'supports' => array( 'comments', 'trackbacks' ) ) ); 1030 $post_id = self::factory()->post->create( array( 1031 'post_author' => self::$editor_id, 1032 'post_status' => 'public', 1033 'post_content' => rand_str(), 1034 'post_title' => rand_str(), 1035 'post_type' => $post_type, 1036 ) ); 1037 $post = get_post( $post_id ); 1072 $post_id = self::factory()->post->create( 1073 array( 1074 'post_author' => self::$editor_id, 1075 'post_status' => 'public', 1076 'post_content' => rand_str(), 1077 'post_title' => rand_str(), 1078 'post_type' => $post_type, 1079 ) 1080 ); 1081 $post = get_post( $post_id ); 1038 1082 1039 1083 $this->assertEquals( 'open', $post->comment_status ); … … 1046 1090 */ 1047 1091 function test_wp_insert_post_cpt_default_comment_ping_status_closed() { 1048 $post_type = rand_str( 20);1092 $post_type = rand_str( 20 ); 1049 1093 register_post_type( $post_type ); 1050 $post_id = self::factory()->post->create( array( 1051 'post_author' => self::$editor_id, 1052 'post_status' => 'public', 1053 'post_content' => rand_str(), 1054 'post_title' => rand_str(), 1055 'post_type' => $post_type, 1056 ) ); 1057 $post = get_post( $post_id ); 1094 $post_id = self::factory()->post->create( 1095 array( 1096 'post_author' => self::$editor_id, 1097 'post_status' => 'public', 1098 'post_content' => rand_str(), 1099 'post_title' => rand_str(), 1100 'post_type' => $post_type, 1101 ) 1102 ); 1103 $post = get_post( $post_id ); 1058 1104 1059 1105 $this->assertEquals( 'closed', $post->comment_status ); … … 1077 1123 1078 1124 // Create a sticky post. 1079 $post = self::factory()->post->create_and_get( array( 1080 'post_title' => 'Will be changed', 1081 'post_content' => 'Will be changed', 1082 ) ); 1125 $post = self::factory()->post->create_and_get( 1126 array( 1127 'post_title' => 'Will be changed', 1128 'post_content' => 'Will be changed', 1129 ) 1130 ); 1083 1131 stick_post( $post->ID ); 1084 1132 … … 1087 1135 1088 1136 // Edit the post. 1089 $post->post_title = 'Updated';1137 $post->post_title = 'Updated'; 1090 1138 $post->post_content = 'Updated'; 1091 1139 wp_update_post( $post ); … … 1106 1154 function test_user_without_publish_cannot_affect_sticky_with_edit_post() { 1107 1155 // Create a sticky post. 1108 $post = self::factory()->post->create_and_get( array( 1109 'post_title' => 'Will be changed', 1110 'post_content' => 'Will be changed', 1111 ) ); 1156 $post = self::factory()->post->create_and_get( 1157 array( 1158 'post_title' => 'Will be changed', 1159 'post_content' => 'Will be changed', 1160 ) 1161 ); 1112 1162 stick_post( $post->ID ); 1113 1163 … … 1144 1194 function test_hooks_fire_when_post_gets_stuck_and_unstuck() { 1145 1195 $post_id = self::factory()->post->create(); 1146 $a1 = new MockAction();1147 $a2 = new MockAction();1196 $a1 = new MockAction(); 1197 $a2 = new MockAction(); 1148 1198 1149 1199 $this->assertFalse( is_sticky( $post_id ) ); … … 1171 1221 */ 1172 1222 function test_post_updates_without_slug_provided() { 1173 $post_id = self::factory()->post->create( array( 1174 'post_title' => 'Stuff', 1175 'post_status' => 'publish' 1176 ) ); 1223 $post_id = self::factory()->post->create( 1224 array( 1225 'post_title' => 'Stuff', 1226 'post_status' => 'publish', 1227 ) 1228 ); 1177 1229 1178 1230 $data = array( 1179 1231 'ID' => $post_id, 1180 'post_title' => 'Stuff and Things' 1232 'post_title' => 'Stuff and Things', 1181 1233 ); 1182 1234 … … 1185 1237 $updated_post = get_post( $post_id ); 1186 1238 // Ensure changing the post_title didn't modify the post_name. 1187 $this->assertEquals( 'stuff', $updated_post->post_name);1239 $this->assertEquals( 'stuff', $updated_post->post_name ); 1188 1240 } 1189 1241 … … 1211 1263 function test_wp_insert_post_should_respect_post_date_gmt() { 1212 1264 $post = array( 1213 'post_author' => self::$editor_id,1214 'post_status' => 'publish',1215 'post_content' => rand_str(),1216 'post_title' => rand_str(),1265 'post_author' => self::$editor_id, 1266 'post_status' => 'publish', 1267 'post_content' => rand_str(), 1268 'post_title' => rand_str(), 1217 1269 'post_date_gmt' => '2014-01-01 12:00:00', 1218 1270 ); 1219 1271 1220 1272 // insert a post and make sure the ID is ok 1221 $id = wp_insert_post( $post);1222 1223 $out = get_post( $id);1224 1225 $this->assertEquals( $post['post_content'], $out->post_content);1226 $this->assertEquals( $post['post_title'], $out->post_title);1227 $this->assertEquals( $post['post_author'], $out->post_author);1228 $this->assertEquals( get_date_from_gmt($post['post_date_gmt']), $out->post_date);1229 $this->assertEquals( $post['post_date_gmt'], $out->post_date_gmt);1273 $id = wp_insert_post( $post ); 1274 1275 $out = get_post( $id ); 1276 1277 $this->assertEquals( $post['post_content'], $out->post_content ); 1278 $this->assertEquals( $post['post_title'], $out->post_title ); 1279 $this->assertEquals( $post['post_author'], $out->post_author ); 1280 $this->assertEquals( get_date_from_gmt( $post['post_date_gmt'] ), $out->post_date ); 1281 $this->assertEquals( $post['post_date_gmt'], $out->post_date_gmt ); 1230 1282 } 1231 1283 1232 1284 function test_wp_delete_post_reassign_hierarchical_post_type() { 1233 1285 $grandparent_page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 1234 $parent_page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $grandparent_page_id ) ); 1235 $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $parent_page_id ) ); 1286 $parent_page_id = self::factory()->post->create( 1287 array( 1288 'post_type' => 'page', 1289 'post_parent' => $grandparent_page_id, 1290 ) 1291 ); 1292 $page_id = self::factory()->post->create( 1293 array( 1294 'post_type' => 'page', 1295 'post_parent' => $parent_page_id, 1296 ) 1297 ); 1236 1298 $this->assertEquals( $parent_page_id, get_post( $page_id )->post_parent ); 1237 1299 wp_delete_post( $parent_page_id, true ); … … 1259 1321 wp_set_current_user( $this->factory()->user->create( array( 'role' => 'contributor' ) ) ); 1260 1322 1261 $uuid = wp_generate_uuid4(); 1262 $post_id = wp_insert_post( array( 1263 'post_type' => 'customize_changeset', 1264 'post_name' => strtoupper( $uuid ), 1265 'post_content' => wp_json_encode( $changeset_data ), 1266 ) ); 1323 $uuid = wp_generate_uuid4(); 1324 $post_id = wp_insert_post( 1325 array( 1326 'post_type' => 'customize_changeset', 1327 'post_name' => strtoupper( $uuid ), 1328 'post_content' => wp_json_encode( $changeset_data ), 1329 ) 1330 ); 1267 1331 $this->assertEquals( $uuid, get_post( $post_id )->post_name, 'Expected lower-case UUID4 to be inserted.' ); 1268 1332 $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) ); 1269 1333 1270 1334 $changeset_data['blogname']['value'] = 'Hola Mundo'; 1271 wp_update_post( array( 1272 'ID' => $post_id, 1273 'post_status' => 'draft', 1274 'post_content' => wp_json_encode( $changeset_data ), 1275 ) ); 1335 wp_update_post( 1336 array( 1337 'ID' => $post_id, 1338 'post_status' => 'draft', 1339 'post_content' => wp_json_encode( $changeset_data ), 1340 ) 1341 ); 1276 1342 $this->assertEquals( $uuid, get_post( $post_id )->post_name, 'Expected post_name to not have been dropped for drafts.' ); 1277 1343 $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) ); 1278 1344 1279 1345 $changeset_data['blogname']['value'] = 'Hallo Welt'; 1280 wp_update_post( array( 1281 'ID' => $post_id, 1282 'post_status' => 'pending', 1283 'post_content' => wp_json_encode( $changeset_data ), 1284 ) ); 1346 wp_update_post( 1347 array( 1348 'ID' => $post_id, 1349 'post_status' => 'pending', 1350 'post_content' => wp_json_encode( $changeset_data ), 1351 ) 1352 ); 1285 1353 $this->assertEquals( $uuid, get_post( $post_id )->post_name, 'Expected post_name to not have been dropped for pending.' ); 1286 1354 $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
Note: See TracChangeset
for help on using the changeset viewer.