Changeset 30587 for trunk/tests/phpunit/tests/db.php
- Timestamp:
- 11/27/2014 10:59:10 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/db.php
r30528 r30587 282 282 $current_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' ); 283 283 284 $new_modes = $expected_modes = array( 'IGNORE_SPACE', 'NO_AUTO_CREATE_USER' ); 285 $expected_modes[] = 'STRICT_ALL_TABLES'; 284 $new_modes = array( 'IGNORE_SPACE', 'NO_AUTO_CREATE_USER' ); 286 285 287 286 $wpdb->set_sql_mode( $new_modes ); 288 287 289 288 $check_new_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' ); 290 $this->assertEqualSets( $ expected_modes, explode( ',', $check_new_modes ) );289 $this->assertEqualSets( $new_modes, explode( ',', $check_new_modes ) ); 291 290 292 291 $wpdb->set_sql_mode( explode( ',', $current_modes ) ); … … 341 340 unset( $modes[ $pos ] ); 342 341 return $modes; 343 }344 345 /**346 * @ticket 21212347 */348 function test_set_sql_mode_strict() {349 global $wpdb;350 $wpdb->set_sql_mode();351 $sql_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );352 $this->assertContains( 'STRICT_ALL_TABLES', explode( ',', $sql_modes ) );353 }354 355 /**356 * @ticket 21212357 */358 function test_strict_mode_numeric_strings() {359 global $wpdb;360 $post_id = $this->factory->post->create();361 $wpdb->update( $wpdb->posts, array( 'post_parent' => 4 ), array( 'ID' => $post_id ), array( '%s' ) );362 $this->assertContains( "`post_parent` = '4'", $wpdb->last_query );363 $this->assertEmpty( $wpdb->last_error );364 }365 366 /**367 * @ticket 21212368 */369 function test_strict_mode_numeric_strings_using_query() {370 global $wpdb;371 $post_id = $this->factory->post->create();372 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %s WHERE ID = %s", '4', $post_id ) );373 $this->assertEmpty( $wpdb->last_error );374 }375 376 /**377 * @ticket 21212378 */379 function test_strict_mode_nan() {380 global $wpdb;381 $post_id = $this->factory->post->create();382 $suppress = $wpdb->suppress_errors( true );383 $wpdb->update( $wpdb->posts, array( 'post_parent' => 'foo' ), array( 'ID' => $post_id ), array( '%s' ) );384 $this->assertContains( "`post_parent` = 'foo'", $wpdb->last_query );385 $this->assertContains( 'Incorrect integer value', $wpdb->last_error );386 $wpdb->suppress_errors( $suppress );387 }388 389 /**390 * @ticket 21212391 */392 function test_strict_mode_nan_using_query() {393 global $wpdb;394 $post_id = $this->factory->post->create();395 $suppress = $wpdb->suppress_errors( true );396 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %s WHERE ID = %s", 'foo', $post_id ) );397 $this->assertContains( 'Incorrect integer value', $wpdb->last_error );398 $wpdb->suppress_errors( $suppress );399 }400 401 /**402 * @ticket 21212403 */404 function test_strict_mode_number_start_of_string() {405 global $wpdb;406 $post_id = $this->factory->post->create();407 $suppress = $wpdb->suppress_errors( true );408 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %s WHERE ID = %s", '4foo', $post_id ) );409 $this->assertContains( "Data truncated for column 'post_parent'", $wpdb->last_error );410 $wpdb->suppress_errors( $suppress );411 }412 413 /**414 * @ticket 21212415 */416 function test_strict_mode_booleans_true() {417 global $wpdb;418 $user_id = $this->factory->user->create();419 $wpdb->query( "UPDATE $wpdb->users SET user_status = true WHERE ID = $user_id" );420 $this->assertEmpty( $wpdb->last_error );421 $user = get_userdata( $user_id );422 $this->assertSame( '1', $user->user_status );423 }424 425 /**426 * @ticket 21212427 */428 function test_strict_mode_booleans_false() {429 global $wpdb;430 $user_id = $this->factory->user->create();431 $wpdb->query( "UPDATE $wpdb->users SET user_status = false WHERE ID = $user_id" );432 $this->assertEmpty( $wpdb->last_error );433 $user = get_userdata( $user_id );434 $this->assertEquals( '0', $user->user_status );435 }436 437 /**438 * @ticket 21212439 */440 function test_strict_mode_zero_date_is_valid() {441 global $wpdb;442 $user_id = $this->factory->user->create();443 $wpdb->query( "UPDATE $wpdb->users SET user_registered = '0000-00-00' WHERE ID = $user_id" );444 $this->assertEmpty( $wpdb->last_error );445 $user = get_userdata( $user_id );446 $this->assertEquals( '0000-00-00 00:00:00', $user->user_registered );447 }448 449 /**450 * @ticket 21212451 */452 function test_strict_mode_zero_datetime_is_valid() {453 global $wpdb;454 $user_id = $this->factory->user->create();455 $wpdb->query( "UPDATE $wpdb->users SET user_registered = '0000-00-00 00:00:00' WHERE ID = $user_id" );456 $this->assertEmpty( $wpdb->last_error );457 $user = get_userdata( $user_id );458 $this->assertEquals( '0000-00-00 00:00:00', $user->user_registered );459 }460 461 /**462 * @ticket 21212463 */464 function test_strict_mode_invalid_dates_are_invalid() {465 global $wpdb;466 $user_id = $this->factory->user->create();467 $suppress = $wpdb->suppress_errors( true );468 $wpdb->query( "UPDATE $wpdb->users SET user_registered = '2014-02-29 00:00:00' WHERE ID = $user_id" );469 $this->assertContains( 'Incorrect datetime value', $wpdb->last_error );470 $wpdb->suppress_errors( $suppress );471 }472 473 /**474 * @ticket 21212475 */476 function test_strict_mode_nulls_are_invalid() {477 global $wpdb;478 $user_id = $this->factory->user->create();479 $suppress = $wpdb->suppress_errors( true );480 $wpdb->query( "UPDATE $wpdb->users SET user_nicename = NULL WHERE ID = $user_id" );481 $this->assertContains( 'cannot be null', $wpdb->last_error );482 $wpdb->suppress_errors( $suppress );483 342 } 484 343
Note: See TracChangeset
for help on using the changeset viewer.