Make WordPress Core


Ignore:
Timestamp:
11/14/2014 09:33:50 PM (11 years ago)
Author:
pento
Message:

If a saving a post fails, remove any invalid characters (such as emoji) from the primary text fields, then try to save it again.

See #21212.

File:
1 edited

Legend:

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

    r30158 r30346  
    10171017        _unregister_post_type( 'post-type-2' );
    10181018    }
     1019
     1020    /**
     1021     * @ticket 21212
     1022     */
     1023    function test_utf8mb3_post_saves_with_emoji() {
     1024        global $wpdb;
     1025        $_wpdb = new wpdb_exposed_methods_for_testing();
     1026
     1027        if ( 'utf8' !== $_wpdb->get_col_charset( $wpdb->posts, 'post_title' ) ) {
     1028            $this->markTestSkipped( 'This test is only useful with the utf8 character set' );
     1029        }
     1030
     1031        require_once( ABSPATH . '/wp-admin/includes/post.php' );
     1032
     1033        $post_id = $this->factory->post->create();
     1034
     1035        $data = array(
     1036            'post_ID'      => $post_id,
     1037            'post_title'   => "foo\xf0\x9f\x98\x88bar",
     1038            'post_content' => "foo\xf0\x9f\x98\x8ebaz",
     1039            'post_excerpt' => "foo\xf0\x9f\x98\x90bat"
     1040        );
     1041
     1042        $expected = array(
     1043            'post_title'   => "foobar",
     1044            'post_content' => "foobaz",
     1045            'post_excerpt' => "foobat"
     1046        );
     1047
     1048        edit_post( $data );
     1049
     1050        $post = get_post( $post_id );
     1051
     1052        foreach( $expected as $field => $value ) {
     1053            $this->assertEquals( $post->$field, $value );
     1054        }
     1055    }
    10191056}
Note: See TracChangeset for help on using the changeset viewer.