Make WordPress Core


Ignore:
Timestamp:
10/18/2016 08:04:36 PM (9 years ago)
Author:
westonruter
Message:

Customize: Implement customized state persistence with changesets.

Includes infrastructure developed in the Customize Snapshots feature plugin.

See https://make.wordpress.org/core/2016/10/12/customize-changesets-technical-design-decisions/

Props westonruter, valendesigns, utkarshpatel, stubgo, lgedeon, ocean90, ryankienstra, mihai2u, dlh, aaroncampbell, jonathanbardo, jorbin.
See #28721.
See #31089.
Fixes #30937.
Fixes #31517.
Fixes #30028.
Fixes #23225.
Fixes #34142.
Fixes #36485.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r38398 r38810  
    12411241    }
    12421242
     1243    /**
     1244     * Test ensuring that the post_name (UUID) is preserved when wp_insert_post()/wp_update_post() is called.
     1245     *
     1246     * @see _wp_customize_changeset_filter_insert_post_data()
     1247     * @ticket 30937
     1248     */
     1249    function test_wp_insert_post_for_customize_changeset_should_not_drop_post_name() {
     1250
     1251        $this->assertEquals( 10, has_filter( 'wp_insert_post_data', '_wp_customize_changeset_filter_insert_post_data' ) );
     1252
     1253        $changeset_data = array(
     1254            'blogname' => array(
     1255                'value' => 'Hello World',
     1256            ),
     1257        );
     1258
     1259        wp_set_current_user( $this->factory()->user->create( array( 'role' => 'contributor' ) ) );
     1260
     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        ) );
     1267        $this->assertEquals( $uuid, get_post( $post_id )->post_name, 'Expected lower-case UUID4 to be inserted.' );
     1268        $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
     1269
     1270        $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        ) );
     1276        $this->assertEquals( $uuid, get_post( $post_id )->post_name, 'Expected post_name to not have been dropped for drafts.' );
     1277        $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
     1278
     1279        $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        ) );
     1285        $this->assertEquals( $uuid, get_post( $post_id )->post_name, 'Expected post_name to not have been dropped for pending.' );
     1286        $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
     1287    }
     1288
    12431289}
Note: See TracChangeset for help on using the changeset viewer.