Customize: Let `establish_loaded_changeset` query changesets from any author not just current user when determining which changeset to autoload in non-branching mode.

See #39896.


git-svn-id: https://develop.svn.wordpress.org/trunk@41720 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter 2017-10-04 00:00:47 +00:00
parent 43a34c9167
commit e965140cc9
2 changed files with 33 additions and 4 deletions

View File

@ -612,6 +612,7 @@ final class WP_Customize_Manager {
$unpublished_changeset_posts = $this->get_changeset_posts( array(
'post_status' => array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ),
'exclude_restore_dismissed' => false,
'author' => 'any',
'posts_per_page' => 1,
'order' => 'DESC',
'orderby' => 'date',

View File

@ -151,24 +151,52 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
* @covers WP_Customize_Manager::__construct()
*/
public function test_constructor_deferred_changeset_uuid() {
wp_set_current_user( self::$admin_user_id );
$other_admin_user_id = $this->factory()->user->create( array( 'role' => 'admin' ) );
$data = array(
'blogname' => array(
'value' => 'Test',
),
);
$uuid = wp_generate_uuid4();
$post_id = $this->factory()->post->create( array(
$uuid1 = wp_generate_uuid4();
$this->factory()->post->create( array(
'post_type' => 'customize_changeset',
'post_name' => $uuid,
'post_name' => $uuid1,
'post_status' => 'draft',
'post_content' => wp_json_encode( $data ),
'post_author' => get_current_user_id(),
'post_date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '-2 days' ) ),
) );
/*
* Create a changeset for another user that is newer to ensure that it is the one that gets returned,
* as in non-branching mode there should only be one pending changeset at a time.
*/
$uuid2 = wp_generate_uuid4();
$post_id = $this->factory()->post->create( array(
'post_type' => 'customize_changeset',
'post_name' => $uuid2,
'post_status' => 'draft',
'post_content' => wp_json_encode( $data ),
'post_author' => $other_admin_user_id,
'post_date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '-1 day' ) ),
) );
$wp_customize = new WP_Customize_Manager( array(
'changeset_uuid' => false, // Cause UUID to be deferred.
'branching' => false, // To cause drafted changeset to be autoloaded.
) );
$this->assertEquals( $uuid, $wp_customize->changeset_uuid() );
$this->assertEquals( $uuid2, $wp_customize->changeset_uuid() );
$this->assertEquals( $post_id, $wp_customize->changeset_post_id() );
$wp_customize = new WP_Customize_Manager( array(
'changeset_uuid' => false, // Cause UUID to be deferred.
'branching' => true, // To cause no drafted changeset to be autoloaded.
) );
$this->assertNotContains( $wp_customize->changeset_uuid(), array( $uuid1, $uuid2 ) );
$this->assertEmpty( $wp_customize->changeset_post_id() );
}
/**