Changeset 30807 for branches/4.1/tests/phpunit/tests/db.php
- Timestamp:
- 12/10/2014 10:56:25 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.1/tests/phpunit/tests/db.php
r30704 r30807 233 233 $this->assertNotEmpty( $wpdb->dbh ); 234 234 } 235 236 /**237 * @ticket 21212238 */239 function test_wpdb_actually_protected_properties() {240 global $wpdb;241 242 $new_meta = "HAHA I HOPE THIS DOESN'T WORK";243 244 $col_meta = $wpdb->col_meta;245 $wpdb->col_meta = $new_meta;246 247 $this->assertNotEquals( $col_meta, $new_meta );248 $this->assertEquals( $col_meta, $wpdb->col_meta );249 }250 251 235 /** 252 236 * @ticket 18510 … … 521 505 $wpdb->suppress_errors( $suppress ); 522 506 } 523 524 /**525 * @ticket 21212526 */527 function data_get_table_from_query() {528 $table = 'a_test_table_name';529 530 $queries = array(531 // Basic532 "SELECT * FROM $table",533 "SELECT * FROM `$table`",534 535 "INSERT $table",536 "INSERT IGNORE $table",537 "INSERT IGNORE INTO $table",538 "INSERT INTO $table",539 "INSERT LOW_PRIORITY $table",540 "INSERT DELAYED $table",541 "INSERT HIGH_PRIORITY $table",542 "INSERT LOW_PRIORITY IGNORE $table",543 "INSERT LOW_PRIORITY INTO $table",544 "INSERT LOW_PRIORITY IGNORE INTO $table",545 546 "REPLACE $table",547 "REPLACE INTO $table",548 "REPLACE LOW_PRIORITY $table",549 "REPLACE DELAYED $table",550 "REPLACE LOW_PRIORITY INTO $table",551 552 "UPDATE LOW_PRIORITY $table",553 "UPDATE LOW_PRIORITY IGNORE $table",554 555 "DELETE $table",556 "DELETE IGNORE $table",557 "DELETE IGNORE FROM $table",558 "DELETE FROM $table",559 "DELETE LOW_PRIORITY $table",560 "DELETE QUICK $table",561 "DELETE IGNORE $table",562 "DELETE LOW_PRIORITY FROM $table",563 564 // STATUS565 "SHOW TABLE STATUS LIKE '$table'",566 "SHOW TABLE STATUS WHERE NAME='$table'",567 568 "SHOW TABLES LIKE '$table'",569 "SHOW FULL TABLES LIKE '$table'",570 "SHOW TABLES WHERE NAME='$table'",571 572 // Extended573 "EXPLAIN SELECT * FROM $table",574 "EXPLAIN EXTENDED SELECT * FROM $table",575 "EXPLAIN EXTENDED SELECT * FROM `$table`",576 577 "DESCRIBE $table",578 "DESC $table",579 "EXPLAIN $table",580 "HANDLER $table",581 582 "LOCK TABLE $table",583 "LOCK TABLES $table",584 "UNLOCK TABLE $table",585 586 "RENAME TABLE $table",587 "OPTIMIZE TABLE $table",588 "BACKUP TABLE $table",589 "RESTORE TABLE $table",590 "CHECK TABLE $table",591 "CHECKSUM TABLE $table",592 "ANALYZE TABLE $table",593 "REPAIR TABLE $table",594 595 "TRUNCATE $table",596 "TRUNCATE TABLE $table",597 598 "CREATE TABLE $table",599 "CREATE TEMPORARY TABLE $table",600 "CREATE TABLE IF NOT EXISTS $table",601 602 "ALTER TABLE $table",603 "ALTER IGNORE TABLE $table",604 605 "DROP TABLE $table",606 "DROP TABLE IF EXISTS $table",607 608 "CREATE INDEX foo(bar(20)) ON $table",609 "CREATE UNIQUE INDEX foo(bar(20)) ON $table",610 "CREATE FULLTEXT INDEX foo(bar(20)) ON $table",611 "CREATE SPATIAL INDEX foo(bar(20)) ON $table",612 613 "DROP INDEX foo ON $table",614 615 "LOAD DATA INFILE 'wp.txt' INTO TABLE $table",616 "LOAD DATA LOW_PRIORITY INFILE 'wp.txt' INTO TABLE $table",617 "LOAD DATA CONCURRENT INFILE 'wp.txt' INTO TABLE $table",618 "LOAD DATA LOW_PRIORITY LOCAL INFILE 'wp.txt' INTO TABLE $table",619 "LOAD DATA INFILE 'wp.txt' REPLACE INTO TABLE $table",620 "LOAD DATA INFILE 'wp.txt' IGNORE INTO TABLE $table",621 622 "GRANT ALL ON TABLE $table",623 "REVOKE ALL ON TABLE $table",624 625 "SHOW COLUMNS FROM $table",626 "SHOW FULL COLUMNS FROM $table",627 "SHOW CREATE TABLE $table",628 "SHOW INDEX FROM $table",629 );630 631 foreach ( $queries as &$query ) {632 $query = array( $query, $table );633 }634 return $queries;635 }636 637 /**638 * @dataProvider data_get_table_from_query639 * @ticket 21212640 */641 function test_get_table_from_query( $query, $table ) {642 $this->assertEquals( $table, self::$_wpdb->get_table_from_query( $query ) );643 }644 645 function data_get_table_from_query_false() {646 $table = 'a_test_table_name';647 return array(648 array( "LOL THIS ISN'T EVEN A QUERY $table" ),649 );650 }651 652 /**653 * @dataProvider data_get_table_from_query_false654 * @ticket 21212655 */656 function test_get_table_from_query_false( $query ) {657 $this->assertFalse( self::$_wpdb->get_table_from_query( $query ) );658 }659 660 /**661 * @ticket 21212662 */663 function data_process_field_formats() {664 $core_db_fields_no_format_specified = array(665 array( 'post_content' => 'foo', 'post_parent' => 0 ),666 null,667 array(668 'post_content' => array( 'value' => 'foo', 'format' => '%s' ),669 'post_parent' => array( 'value' => 0, 'format' => '%d' ),670 )671 );672 673 $core_db_fields_formats_specified = array(674 array( 'post_content' => 'foo', 'post_parent' => 0 ),675 array( '%d', '%s' ), // These override core field_types676 array(677 'post_content' => array( 'value' => 'foo', 'format' => '%d' ),678 'post_parent' => array( 'value' => 0, 'format' => '%s' ),679 )680 );681 682 $misc_fields_no_format_specified = array(683 array( 'this_is_not_a_core_field' => 'foo', 'this_is_not_either' => 0 ),684 null,685 array(686 'this_is_not_a_core_field' => array( 'value' => 'foo', 'format' => '%s' ),687 'this_is_not_either' => array( 'value' => 0, 'format' => '%s' ),688 )689 );690 691 $misc_fields_formats_specified = array(692 array( 'this_is_not_a_core_field' => 0, 'this_is_not_either' => 1.2 ),693 array( '%d', '%f' ),694 array(695 'this_is_not_a_core_field' => array( 'value' => 0, 'format' => '%d' ),696 'this_is_not_either' => array( 'value' => 1.2, 'format' => '%f' ),697 )698 );699 700 $misc_fields_insufficient_formats_specified = array(701 array( 'this_is_not_a_core_field' => 0, 'this_is_not_either' => 's', 'nor_this' => 1 ),702 array( '%d', '%s' ), // The first format is used for the third703 array(704 'this_is_not_a_core_field' => array( 'value' => 0, 'format' => '%d' ),705 'this_is_not_either' => array( 'value' => 's', 'format' => '%s' ),706 'nor_this' => array( 'value' => 1, 'format' => '%d' ),707 )708 );709 710 $vars = get_defined_vars();711 // Push the variable name onto the end for assertSame $message712 foreach ( $vars as $var_name => $var ) {713 $vars[ $var_name ][] = $var_name;714 }715 return array_values( $vars );716 }717 718 /**719 * @dataProvider data_process_field_formats720 * @ticket 21212721 */722 function test_process_field_formats( $data, $format, $expected, $message ) {723 $actual = self::$_wpdb->process_field_formats( $data, $format );724 $this->assertSame( $expected, $actual, $message );725 }726 727 /**728 * @ticket 21212729 */730 function test_process_fields() {731 global $wpdb;732 $data = array( 'post_content' => '¡foo foo foo!' );733 $expected = array(734 'post_content' => array(735 'value' => '¡foo foo foo!',736 'format' => '%s',737 'charset' => $wpdb->charset,738 'ascii' => false,739 )740 );741 742 $this->assertSame( $expected, self::$_wpdb->process_fields( $wpdb->posts, $data, null ) );743 }744 745 /**746 * @ticket 21212747 * @depends test_process_fields748 */749 function test_process_fields_on_nonexistent_table( $data ) {750 self::$_wpdb->suppress_errors( true );751 $data = array( 'post_content' => '¡foo foo foo!' );752 $this->assertFalse( self::$_wpdb->process_fields( 'nonexistent_table', $data, null ) );753 self::$_wpdb->suppress_errors( false );754 }755 756 /**757 * @ticket 21212758 */759 function test_pre_get_table_charset_filter() {760 add_filter( 'pre_get_table_charset', array( $this, 'filter_pre_get_table_charset' ), 10, 2 );761 $charset = self::$_wpdb->get_table_charset( 'some_table' );762 remove_filter( 'pre_get_table_charset', array( $this, 'filter_pre_get_table_charset' ), 10 );763 764 $this->assertEquals( $charset, 'fake_charset' );765 }766 function filter_pre_get_table_charset( $charset, $table ) {767 return 'fake_charset';768 }769 770 /**771 * @ticket 21212772 */773 function test_pre_get_col_charset_filter() {774 add_filter( 'pre_get_col_charset', array( $this, 'filter_pre_get_col_charset' ), 10, 3 );775 $charset = self::$_wpdb->get_col_charset( 'some_table', 'some_col' );776 remove_filter( 'pre_get_col_charset', array( $this, 'filter_pre_get_col_charset' ), 10 );777 778 $this->assertEquals( $charset, 'fake_col_charset' );779 }780 function filter_pre_get_col_charset( $charset, $table, $column ) {781 return 'fake_col_charset';782 }783 507 } 784 508
Note: See TracChangeset
for help on using the changeset viewer.