mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Customize: Reject a changeset update when a non-future date is provided and also ensure that a published changeset always gets set to the current date/time.
* Also moves checks from `customize_save` Ajax handler to the underlying `WP_Customize_Manager::save_changeset_post()` call which plugins may invoke directly. * Ensures that `customize_save_response` filter is always passed an array, with error code available as `code`. Props utkarshpatel, westonruter, sayedwp. See #30937. Fixes #38943. git-svn-id: https://develop.svn.wordpress.org/trunk@39409 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -164,7 +164,7 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
|
||||
$wp_customize->save_changeset_post( array( 'status' => 'publish' ) );
|
||||
$this->make_ajax_call( 'customize_save' );
|
||||
$this->assertFalse( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'changeset_already_published', $this->_last_response_parsed['data'] );
|
||||
$this->assertEquals( 'changeset_already_published', $this->_last_response_parsed['data']['code'] );
|
||||
wp_update_post( array( 'ID' => $wp_customize->changeset_post_id(), 'post_status' => 'auto-draft' ) );
|
||||
|
||||
// User cannot edit.
|
||||
@@ -213,7 +213,7 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
|
||||
$_POST['customize_changeset_date'] = '2010-01-01 00:00:00';
|
||||
$this->make_ajax_call( 'customize_save' );
|
||||
$this->assertFalse( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'not_future_date', $this->_last_response_parsed['data'] );
|
||||
$this->assertEquals( 'not_future_date', $this->_last_response_parsed['data']['code'] );
|
||||
$_POST['customize_changeset_date'] = ( gmdate( 'Y' ) + 1 ) . '-01-01 00:00:00';
|
||||
$this->make_ajax_call( 'customize_save' );
|
||||
$this->assertTrue( $this->_last_response_parsed['success'] );
|
||||
@@ -307,4 +307,80 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
|
||||
$this->assertEquals( 'New Site Title', get_option( 'blogname' ) );
|
||||
$this->assertEquals( 'Published', get_post( $post_id )->post_title );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test WP_Customize_Manager::save().
|
||||
*
|
||||
* @ticket 38943
|
||||
* @covers WP_Customize_Manager::save()
|
||||
*/
|
||||
function test_success_save_post_date() {
|
||||
$uuid = wp_generate_uuid4();
|
||||
$post_id = $this->factory()->post->create( array(
|
||||
'post_name' => $uuid,
|
||||
'post_title' => 'Original',
|
||||
'post_type' => 'customize_changeset',
|
||||
'post_status' => 'auto-draft',
|
||||
'post_content' => wp_json_encode( array(
|
||||
'blogname' => array(
|
||||
'value' => 'New Site Title',
|
||||
),
|
||||
) ),
|
||||
) );
|
||||
$wp_customize = $this->set_up_valid_state( $uuid );
|
||||
|
||||
// Success future schedule date.
|
||||
$future_date = ( gmdate( 'Y' ) + 1 ) . '-01-01 00:00:00';
|
||||
$_POST['customize_changeset_status'] = 'future';
|
||||
$_POST['customize_changeset_title'] = 'Future date';
|
||||
$_POST['customize_changeset_date'] = $future_date;
|
||||
$this->make_ajax_call( 'customize_save' );
|
||||
$this->assertTrue( $this->_last_response_parsed['success'] );
|
||||
$changeset_post_schedule = get_post( $post_id );
|
||||
$this->assertEquals( $future_date, $changeset_post_schedule->post_date );
|
||||
|
||||
// Success future changeset change to draft keeping existing date.
|
||||
unset( $_POST['customize_changeset_date'] );
|
||||
$_POST['customize_changeset_status'] = 'draft';
|
||||
$this->make_ajax_call( 'customize_save' );
|
||||
$this->assertTrue( $this->_last_response_parsed['success'] );
|
||||
$changeset_post_draft = get_post( $post_id );
|
||||
$this->assertEquals( $future_date, $changeset_post_draft->post_date );
|
||||
|
||||
// Success if date is not passed with schedule changeset and stored changeset have future date.
|
||||
$_POST['customize_changeset_status'] = 'future';
|
||||
$this->make_ajax_call( 'customize_save' );
|
||||
$this->assertTrue( $this->_last_response_parsed['success'] );
|
||||
$changeset_post_schedule = get_post( $post_id );
|
||||
$this->assertEquals( $future_date, $changeset_post_schedule->post_date );
|
||||
// Success if draft with past date.
|
||||
$now = current_time( 'mysql' );
|
||||
wp_update_post( array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'draft',
|
||||
'post_date' => $now,
|
||||
'post_date_gmt' => get_gmt_from_date( $now ),
|
||||
) );
|
||||
|
||||
// Fail if future request and existing date is past.
|
||||
$_POST['customize_changeset_status'] = 'future';
|
||||
unset( $_POST['customize_changeset_date'] );
|
||||
$this->make_ajax_call( 'customize_save' );
|
||||
$this->assertFalse( $this->_last_response_parsed['success'] );
|
||||
$this->assertEquals( 'not_future_date', $this->_last_response_parsed['data']['code'] );
|
||||
|
||||
// Success publish changeset reset date to current.
|
||||
wp_update_post( array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'future',
|
||||
'post_date' => $future_date,
|
||||
'post_date_gmt' => get_gmt_from_date( $future_date ),
|
||||
) );
|
||||
unset( $_POST['customize_changeset_date'] );
|
||||
$_POST['customize_changeset_status'] = 'publish';
|
||||
$this->make_ajax_call( 'customize_save' );
|
||||
$this->assertTrue( $this->_last_response_parsed['success'] );
|
||||
$changeset_post_publish = get_post( $post_id );
|
||||
$this->assertNotEquals( $future_date, $changeset_post_publish->post_date );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,10 +627,11 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
'custom' => 'something',
|
||||
),
|
||||
);
|
||||
$date = ( gmdate( 'Y' ) + 1 ) . '-12-01 00:00:00';
|
||||
$r = $manager->save_changeset_post( array(
|
||||
'status' => 'auto-draft',
|
||||
'title' => 'Auto Draft',
|
||||
'date_gmt' => '2010-01-01 00:00:00',
|
||||
'date_gmt' => $date,
|
||||
'data' => $pre_saved_data,
|
||||
) );
|
||||
$this->assertInternalType( 'array', $r );
|
||||
@@ -651,7 +652,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
}
|
||||
$this->assertEquals( 'Auto Draft', get_post( $post_id )->post_title );
|
||||
$this->assertEquals( 'auto-draft', get_post( $post_id )->post_status );
|
||||
$this->assertEquals( '2010-01-01 00:00:00', get_post( $post_id )->post_date_gmt );
|
||||
$this->assertEquals( $date, get_post( $post_id )->post_date_gmt );
|
||||
$this->assertNotEquals( 'Changeset Title', get_option( 'blogname' ) );
|
||||
$this->assertArrayHasKey( 'setting_validities', $r );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user