| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group mbstring |
| | 5 | */ |
| | 6 | class Tests_Mbstring_Serialize extends WP_UnitTestCase { |
| | 7 | |
| | 8 | /** |
| | 9 | * @ticket 180071 |
| | 10 | * @see http://core.trac.wordpress.org/ticket/18007 |
| | 11 | * @global mixed $wpdb |
| | 12 | */ |
| | 13 | public function test_get_option() { |
| | 14 | global $wpdb; |
| | 15 | |
| | 16 | /** |
| | 17 | * Context |
| | 18 | * |
| | 19 | * utf-8 encoded database fields |
| | 20 | * auto overlaoding singlebyte functions from conf (see http://www.php.net/manual/en/mbstring.overload.php) |
| | 21 | */ |
| | 22 | |
| | 23 | if ( ini_get( 'mbstring.func_overload' ) < 4 ) { |
| | 24 | $this->markTestIncomplete( 'Please run as php -d mbstring.func_overload=4 /usr/bin/phpunit -c mbstring.xml'); |
| | 25 | } |
| | 26 | |
| | 27 | // Need to figure out a better solution for this. It won't get rolled back during teardown |
| | 28 | $wpdb->query( 'ALTER TABLE ' . $wpdb->options . ' MODIFY option_value LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci ' ); |
| | 29 | |
| | 30 | /** |
| | 31 | * Bug scenario |
| | 32 | * |
| | 33 | * the strlen call is actually a mb_strlen one |
| | 34 | * the $length var is the number of characters (not bytes) |
| | 35 | * using $data[$length-1] don't retrieve the last char but one before, it's actual position is undefined, depending on the other content of the string |
| | 36 | * this $lastc is not ; or } |
| | 37 | * the string is understood has not serialized |
| | 38 | */ |
| | 39 | |
| | 40 | // Set an option with |
| | 41 | $expected = array( "aéùp" ); |
| | 42 | $serialized = serialize( serialize( $expected ) ); |
| | 43 | |
| | 44 | // Alternate way to create the serialized data |
| | 45 | // $serialized = 's:23:"a:1:{i:0;s:6:"aéùp";}'; |
| | 46 | |
| | 47 | update_option( 'test_18007_option', $expected ); |
| | 48 | |
| | 49 | //* |
| | 50 | // Alternate way to set an option |
| | 51 | $result = $wpdb->query( |
| | 52 | $wpdb->prepare( |
| | 53 | "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) |
| | 54 | ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", |
| | 55 | 'test_18007_option', $serialized, 'no' |
| | 56 | ) |
| | 57 | ); |
| | 58 | //*/ |
| | 59 | |
| | 60 | // Retrieve the option |
| | 61 | $test = get_option( 'test_18007_option' ); |
| | 62 | |
| | 63 | // This should not unserialize properly |
| | 64 | $this->assertNotEquals( $expected, $test ); |
| | 65 | } |
| | 66 | } |