- Timestamp:
- 09/23/2019 05:39:36 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r46249 r46252 4414 4414 } 4415 4415 4416 public function test_putting_same_publish_date_does_not_remove_floating_date() { 4417 4418 wp_set_current_user( self::$superadmin_id ); 4419 4420 $time = date( 'Y-m-d H:i:s' ); 4421 4422 $post = self::factory()->post->create_and_get( 4423 array( 4424 'post_status' => 'draft', 4425 'post_date' => $time, 4426 ) 4427 ); 4428 4429 $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); 4430 4431 $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); 4432 $get->set_query_params( array( 'context' => 'edit' ) ); 4433 4434 $get = rest_get_server()->dispatch( $get ); 4435 $get_body = $get->get_data(); 4436 4437 $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); 4438 $put->set_body_params( $get_body ); 4439 4440 $response = rest_get_server()->dispatch( $put ); 4441 $body = $response->get_data(); 4442 4443 $this->assertEquals( $get_body['date'], $body['date'] ); 4444 $this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] ); 4445 4446 $this->assertEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); 4447 } 4448 4449 public function test_putting_different_publish_date_removes_floating_date() { 4450 4451 wp_set_current_user( self::$superadmin_id ); 4452 4453 $time = date( 'Y-m-d H:i:s' ); 4454 $new_time = date( 'Y-m-d H:i:s', strtotime( '+1 week' ) ); 4455 4456 $post = self::factory()->post->create_and_get( 4457 array( 4458 'post_status' => 'draft', 4459 'post_date' => $time, 4460 ) 4461 ); 4462 4463 $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); 4464 4465 $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); 4466 $get->set_query_params( array( 'context' => 'edit' ) ); 4467 4468 $get = rest_get_server()->dispatch( $get ); 4469 $get_body = $get->get_data(); 4470 4471 $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); 4472 $put->set_body_params( 4473 array_merge( 4474 $get_body, 4475 array( 4476 'date' => mysql_to_rfc3339( $new_time ), 4477 ) 4478 ) 4479 ); 4480 4481 $response = rest_get_server()->dispatch( $put ); 4482 $body = $response->get_data(); 4483 4484 $this->assertEquals( mysql_to_rfc3339( $new_time ), $body['date'] ); 4485 4486 $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); 4487 } 4488 4489 public function test_publishing_post_with_same_date_removes_floating_date() { 4490 4491 wp_set_current_user( self::$superadmin_id ); 4492 4493 $time = date( 'Y-m-d H:i:s' ); 4494 4495 $post = self::factory()->post->create_and_get( 4496 array( 4497 'post_status' => 'draft', 4498 'post_date' => $time, 4499 ) 4500 ); 4501 4502 $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); 4503 4504 $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); 4505 $get->set_query_params( array( 'context' => 'edit' ) ); 4506 4507 $get = rest_get_server()->dispatch( $get ); 4508 $get_body = $get->get_data(); 4509 4510 $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); 4511 $put->set_body_params( 4512 array_merge( 4513 $get_body, 4514 array( 4515 'status' => 'publish', 4516 ) 4517 ) 4518 ); 4519 4520 $response = rest_get_server()->dispatch( $put ); 4521 $body = $response->get_data(); 4522 4523 $this->assertEquals( $get_body['date'], $body['date'] ); 4524 $this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] ); 4525 4526 $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); 4527 } 4528 4416 4529 public function tearDown() { 4417 4530 _unregister_post_type( 'private-post' );
Note: See TracChangeset
for help on using the changeset viewer.