Make WordPress Core

Changeset 31372


Ignore:
Timestamp:
02/09/2015 12:38:11 AM (10 years ago)
Author:
pento
Message:

WPDB: Some character set tests were failing if DB_CHARSET was empty, or a non-utf8 character set.

Location:
trunk/tests/phpunit/tests
Files:
2 edited

Legend:

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

    r30704 r31372  
    730730    function test_process_fields() {
    731731        global $wpdb;
     732
     733        if ( $wpdb->charset ) {
     734            $expected_charset = $wpdb->charset;
     735        } else {
     736            $expected_charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' );
     737        }
     738
     739        if ( ! in_array( $expected_charset, array( 'utf8', 'utf8mb4', 'latin1' ) ) ) {
     740            $this->markTestSkipped( "This test only works with utf8, utf8mb4 or latin1 character sets" );
     741        }
     742
    732743        $data = array( 'post_content' => '¡foo foo foo!' );
    733744        $expected = array(
     
    735746                'value' => '¡foo foo foo!',
    736747                'format' => '%s',
    737                 'charset' => $wpdb->charset,
     748                'charset' => $expected_charset,
    738749                'ascii' => false,
    739750            )
  • trunk/tests/phpunit/tests/db/charset.php

    r31349 r31372  
    123123     */
    124124    function test_strip_invalid_text( $data, $expected, $message ) {
    125         if ( $data[0]['charset'] === 'koi8r' ) {
    126             self::$_wpdb->query( 'SET NAMES koi8r' );
    127         }
    128125        $actual = self::$_wpdb->strip_invalid_text( $data );
    129126        $this->assertSame( $expected, $actual, $message );
     
    135132    function test_process_fields_failure() {
    136133        global $wpdb;
     134
     135        $charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' );
     136        if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
     137            $this->markTestSkipped( 'This test requires a utf8 character set' );
     138        }
     139
    137140        // \xf0\xff\xff\xff is invalid in utf8 and utf8mb4.
    138141        $data = array( 'post_content' => "H€llo\xf0\xff\xff\xffWorld¢" );
     
    144147     */
    145148    function data_process_field_charsets() {
    146         $charset = $GLOBALS['wpdb']->charset; // This is how all tables were installed
     149        if ( $GLOBALS['wpdb']->charset ) {
     150            $charset = $GLOBALS['wpdb']->charset;
     151        } else {
     152            $charset = $GLOBALS['wpdb']->get_col_charset( $GLOBALS['wpdb']->posts, 'post_content' );
     153        }
     154
    147155        // 'value' and 'format' are $data, 'charset' ends up as part of $expected
    148156
     
    221229    function test_strip_invalid_text_for_column() {
    222230        global $wpdb;
     231
     232        $charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' );
     233        if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
     234            $this->markTestSkipped( 'This test requires a utf8 character set' );
     235        }
     236
    223237        // Invalid 3-byte and 4-byte sequences
    224238        $value = "H€llo\xe0\x80\x80World\xf0\xff\xff\xff¢";
     
    438452    function test_invalid_characters_in_query() {
    439453        global $wpdb;
     454
     455        $charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' );
     456        if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
     457            $this->markTestSkipped( 'This test requires a utf8 character set' );
     458        }
     459
    440460        $this->assertFalse( $wpdb->query( "INSERT INTO {$wpdb->posts} (post_content) VALUES ('foo\xf0\xff\xff\xffbar')" ) );
    441461    }
Note: See TracChangeset for help on using the changeset viewer.