Changeset 47122 for trunk/tests/phpunit/tests/db.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/db.php
r46586 r47122 87 87 global $wpdb; 88 88 89 // Save the current locale settings 89 // Save the current locale settings. 90 90 $current_locales = explode( ';', setlocale( LC_ALL, 0 ) ); 91 91 92 // Switch to Russian 92 // Switch to Russian. 93 93 $flag = setlocale( LC_ALL, 'ru_RU.utf8', 'rus', 'fr_FR.utf8', 'fr_FR', 'de_DE.utf8', 'de_DE', 'es_ES.utf8', 'es_ES', 'ja_JP.utf8', 'ja_JP' ); 94 94 if ( false === $flag ) { … … 96 96 } 97 97 98 // Try an update query 98 // Try an update query. 99 99 $wpdb->suppress_errors( true ); 100 100 $wpdb->update( … … 107 107 $wpdb->suppress_errors( false ); 108 108 109 // Ensure the float isn't 0,700 109 // Ensure the float isn't 0,700. 110 110 $this->assertContains( '0.700', array_pop( $this->_queries ) ); 111 111 112 // Try a prepare 112 // Try a prepare. 113 113 $sql = $wpdb->prepare( 'UPDATE test_table SET float_column = %f AND meta_id = %d', 0.7, 5 ); 114 114 $this->assertContains( '0.700', $sql ); 115 115 116 // Restore locale settings 116 // Restore locale settings. 117 117 foreach ( $current_locales as $locale_setting ) { 118 118 if ( false !== strpos( $locale_setting, '=' ) ) { … … 134 134 135 135 $inputs = array( 136 'howdy%', //Single Percent137 'howdy_', //Single Underscore138 'howdy\\', //Single slash139 'howdy\\howdy%howdy_', // The works140 'howdy\'"[[]*#[^howdy]!+)(*&$#@!~|}{=--`/.,<>?', // Plain text136 'howdy%', // Single percent. 137 'howdy_', // Single underscore. 138 'howdy\\', // Single slash. 139 'howdy\\howdy%howdy_', // The works. 140 'howdy\'"[[]*#[^howdy]!+)(*&$#@!~|}{=--`/.,<>?', // Plain text. 141 141 ); 142 142 $expected = array( … … 195 195 array( 196 196 'a\\%aa', // SELECT 'a\\%aa' 197 'a\\%aa', // LIKE 'a\\\\\\%aa' # The PHP literal would be "LIKE 'a\\\\\\\\\\\\%aa'". 197 'a\\%aa', // LIKE 'a\\\\\\%aa' # The PHP literal would be "LIKE 'a\\\\\\\\\\\\%aa'". This is why we need reliable escape functions! 198 198 '1', 199 199 ), … … 235 235 $dbh = $wpdb->dbh; 236 236 $this->assertNotEmpty( $dbh ); 237 $this->assertTrue( isset( $wpdb->dbh ) ); // Test __isset() 237 $this->assertTrue( isset( $wpdb->dbh ) ); // Test __isset(). 238 238 unset( $wpdb->dbh ); 239 239 $this->assertTrue( empty( $wpdb->dbh ) ); … … 433 433 return array( 434 434 array( 435 "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", // Query 436 array( 1, 'admin', 'extra-arg' ), // ::prepare() args, to be passed via call_user_func_array 437 "SELECT * FROM $wpdb->users WHERE id = 1 AND user_login = 'admin'", // Expected output 435 "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", // Query. 436 array( 1, 'admin', 'extra-arg' ), // ::prepare() args, to be passed via call_user_func_array(). 437 "SELECT * FROM $wpdb->users WHERE id = 1 AND user_login = 'admin'", // Expected output. 438 438 ), 439 439 array( … … 749 749 /** 750 750 * @ticket 21212 751 * @ticket 32763 751 752 */ 752 753 function data_get_table_from_query() { … … 759 760 760 761 $queries = array( 761 // Basic 762 // Basic. 762 763 "SELECT * FROM $table", 763 764 "SELECT * FROM `$table`", … … 796 797 "DELETE `a` FROM $table a", 797 798 798 // Extended 799 // Extended. 799 800 "EXPLAIN SELECT * FROM $table", 800 801 "EXPLAIN EXTENDED SELECT * FROM $table", … … 898 899 function data_get_escaped_table_from_show_query() { 899 900 return array( 900 // Equality 901 // Equality. 901 902 array( "SHOW TABLE STATUS WHERE Name = 'test_name'", 'test_name' ), 902 903 array( 'SHOW TABLE STATUS WHERE NAME="test_name"', 'test_name' ), … … 904 905 array( "SHOW FULL TABLES WHERE Name='test_name'", 'test_name' ), 905 906 906 // LIKE 907 // LIKE. 907 908 array( "SHOW TABLE STATUS LIKE 'test\_prefix\_%'", 'test_prefix_' ), 908 909 array( 'SHOW TABLE STATUS LIKE "test\_prefix\_%"', 'test_prefix_' ), … … 947 948 'post_parent' => 0, 948 949 ), 949 array( '%d', '%s' ), // These override core field_types 950 array( '%d', '%s' ), // These override core field_types. 950 951 array( 951 952 'post_content' => array( … … 1002 1003 'nor_this' => 1, 1003 1004 ), 1004 array( '%d', '%s' ), // The first format is used for the third 1005 array( '%d', '%s' ), // The first format is used for the third. 1005 1006 array( 1006 1007 'this_is_not_a_core_field' => array( … … 1020 1021 1021 1022 $vars = get_defined_vars(); 1022 // Push the variable name onto the end for assertSame $message1023 // Push the variable name onto the end for assertSame() $message. 1023 1024 foreach ( $vars as $var_name => $var ) { 1024 1025 $vars[ $var_name ][] = $var_name; … … 1393 1394 return array( 1394 1395 array( 1395 '%5s', // SQL to prepare 1396 'foo', // Value to insert in the SQL 1397 false, // Whether to expect an incorrect usage error or not 1398 ' foo', // Expected output 1396 '%5s', // SQL to prepare. 1397 'foo', // Value to insert in the SQL. 1398 false, // Whether to expect an incorrect usage error or not. 1399 ' foo', // Expected output. 1399 1400 ), 1400 1401 array( … … 1587 1588 return array( 1588 1589 array( 1589 '%s', // String to pass through esc_url() 1590 ' {ESCAPE} ', // Query to insert the output of esc_url() into, replacing "{ESCAPE}" 1591 'foo', // Data to send to prepare() 1592 true, // Whether to expect an incorrect usage error or not 1593 " {$wpdb->placeholder_escape()}s ", // Expected output 1590 '%s', // String to pass through esc_url(). 1591 ' {ESCAPE} ', // Query to insert the output of esc_url() into, replacing "{ESCAPE}". 1592 'foo', // Data to send to prepare(). 1593 true, // Whether to expect an incorrect usage error or not. 1594 " {$wpdb->placeholder_escape()}s ", // Expected output. 1594 1595 ), 1595 1596 array( … … 1705 1706 return array( 1706 1707 array( 1707 '', // DB_HOST 1708 false, // Expect parse_db_host to bail for this hostname 1709 '', // Parsed host 1710 null, // Parsed port 1711 null, // Parsed socket 1712 false, // is_ipv61708 '', // DB_HOST. 1709 false, // Expect parse_db_host to bail for this hostname. 1710 '', // Parsed host. 1711 null, // Parsed port. 1712 null, // Parsed socket. 1713 false, // $is_ipv6. 1713 1714 ), 1714 1715 array(
Note: See TracChangeset
for help on using the changeset viewer.