Changeset 42343 for trunk/tests/phpunit/tests/db/charset.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/db/charset.php
r39626 r42343 11 11 /** 12 12 * Our special WPDB 13 * 13 14 * @var resource 14 15 */ … … 41 42 function data_strip_invalid_text() { 42 43 $fields = array( 43 'latin1' => array(44 'latin1' => array( 44 45 // latin1. latin1 never changes. 45 46 'charset' => 'latin1', 46 47 'value' => "\xf0\x9f\x8e\xb7", 47 48 'expected' => "\xf0\x9f\x8e\xb7", 48 'length' => array( 'type' => 'char', 'length' => 100 ), 49 ), 50 'latin1_char_length' => array( 49 'length' => array( 50 'type' => 'char', 51 'length' => 100, 52 ), 53 ), 54 'latin1_char_length' => array( 51 55 // latin1. latin1 never changes. 52 56 'charset' => 'latin1', 53 57 'value' => str_repeat( 'A', 11 ), 54 58 'expected' => str_repeat( 'A', 10 ), 55 'length' => array( 'type' => 'char', 'length' => 10 ), 56 ), 57 'latin1_byte_length' => array( 59 'length' => array( 60 'type' => 'char', 61 'length' => 10, 62 ), 63 ), 64 'latin1_byte_length' => array( 58 65 // latin1. latin1 never changes. 59 66 'charset' => 'latin1', 60 67 'value' => str_repeat( 'A', 11 ), 61 68 'expected' => str_repeat( 'A', 10 ), 62 'length' => array( 'type' => 'byte', 'length' => 10 ), 63 ), 64 'ascii' => array( 69 'length' => array( 70 'type' => 'byte', 71 'length' => 10, 72 ), 73 ), 74 'ascii' => array( 65 75 // ascii gets special treatment, make sure it's covered 66 76 'charset' => 'ascii', 67 77 'value' => 'Hello World', 68 78 'expected' => 'Hello World', 69 'length' => array( 'type' => 'char', 'length' => 100 ), 70 ), 71 'ascii_char_length' => array( 79 'length' => array( 80 'type' => 'char', 81 'length' => 100, 82 ), 83 ), 84 'ascii_char_length' => array( 72 85 // ascii gets special treatment, make sure it's covered 73 86 'charset' => 'ascii', 74 87 'value' => str_repeat( 'A', 11 ), 75 88 'expected' => str_repeat( 'A', 10 ), 76 'length' => array( 'type' => 'char', 'length' => 10 ), 77 ), 78 'ascii_byte_length' => array( 89 'length' => array( 90 'type' => 'char', 91 'length' => 10, 92 ), 93 ), 94 'ascii_byte_length' => array( 79 95 // ascii gets special treatment, make sure it's covered 80 96 'charset' => 'ascii', 81 97 'value' => str_repeat( 'A', 11 ), 82 98 'expected' => str_repeat( 'A', 10 ), 83 'length' => array( 'type' => 'byte', 'length' => 10 ), 84 ), 85 'utf8' => array( 99 'length' => array( 100 'type' => 'byte', 101 'length' => 10, 102 ), 103 ), 104 'utf8' => array( 86 105 // utf8 only allows <= 3-byte chars 87 106 'charset' => 'utf8', 88 107 'value' => "H€llo\xf0\x9f\x98\x88World¢", 89 108 'expected' => 'H€lloWorld¢', 90 'length' => array( 'type' => 'char', 'length' => 100 ), 91 ), 92 'utf8_23char_length' => array( 109 'length' => array( 110 'type' => 'char', 111 'length' => 100, 112 ), 113 ), 114 'utf8_23char_length' => array( 93 115 // utf8 only allows <= 3-byte chars 94 116 'charset' => 'utf8', 95 'value' => str_repeat( "²3", 10 ), 96 'expected' => str_repeat( "²3", 5 ), 97 'length' => array( 'type' => 'char', 'length' => 10 ), 98 ), 99 'utf8_23byte_length' => array( 117 'value' => str_repeat( '²3', 10 ), 118 'expected' => str_repeat( '²3', 5 ), 119 'length' => array( 120 'type' => 'char', 121 'length' => 10, 122 ), 123 ), 124 'utf8_23byte_length' => array( 100 125 // utf8 only allows <= 3-byte chars 101 126 'charset' => 'utf8', 102 'value' => str_repeat( "²3", 10 ), 103 'expected' => "²3²3", 104 'length' => array( 'type' => 'byte', 'length' => 10 ), 105 ), 106 'utf8_3char_length' => array( 127 'value' => str_repeat( '²3', 10 ), 128 'expected' => '²3²3', 129 'length' => array( 130 'type' => 'byte', 131 'length' => 10, 132 ), 133 ), 134 'utf8_3char_length' => array( 107 135 // utf8 only allows <= 3-byte chars 108 136 'charset' => 'utf8', 109 'value' => str_repeat( "3", 11 ), 110 'expected' => str_repeat( "3", 10 ), 111 'length' => array( 'type' => 'char', 'length' => 10 ), 112 ), 113 'utf8_3byte_length' => array( 137 'value' => str_repeat( '3', 11 ), 138 'expected' => str_repeat( '3', 10 ), 139 'length' => array( 140 'type' => 'char', 141 'length' => 10, 142 ), 143 ), 144 'utf8_3byte_length' => array( 114 145 // utf8 only allows <= 3-byte chars 115 146 'charset' => 'utf8', 116 'value' => str_repeat( "3", 11 ), 117 'expected' => "333", 118 'length' => array( 'type' => 'byte', 'length' => 10 ), 119 ), 120 'utf8mb3' => array( 147 'value' => str_repeat( '3', 11 ), 148 'expected' => '333', 149 'length' => array( 150 'type' => 'byte', 151 'length' => 10, 152 ), 153 ), 154 'utf8mb3' => array( 121 155 // utf8mb3 should behave the same an utf8 122 156 'charset' => 'utf8mb3', 123 157 'value' => "H€llo\xf0\x9f\x98\x88World¢", 124 158 'expected' => 'H€lloWorld¢', 125 'length' => array( 'type' => 'char', 'length' => 100 ), 126 ), 127 'utf8mb3_23char_length' => array( 159 'length' => array( 160 'type' => 'char', 161 'length' => 100, 162 ), 163 ), 164 'utf8mb3_23char_length' => array( 128 165 // utf8mb3 should behave the same an utf8 129 166 'charset' => 'utf8mb3', 130 'value' => str_repeat( "²3", 10 ), 131 'expected' => str_repeat( "²3", 5 ), 132 'length' => array( 'type' => 'char', 'length' => 10 ), 133 ), 134 'utf8mb3_23byte_length' => array( 167 'value' => str_repeat( '²3', 10 ), 168 'expected' => str_repeat( '²3', 5 ), 169 'length' => array( 170 'type' => 'char', 171 'length' => 10, 172 ), 173 ), 174 'utf8mb3_23byte_length' => array( 135 175 // utf8mb3 should behave the same an utf8 136 176 'charset' => 'utf8mb3', 137 'value' => str_repeat( "²3", 10 ), 138 'expected' => "²3²3", 139 'length' => array( 'type' => 'byte', 'length' => 10 ), 140 ), 141 'utf8mb3_3char_length' => array( 177 'value' => str_repeat( '²3', 10 ), 178 'expected' => '²3²3', 179 'length' => array( 180 'type' => 'byte', 181 'length' => 10, 182 ), 183 ), 184 'utf8mb3_3char_length' => array( 142 185 // utf8mb3 should behave the same an utf8 143 186 'charset' => 'utf8mb3', 144 'value' => str_repeat( "3", 11 ), 145 'expected' => str_repeat( "3", 10 ), 146 'length' => array( 'type' => 'char', 'length' => 10 ), 147 ), 148 'utf8mb3_3byte_length' => array( 187 'value' => str_repeat( '3', 11 ), 188 'expected' => str_repeat( '3', 10 ), 189 'length' => array( 190 'type' => 'char', 191 'length' => 10, 192 ), 193 ), 194 'utf8mb3_3byte_length' => array( 149 195 // utf8mb3 should behave the same an utf8 150 196 'charset' => 'utf8mb3', 151 'value' => str_repeat( "3", 10 ), 152 'expected' => "333", 153 'length' => array( 'type' => 'byte', 'length' => 10 ), 154 ), 155 'utf8mb4' => array( 197 'value' => str_repeat( '3', 10 ), 198 'expected' => '333', 199 'length' => array( 200 'type' => 'byte', 201 'length' => 10, 202 ), 203 ), 204 'utf8mb4' => array( 156 205 // utf8mb4 allows 4-byte characters, too 157 206 'charset' => 'utf8mb4', 158 207 'value' => "H€llo\xf0\x9f\x98\x88World¢", 159 208 'expected' => "H€llo\xf0\x9f\x98\x88World¢", 160 'length' => array( 'type' => 'char', 'length' => 100 ), 161 ), 162 'utf8mb4_234char_length' => array( 209 'length' => array( 210 'type' => 'char', 211 'length' => 100, 212 ), 213 ), 214 'utf8mb4_234char_length' => array( 163 215 // utf8mb4 allows 4-byte characters, too 164 216 'charset' => 'utf8mb4', 165 'value' => str_repeat( "²3𝟜", 10 ), 166 'expected' => "²3𝟜²3𝟜²3𝟜²", 167 'length' => array( 'type' => 'char', 'length' => 10 ), 168 ), 169 'utf8mb4_234byte_length' => array( 217 'value' => str_repeat( '²3𝟜', 10 ), 218 'expected' => '²3𝟜²3𝟜²3𝟜²', 219 'length' => array( 220 'type' => 'char', 221 'length' => 10, 222 ), 223 ), 224 'utf8mb4_234byte_length' => array( 170 225 // utf8mb4 allows 4-byte characters, too 171 226 'charset' => 'utf8mb4', 172 'value' => str_repeat( "²3𝟜", 10 ), 173 'expected' => "²3𝟜", 174 'length' => array( 'type' => 'byte', 'length' => 10 ), 175 ), 176 'utf8mb4_4char_length' => array( 227 'value' => str_repeat( '²3𝟜', 10 ), 228 'expected' => '²3𝟜', 229 'length' => array( 230 'type' => 'byte', 231 'length' => 10, 232 ), 233 ), 234 'utf8mb4_4char_length' => array( 177 235 // utf8mb4 allows 4-byte characters, too 178 236 'charset' => 'utf8mb4', 179 'value' => str_repeat( "𝟜", 11 ), 180 'expected' => str_repeat( "𝟜", 10 ), 181 'length' => array( 'type' => 'char', 'length' => 10 ), 182 ), 183 'utf8mb4_4byte_length' => array( 237 'value' => str_repeat( '𝟜', 11 ), 238 'expected' => str_repeat( '𝟜', 10 ), 239 'length' => array( 240 'type' => 'char', 241 'length' => 10, 242 ), 243 ), 244 'utf8mb4_4byte_length' => array( 184 245 // utf8mb4 allows 4-byte characters, too 185 246 'charset' => 'utf8mb4', 186 'value' => str_repeat( "𝟜", 10 ), 187 'expected' => "𝟜𝟜", 188 'length' => array( 'type' => 'byte', 'length' => 10 ), 189 ), 190 'koi8r' => array( 247 'value' => str_repeat( '𝟜', 10 ), 248 'expected' => '𝟜𝟜', 249 'length' => array( 250 'type' => 'byte', 251 'length' => 10, 252 ), 253 ), 254 'koi8r' => array( 191 255 'charset' => 'koi8r', 192 256 'value' => "\xfdord\xf2ress", 193 257 'expected' => "\xfdord\xf2ress", 194 'length' => array( 'type' => 'char', 'length' => 100 ), 195 ), 196 'koi8r_char_length' => array( 258 'length' => array( 259 'type' => 'char', 260 'length' => 100, 261 ), 262 ), 263 'koi8r_char_length' => array( 197 264 'charset' => 'koi8r', 198 265 'value' => str_repeat( "\xfd\xf2", 10 ), 199 266 'expected' => str_repeat( "\xfd\xf2", 5 ), 200 'length' => array( 'type' => 'char', 'length' => 10 ), 201 ), 202 'koi8r_byte_length' => array( 267 'length' => array( 268 'type' => 'char', 269 'length' => 10, 270 ), 271 ), 272 'koi8r_byte_length' => array( 203 273 'charset' => 'koi8r', 204 274 'value' => str_repeat( "\xfd\xf2", 10 ), 205 275 'expected' => str_repeat( "\xfd\xf2", 5 ), 206 'length' => array( 'type' => 'byte', 'length' => 10 ), 207 ), 208 'hebrew' => array( 276 'length' => array( 277 'type' => 'byte', 278 'length' => 10, 279 ), 280 ), 281 'hebrew' => array( 209 282 'charset' => 'hebrew', 210 283 'value' => "\xf9ord\xf7ress", 211 284 'expected' => "\xf9ord\xf7ress", 212 'length' => array( 'type' => 'char', 'length' => 100 ), 213 ), 214 'hebrew_char_length' => array( 285 'length' => array( 286 'type' => 'char', 287 'length' => 100, 288 ), 289 ), 290 'hebrew_char_length' => array( 215 291 'charset' => 'hebrew', 216 292 'value' => str_repeat( "\xf9\xf7", 10 ), 217 293 'expected' => str_repeat( "\xf9\xf7", 5 ), 218 'length' => array( 'type' => 'char', 'length' => 10 ), 219 ), 220 'hebrew_byte_length' => array( 294 'length' => array( 295 'type' => 'char', 296 'length' => 10, 297 ), 298 ), 299 'hebrew_byte_length' => array( 221 300 'charset' => 'hebrew', 222 301 'value' => str_repeat( "\xf9\xf7", 10 ), 223 302 'expected' => str_repeat( "\xf9\xf7", 5 ), 224 'length' => array( 'type' => 'byte', 'length' => 10 ), 225 ), 226 'cp1251' => array( 303 'length' => array( 304 'type' => 'byte', 305 'length' => 10, 306 ), 307 ), 308 'cp1251' => array( 227 309 'charset' => 'cp1251', 228 310 'value' => "\xd8ord\xd0ress", 229 311 'expected' => "\xd8ord\xd0ress", 230 'length' => array( 'type' => 'char', 'length' => 100 ), 231 ), 232 'cp1251_no_length' => array( 312 'length' => array( 313 'type' => 'char', 314 'length' => 100, 315 ), 316 ), 317 'cp1251_no_length' => array( 233 318 'charset' => 'cp1251', 234 319 'value' => "\xd8ord\xd0ress", … … 236 321 'length' => false, 237 322 ), 238 'cp1251_no_length_ascii' => array(323 'cp1251_no_length_ascii' => array( 239 324 'charset' => 'cp1251', 240 'value' => "WordPress",241 'expected' => "WordPress",325 'value' => 'WordPress', 326 'expected' => 'WordPress', 242 327 'length' => false, 243 328 // Don't set 'ascii' => true/false. … … 245 330 // three's only only ASCII in the value. 246 331 ), 247 'cp1251_char_length' => array(332 'cp1251_char_length' => array( 248 333 'charset' => 'cp1251', 249 334 'value' => str_repeat( "\xd8\xd0", 10 ), 250 335 'expected' => str_repeat( "\xd8\xd0", 5 ), 251 'length' => array( 'type' => 'char', 'length' => 10 ), 252 ), 253 'cp1251_byte_length' => array( 336 'length' => array( 337 'type' => 'char', 338 'length' => 10, 339 ), 340 ), 341 'cp1251_byte_length' => array( 254 342 'charset' => 'cp1251', 255 343 'value' => str_repeat( "\xd8\xd0", 10 ), 256 344 'expected' => str_repeat( "\xd8\xd0", 5 ), 257 'length' => array( 'type' => 'byte', 'length' => 10 ), 258 ), 259 'tis620' => array( 345 'length' => array( 346 'type' => 'byte', 347 'length' => 10, 348 ), 349 ), 350 'tis620' => array( 260 351 'charset' => 'tis620', 261 352 'value' => "\xccord\xe3ress", 262 353 'expected' => "\xccord\xe3ress", 263 'length' => array( 'type' => 'char', 'length' => 100 ), 264 ), 265 'tis620_char_length' => array( 354 'length' => array( 355 'type' => 'char', 356 'length' => 100, 357 ), 358 ), 359 'tis620_char_length' => array( 266 360 'charset' => 'tis620', 267 361 'value' => str_repeat( "\xcc\xe3", 10 ), 268 362 'expected' => str_repeat( "\xcc\xe3", 5 ), 269 'length' => array( 'type' => 'char', 'length' => 10 ), 270 ), 271 'tis620_byte_length' => array( 363 'length' => array( 364 'type' => 'char', 365 'length' => 10, 366 ), 367 ), 368 'tis620_byte_length' => array( 272 369 'charset' => 'tis620', 273 370 'value' => str_repeat( "\xcc\xe3", 10 ), 274 371 'expected' => str_repeat( "\xcc\xe3", 5 ), 275 'length' => array( 'type' => 'byte', 'length' => 10 ), 276 ), 277 'ujis_with_utf8_connection' => array( 372 'length' => array( 373 'type' => 'byte', 374 'length' => 10, 375 ), 376 ), 377 'ujis_with_utf8_connection' => array( 278 378 'charset' => 'ujis', 279 379 'connection_charset' => 'utf8', 280 380 'value' => '自動下書き', 281 381 'expected' => '自動下書き', 282 'length' => array( 'type' => 'byte', 'length' => 100 ), 382 'length' => array( 383 'type' => 'byte', 384 'length' => 100, 385 ), 283 386 ), 284 387 'ujis_with_utf8_connection_char_length' => array( … … 287 390 'value' => '自動下書き', 288 391 'expected' => '自動下書', 289 'length' => array( 'type' => 'char', 'length' => 4 ), 392 'length' => array( 393 'type' => 'char', 394 'length' => 4, 395 ), 290 396 ), 291 397 'ujis_with_utf8_connection_byte_length' => array( … … 294 400 'value' => '自動下書き', 295 401 'expected' => '自動', 296 'length' => array( 'type' => 'byte', 'length' => 6 ), 297 ), 298 'false' => array( 402 'length' => array( 403 'type' => 'byte', 404 'length' => 6, 405 ), 406 ), 407 'false' => array( 299 408 // false is a column with no character set (ie, a number column) 300 409 'charset' => false, … … 307 416 if ( function_exists( 'mb_convert_encoding' ) ) { 308 417 // big5 is a non-Unicode multibyte charset 309 $utf8 = "a\xe5\x85\xb1b"; // UTF-8 Character 20849310 $big5 = mb_convert_encoding( $utf8, 'BIG-5', 'UTF-8' );418 $utf8 = "a\xe5\x85\xb1b"; // UTF-8 Character 20849 419 $big5 = mb_convert_encoding( $utf8, 'BIG-5', 'UTF-8' ); 311 420 $conv_utf8 = mb_convert_encoding( $big5, 'UTF-8', 'BIG-5' ); 312 421 // Make sure PHP's multibyte conversions are working correctly … … 318 427 'value' => $big5, 319 428 'expected' => $big5, 320 'length' => array( 'type' => 'char', 'length' => 100 ), 429 'length' => array( 430 'type' => 'char', 431 'length' => 100, 432 ), 321 433 ); 322 434 … … 325 437 'value' => str_repeat( $big5, 10 ), 326 438 'expected' => str_repeat( $big5, 3 ) . 'a', 327 'length' => array( 'type' => 'char', 'length' => 10 ), 439 'length' => array( 440 'type' => 'char', 441 'length' => 10, 442 ), 328 443 ); 329 444 … … 332 447 'value' => str_repeat( $big5, 10 ), 333 448 'expected' => str_repeat( $big5, 2 ) . 'a', 334 'length' => array( 'type' => 'byte', 'length' => 10 ), 449 'length' => array( 450 'type' => 'byte', 451 'length' => 10, 452 ), 335 453 ); 336 454 } … … 339 457 $data_provider = $multiple = $multiple_expected = array(); 340 458 foreach ( $fields as $test_case => $field ) { 341 $expected = $field;459 $expected = $field; 342 460 $expected['value'] = $expected['expected']; 343 461 unset( $expected['expected'], $field['expected'], $expected['connection_charset'] ); 344 462 345 463 // We're keeping track of these for our multiple-field test. 346 $multiple[] = $field;464 $multiple[] = $field; 347 465 $multiple_expected[] = $expected; 348 466 349 467 // strip_invalid_text() expects an array of fields. We're testing one field at a time. 350 $data = array( $field );468 $data = array( $field ); 351 469 $expected = array( $expected ); 352 470 … … 363 481 */ 364 482 function test_strip_invalid_text( $data, $expected, $message ) { 365 if ( version_compare( PHP_VERSION, '5.3', '<' ) && stristr( php_uname( 's' ), 'win' ) ) {483 if ( version_compare( PHP_VERSION, '5.3', '<' ) && stristr( php_uname( 's' ), 'win' ) ) { 366 484 $this->markTestSkipped( 'This test fails in PHP 5.2 on Windows. See https://core.trac.wordpress.org/ticket/31262' ); 367 485 } … … 423 541 424 542 $no_string_fields = array( 425 'post_parent' => array( 'value' => 10, 'format' => '%d', 'charset' => false ), 426 'comment_count' => array( 'value' => 0, 'format' => '%d', 'charset' => false ), 543 'post_parent' => array( 544 'value' => 10, 545 'format' => '%d', 546 'charset' => false, 547 ), 548 'comment_count' => array( 549 'value' => 0, 550 'format' => '%d', 551 'charset' => false, 552 ), 427 553 ); 428 554 429 555 $all_ascii_fields = array( 430 'post_content' => array( 'value' => 'foo foo foo!', 'format' => '%s', 'charset' => $charset ), 431 'post_excerpt' => array( 'value' => 'bar bar bar!', 'format' => '%s', 'charset' => $charset ), 556 'post_content' => array( 557 'value' => 'foo foo foo!', 558 'format' => '%s', 559 'charset' => $charset, 560 ), 561 'post_excerpt' => array( 562 'value' => 'bar bar bar!', 563 'format' => '%s', 564 'charset' => $charset, 565 ), 432 566 ); 433 567 434 568 // This is the same data used in process_field_charsets_for_nonexistent_table() 435 569 $non_ascii_string_fields = array( 436 'post_content' => array( 'value' => '¡foo foo foo!', 'format' => '%s', 'charset' => $charset ), 437 'post_excerpt' => array( 'value' => '¡bar bar bar!', 'format' => '%s', 'charset' => $charset ), 570 'post_content' => array( 571 'value' => '¡foo foo foo!', 572 'format' => '%s', 573 'charset' => $charset, 574 ), 575 'post_excerpt' => array( 576 'value' => '¡bar bar bar!', 577 'format' => '%s', 578 'charset' => $charset, 579 ), 438 580 ); 439 581 … … 470 612 */ 471 613 function test_process_field_charsets_on_nonexistent_table() { 472 $data = array( 'post_content' => array( 'value' => '¡foo foo foo!', 'format' => '%s' ) ); 614 $data = array( 615 'post_content' => array( 616 'value' => '¡foo foo foo!', 617 'format' => '%s', 618 ), 619 ); 473 620 self::$_wpdb->suppress_errors( true ); 474 621 $this->assertFalse( self::$_wpdb->process_field_charsets( $data, 'nonexistent_table' ) ); … … 503 650 504 651 // Invalid 3-byte and 4-byte sequences 505 $value = "H€llo\xe0\x80\x80World\xf0\xff\xff\xff¢";506 $expected = "H€lloWorld¢";507 $actual = $wpdb->strip_invalid_text_for_column( $wpdb->posts, 'post_content', $value );652 $value = "H€llo\xe0\x80\x80World\xf0\xff\xff\xff¢"; 653 $expected = 'H€lloWorld¢'; 654 $actual = $wpdb->strip_invalid_text_for_column( $wpdb->posts, 'post_content', $value ); 508 655 $this->assertEquals( $expected, $actual ); 509 656 } … … 511 658 /** 512 659 * Set of table definitions for testing wpdb::get_table_charset and wpdb::get_column_charset 660 * 513 661 * @var array 514 662 */ … … 517 665 'definition' => '( a INT, b FLOAT )', 518 666 'table_expected' => false, 519 'column_expected' => array( 'a' => false, 'b' => false ) 667 'column_expected' => array( 668 'a' => false, 669 'b' => false, 670 ), 520 671 ), 521 672 array( 522 673 'definition' => '( a VARCHAR(50) CHARACTER SET big5, b TEXT CHARACTER SET big5 )', 523 674 'table_expected' => 'big5', 524 'column_expected' => array( 'a' => 'big5', 'b' => 'big5' ) 675 'column_expected' => array( 676 'a' => 'big5', 677 'b' => 'big5', 678 ), 525 679 ), 526 680 array( 527 681 'definition' => '( a VARCHAR(50) CHARACTER SET big5, b BINARY )', 528 682 'table_expected' => 'binary', 529 'column_expected' => array( 'a' => 'big5', 'b' => false ) 683 'column_expected' => array( 684 'a' => 'big5', 685 'b' => false, 686 ), 530 687 ), 531 688 array( 532 689 'definition' => '( a VARCHAR(50) CHARACTER SET latin1, b BLOB )', 533 690 'table_expected' => 'binary', 534 'column_expected' => array( 'a' => 'latin1', 'b' => false ) 691 'column_expected' => array( 692 'a' => 'latin1', 693 'b' => false, 694 ), 535 695 ), 536 696 array( 537 697 'definition' => '( a VARCHAR(50) CHARACTER SET latin1, b TEXT CHARACTER SET koi8r )', 538 698 'table_expected' => 'koi8r', 539 'column_expected' => array( 'a' => 'latin1', 'b' => 'koi8r' ) 699 'column_expected' => array( 700 'a' => 'latin1', 701 'b' => 'koi8r', 702 ), 540 703 ), 541 704 array( 542 705 'definition' => '( a VARCHAR(50) CHARACTER SET utf8mb3, b TEXT CHARACTER SET utf8mb3 )', 543 706 'table_expected' => 'utf8', 544 'column_expected' => array( 'a' => 'utf8', 'b' => 'utf8' ) 707 'column_expected' => array( 708 'a' => 'utf8', 709 'b' => 'utf8', 710 ), 545 711 ), 546 712 array( 547 713 'definition' => '( a VARCHAR(50) CHARACTER SET utf8, b TEXT CHARACTER SET utf8mb4 )', 548 714 'table_expected' => 'utf8', 549 'column_expected' => array( 'a' => 'utf8', 'b' => 'utf8mb4' ) 715 'column_expected' => array( 716 'a' => 'utf8', 717 'b' => 'utf8mb4', 718 ), 550 719 ), 551 720 array( 552 721 'definition' => '( a VARCHAR(50) CHARACTER SET big5, b TEXT CHARACTER SET koi8r )', 553 722 'table_expected' => 'ascii', 554 'column_expected' => array( 'a' => 'big5', 'b' => 'koi8r' ) 723 'column_expected' => array( 724 'a' => 'big5', 725 'b' => 'koi8r', 726 ), 555 727 ), 556 728 ); … … 563 735 564 736 $vars = array(); 565 foreach ( $this->table_and_column_defs as $i => $value ) {737 foreach ( $this->table_and_column_defs as $i => $value ) { 566 738 $this_table_name = $table_name . '_' . $i; 567 $drop = "DROP TABLE IF EXISTS $this_table_name";568 $create = "CREATE TABLE $this_table_name {$value['definition']}";569 $vars[] = array( $drop, $create, $this_table_name, $value['table_expected'] );739 $drop = "DROP TABLE IF EXISTS $this_table_name"; 740 $create = "CREATE TABLE $this_table_name {$value['definition']}"; 741 $vars[] = array( $drop, $create, $this_table_name, $value['table_expected'] ); 570 742 } 571 743 … … 603 775 604 776 $vars = array(); 605 foreach ( $this->table_and_column_defs as $i => $value ) {777 foreach ( $this->table_and_column_defs as $i => $value ) { 606 778 $this_table_name = $table_name . '_' . $i; 607 $drop = "DROP TABLE IF EXISTS $this_table_name";608 $create = "CREATE TABLE $this_table_name {$value['definition']}";609 $vars[] = array( $drop, $create, $this_table_name, $value['column_expected'] );779 $drop = "DROP TABLE IF EXISTS $this_table_name"; 780 $create = "CREATE TABLE $this_table_name {$value['definition']}"; 781 $vars[] = array( $drop, $create, $this_table_name, $value['column_expected'] ); 610 782 } 611 783 … … 692 864 function data_strip_invalid_text_from_query() { 693 865 $table_name = 'strip_invalid_text_from_query_table'; 694 $data = array(866 $data = array( 695 867 array( 696 868 // binary tables don't get stripped 697 "( a VARCHAR(50) CHARACTER SET utf8, b BINARY )", // create869 '( a VARCHAR(50) CHARACTER SET utf8, b BINARY )', // create 698 870 "('foo\xf0\x9f\x98\x88bar', 'foo')", // query 699 "('foo\xf0\x9f\x98\x88bar', 'foo')" // expected result871 "('foo\xf0\x9f\x98\x88bar', 'foo')", // expected result 700 872 ), 701 873 array( 702 874 // utf8/utf8mb4 tables default to utf8 703 "( a VARCHAR(50) CHARACTER SET utf8, b VARCHAR(50) CHARACTER SET utf8mb4 )",875 '( a VARCHAR(50) CHARACTER SET utf8, b VARCHAR(50) CHARACTER SET utf8mb4 )', 704 876 "('foo\xf0\x9f\x98\x88bar', 'foo')", 705 "('foobar', 'foo')" 877 "('foobar', 'foo')", 706 878 ), 707 879 ); 708 880 709 foreach ( $data as $i => &$value ) {881 foreach ( $data as $i => &$value ) { 710 882 $this_table_name = $table_name . '_' . $i; 711 883 … … 791 963 function data_table_collation_check() { 792 964 $table_name = 'table_collation_check'; 793 $data = array(965 $data = array( 794 966 array( 795 967 // utf8_bin tables don't need extra sanity checking. 796 "( a VARCHAR(50) COLLATE utf8_bin )", // create797 true // expected result968 '( a VARCHAR(50) COLLATE utf8_bin )', // create 969 true, // expected result 798 970 ), 799 971 array( 800 972 // Neither do utf8_general_ci tables. 801 "( a VARCHAR(50) COLLATE utf8_general_ci )",802 true 973 '( a VARCHAR(50) COLLATE utf8_general_ci )', 974 true, 803 975 ), 804 976 array( 805 977 // utf8_unicode_ci tables do. 806 "( a VARCHAR(50) COLLATE utf8_unicode_ci )",807 false 978 '( a VARCHAR(50) COLLATE utf8_unicode_ci )', 979 false, 808 980 ), 809 981 array( 810 982 // utf8_bin tables don't need extra sanity checking, 811 983 // except for when they're not just utf8_bin. 812 "( a VARCHAR(50) COLLATE utf8_bin, b VARCHAR(50) COLLATE big5_chinese_ci )",813 false 984 '( a VARCHAR(50) COLLATE utf8_bin, b VARCHAR(50) COLLATE big5_chinese_ci )', 985 false, 814 986 ), 815 987 array( 816 988 // utf8_bin tables don't need extra sanity checking 817 989 // when the other columns aren't strings. 818 "( a VARCHAR(50) COLLATE utf8_bin, b INT )",819 true 990 '( a VARCHAR(50) COLLATE utf8_bin, b INT )', 991 true, 820 992 ), 821 993 ); 822 994 823 foreach ( $data as $i => &$value ) {995 foreach ( $data as $i => &$value ) { 824 996 $this_table_name = $table_name . '_' . $i; 825 997 … … 853 1025 $this->assertEquals( $expected, $return ); 854 1026 855 foreach ( $always_true as $true_query ) {1027 foreach ( $always_true as $true_query ) { 856 1028 $return = self::$_wpdb->check_safe_collation( $true_query ); 857 1029 $this->assertTrue( $return ); … … 882 1054 } 883 1055 884 $safe_query = "INSERT INTO $tablename( `a` ) VALUES( 'safe data' )";1056 $safe_query = "INSERT INTO $tablename( `a` ) VALUES( 'safe data' )"; 885 1057 $stripped_query = self::$_wpdb->strip_invalid_text_from_query( $safe_query ); 886 1058 … … 899 1071 } 900 1072 901 $charset = self::$_wpdb->charset;1073 $charset = self::$_wpdb->charset; 902 1074 self::$_wpdb->charset = ''; 903 1075 904 $safe_query = "INSERT INTO $tablename( `a` ) VALUES( 'safe data' )";1076 $safe_query = "INSERT INTO $tablename( `a` ) VALUES( 'safe data' )"; 905 1077 $stripped_query = self::$_wpdb->strip_invalid_text_from_query( $safe_query ); 906 1078
Note: See TracChangeset
for help on using the changeset viewer.