Changes from tags/4.1.1 at r61362 to tags/4.1.2 at r61362
- Location:
- tags/4.1.2
- Files:
-
- 51 edited
-
package.json (modified) (1 diff)
-
src/readme.html (modified) (1 diff)
-
src/wp-admin/about.php (modified) (1 diff)
-
src/wp-admin/includes/class-wp-comments-list-table.php (modified) (1 diff)
-
src/wp-admin/includes/dashboard.php (modified) (1 diff)
-
src/wp-admin/includes/template.php (modified) (1 diff)
-
src/wp-admin/js/nav-menu.js (modified) (3 diffs)
-
src/wp-admin/update-core.php (modified) (2 diffs)
-
src/wp-includes/capabilities.php (modified) (2 diffs)
-
src/wp-includes/class-wp-editor.php (modified) (1 diff)
-
src/wp-includes/formatting.php (modified) (1 diff)
-
src/wp-includes/functions.php (modified) (1 diff)
-
src/wp-includes/js/plupload/plupload.flash.swf (modified) (previous)
-
src/wp-includes/version.php (modified) (1 diff)
-
src/wp-includes/wp-db.php (modified) (13 diffs)
-
tests/phpunit/tests/admin/includesScreen.php (modified) (1 diff)
-
tests/phpunit/tests/ajax/Autosave.php (modified) (1 diff)
-
tests/phpunit/tests/ajax/Response.php (modified) (1 diff)
-
tests/phpunit/tests/basic.php (modified) (1 diff)
-
tests/phpunit/tests/cache.php (modified) (1 diff)
-
tests/phpunit/tests/canonical.php (modified) (1 diff)
-
tests/phpunit/tests/canonical/pageOnFront.php (modified) (1 diff)
-
tests/phpunit/tests/category.php (modified) (1 diff)
-
tests/phpunit/tests/comment/getCommentsPagesCount.php (modified) (1 diff)
-
tests/phpunit/tests/cron.php (modified) (1 diff)
-
tests/phpunit/tests/customize/manager.php (modified) (1 diff)
-
tests/phpunit/tests/customize/setting.php (modified) (1 diff)
-
tests/phpunit/tests/db.php (modified) (2 diffs)
-
tests/phpunit/tests/db/charset.php (modified) (1 diff)
-
tests/phpunit/tests/formatting/SanitizeOrderby.php (modified) (1 diff)
-
tests/phpunit/tests/image/base.php (modified) (1 diff)
-
tests/phpunit/tests/link.php (modified) (1 diff)
-
tests/phpunit/tests/mail.php (modified) (1 diff)
-
tests/phpunit/tests/media.php (modified) (1 diff)
-
tests/phpunit/tests/multisite/bootstrap.php (modified) (1 diff)
-
tests/phpunit/tests/multisite/ms-files-rewriting.php (modified) (1 diff)
-
tests/phpunit/tests/multisite/network.php (modified) (1 diff)
-
tests/phpunit/tests/multisite/site.php (modified) (1 diff)
-
tests/phpunit/tests/option/multisite.php (modified) (1 diff)
-
tests/phpunit/tests/post.php (modified) (1 diff)
-
tests/phpunit/tests/post/meta.php (modified) (1 diff)
-
tests/phpunit/tests/post/revisions.php (modified) (1 diff)
-
tests/phpunit/tests/query/conditionals.php (modified) (1 diff)
-
tests/phpunit/tests/query/search.php (modified) (1 diff)
-
tests/phpunit/tests/rewrite.php (modified) (1 diff)
-
tests/phpunit/tests/shortcode.php (modified) (1 diff)
-
tests/phpunit/tests/user/capabilities.php (modified) (1 diff)
-
tests/phpunit/tests/user/countUserPosts.php (modified) (1 diff)
-
tests/phpunit/tests/user/mapMetaCap.php (modified) (1 diff)
-
tests/phpunit/tests/user/multisite.php (modified) (1 diff)
-
tests/phpunit/tests/xmlrpc/wp/getPage.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tags/4.1.2/package.json
r61362 r61362 1 1 { 2 2 "name": "WordPress", 3 "version": "4.1. 1",3 "version": "4.1.2", 4 4 "description": "WordPress is web software you can use to create a beautiful website or blog.", 5 5 "repository": { -
tags/4.1.2/src/readme.html
r61362 r61362 10 10 <h1 id="logo"> 11 11 <a href="https://wordpress.org/"><img alt="WordPress" src="wp-admin/images/wordpress-logo.png" /></a> 12 <br /> Version 4.1. 112 <br /> Version 4.1.2 13 13 </h1> 14 14 <p style="text-align: center">Semantic Personal Publishing Platform</p> -
tags/4.1.2/src/wp-admin/about.php
r61362 r61362 43 43 44 44 <div class="changelog point-releases"> 45 <h3><?php echo _n( 'Maintenance Release', 'Maintenance Releases', 1 ); ?></h3> 45 <h3><?php echo _n( 'Maintenance and Security Release', 'Maintenance and Security Releases', 2 ); ?></h3> 46 <p><?php printf( _n( '<strong>Version %1$s</strong> addressed a security issue.', 47 '<strong>Version %1$s</strong> addressed some security issues.', 8 ), '4.1.2' ); ?> 48 <?php printf( __( 'For more information, see <a href="%s">the release notes</a>.' ), 'http://codex.wordpress.org/Version_4.1.2' ); ?> 49 </p> 46 50 <p><?php printf( _n( '<strong>Version %1$s</strong> addressed %2$s bug.', 47 51 '<strong>Version %1$s</strong> addressed %2$s bugs.', 21 ), '4.1.1', number_format_i18n( 21 ) ); ?> -
tags/4.1.2/src/wp-admin/includes/class-wp-comments-list-table.php
r61362 r61362 555 555 if ( current_user_can( 'edit_post', $post->ID ) ) { 556 556 $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "'>"; 557 $post_link .= get_the_title( $post->ID) . '</a>';557 $post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>'; 558 558 } else { 559 $post_link = get_the_title( $post->ID);559 $post_link = esc_html( get_the_title( $post->ID ) ); 560 560 } 561 561 -
tags/4.1.2/src/wp-admin/includes/dashboard.php
r61362 r61362 519 519 $GLOBALS['comment'] =& $comment; 520 520 521 $comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));521 $comment_post_title = _draft_or_post_title( $comment->comment_post_ID ); 522 522 523 523 if ( current_user_can( 'edit_post', $comment->comment_post_ID ) ) { -
tags/4.1.2/src/wp-admin/includes/template.php
r61362 r61362 1506 1506 if ( empty( $title ) ) 1507 1507 $title = __( '(no title)' ); 1508 return $title;1508 return esc_html( $title ); 1509 1509 } 1510 1510 -
tags/4.1.2/src/wp-admin/js/nav-menu.js
r61362 r61362 454 454 thisLink = menuItem.find( '.menus-move-left' ), 455 455 thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft ); 456 thisLink.prop( 'title', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ). html( thisLinkText ).css( 'display', 'inline' );456 thisLink.prop( 'title', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ).text( thisLinkText ).css( 'display', 'inline' ); 457 457 } 458 458 … … 461 461 thisLink = menuItem.find( '.menus-move-right' ), 462 462 thisLinkText = menus.under.replace( '%s', prevItemNameRight ); 463 thisLink.prop( 'title', menus.moveUnder.replace( '%s', prevItemNameRight ) ). html( thisLinkText ).css( 'display', 'inline' );463 thisLink.prop( 'title', menus.moveUnder.replace( '%s', prevItemNameRight ) ).text( thisLinkText ).css( 'display', 'inline' ); 464 464 } 465 465 } … … 483 483 } 484 484 485 $this.prop('title', title). html( title );485 $this.prop('title', title).text( title ); 486 486 }); 487 487 }, -
tags/4.1.2/src/wp-admin/update-core.php
r61362 r61362 391 391 <?php 392 392 393 if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( ), $allow_relaxed_file_ownership ) ) ) {393 if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ) ) ) { 394 394 echo '</div>'; 395 395 return; … … 398 398 if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) { 399 399 // Failed to connect, Error and request again 400 request_filesystem_credentials( $url, '', true, ABSPATH, array( ), $allow_relaxed_file_ownership );400 request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ); 401 401 echo '</div>'; 402 402 return; -
tags/4.1.2/src/wp-includes/capabilities.php
r61362 r61362 1375 1375 */ 1376 1376 function current_user_can_for_blog( $blog_id, $capability ) { 1377 if ( is_multisite() ) 1378 switch_to_blog( $blog_id ); 1377 $switched = is_multisite() ? switch_to_blog( $blog_id ) : false; 1379 1378 1380 1379 $current_user = wp_get_current_user(); 1381 1380 1382 if ( empty( $current_user ) ) 1381 if ( empty( $current_user ) ) { 1382 if ( $switched ) { 1383 restore_current_blog(); 1384 } 1383 1385 return false; 1386 } 1384 1387 1385 1388 $args = array_slice( func_get_args(), 2 ); … … 1388 1391 $can = call_user_func_array( array( $current_user, 'has_cap' ), $args ); 1389 1392 1390 if ( is_multisite() )1393 if ( $switched ) { 1391 1394 restore_current_blog(); 1395 } 1392 1396 1393 1397 return $can; -
tags/4.1.2/src/wp-includes/class-wp-editor.php
r61362 r61362 117 117 // A cookie (set when a user resizes the editor) overrides the height. 118 118 $cookie = (int) get_user_setting( 'ed_size' ); 119 120 // Upgrade an old TinyMCE cookie if it is still around, and the new one isn't.121 if ( ! $cookie && isset( $_COOKIE['TinyMCE_content_size'] ) ) {122 parse_str( $_COOKIE['TinyMCE_content_size'], $cookie );123 $cookie = $cookie['ch'];124 }125 119 126 120 if ( $cookie ) -
tags/4.1.2/src/wp-includes/formatting.php
r61362 r61362 1310 1310 1311 1311 /** 1312 * Ensures a string is a valid SQL order by clause. 1313 * 1314 * Accepts one or more columns, with or without ASC/DESC, and also accepts 1315 * RAND(). 1312 * Ensures a string is a valid SQL 'order by' clause. 1313 * 1314 * Accepts one or more columns, with or without a sort order (ASC / DESC). 1315 * e.g. 'column_1', 'column_1, column_2', 'column_1 ASC, column_2 DESC' etc. 1316 * 1317 * Also accepts 'RAND()'. 1316 1318 * 1317 1319 * @since 2.5.1 1318 1320 * 1319 * @param string $orderby Order by string to be checked.1320 * @return false|string Returns the order by clause if it is a match, false otherwise.1321 */ 1322 function sanitize_sql_orderby( $orderby ) {1323 preg_match('/^\s*([a-z0-9_]+(\s+(ASC|DESC))?(\s*,\s*|\s*$))+|^\s*RAND\(\s*\)\s*$/i', $orderby, $obmatches);1324 if ( !$obmatches )1325 return false;1326 return $orderby;1321 * @param string $orderby Order by clause to be validated. 1322 * @return string|bool Returns $orderby if valid, false otherwise. 1323 */ 1324 function sanitize_sql_orderby( $orderby ) { 1325 if ( preg_match( '/^\s*(([a-z0-9_]+|`[a-z0-9_]+`)(\s+(ASC|DESC))?\s*(,\s*(?=[a-z0-9_`])|$))+$/i', $orderby ) || preg_match( '/^\s*RAND\(\s*\)\s*$/i', $orderby ) ) { 1326 return $orderby; 1327 } 1328 return false; 1327 1329 } 1328 1330 -
tags/4.1.2/src/wp-includes/functions.php
r61362 r61362 2050 2050 2051 2051 foreach ( $mimes as $ext_preg => $mime_match ) { 2052 $ext_preg = '!\.(' . $ext_preg . ') (\?.*)?$!i';2052 $ext_preg = '!\.(' . $ext_preg . ')$!i'; 2053 2053 if ( preg_match( $ext_preg, $filename, $ext_matches ) ) { 2054 2054 $type = $mime_match; -
tags/4.1.2/src/wp-includes/version.php
r61362 r61362 5 5 * @global string $wp_version 6 6 */ 7 $wp_version = '4.1. 1-src';7 $wp_version = '4.1.2-src'; 8 8 9 9 /** -
tags/4.1.2/src/wp-includes/wp-db.php
r61362 r61362 145 145 146 146 /** 147 * Cached column info, for sanity checking data before inserting 148 * 149 * @since 4.2.0 150 * @access protected 151 * @var array 152 */ 153 protected $col_meta = array(); 154 155 /** 156 * Calculated character sets on tables 157 * 158 * @since 4.2.0 159 * @access protected 160 * @var array 161 */ 162 protected $table_charset = array(); 163 164 /** 165 * Whether text fields in the current query need to be sanity checked. 166 * 167 * @since 4.2.0 168 * @access protected 169 * @var bool 170 */ 171 protected $check_current_query = true; 172 173 /** 174 * Flag to ensure we don't run into recursion problems when checking the collation. 175 * 176 * @since 4.2.0 177 * @access private 178 * @see wpdb::check_safe_collation() 179 * @var boolean 180 */ 181 private $checking_collation = false; 182 183 /** 147 184 * Saved info on the table column 148 185 * … … 648 685 */ 649 686 public function __set( $name, $value ) { 687 $protected_members = array( 688 'col_meta', 689 'table_charset', 690 'check_current_query', 691 ); 692 if ( in_array( $name, $protected_members, true ) ) { 693 return; 694 } 650 695 $this->$name = $value; 651 696 } … … 717 762 if ( ! empty( $collate ) ) 718 763 $query .= $this->prepare( ' COLLATE %s', $collate ); 719 mysqli_query( $ query, $dbh);764 mysqli_query( $dbh, $query ); 720 765 } 721 766 } else { … … 1542 1587 public function query( $query ) { 1543 1588 if ( ! $this->ready ) { 1589 $this->check_current_query = true; 1544 1590 return false; 1545 1591 } … … 1562 1608 $this->func_call = "\$db->query(\"$query\")"; 1563 1609 1610 // If we're writing to the database, make sure the query will write safely. 1611 if ( $this->check_current_query && ! $this->check_ascii( $query ) ) { 1612 $stripped_query = $this->strip_invalid_text_from_query( $query ); 1613 // strip_invalid_text_from_query() can perform queries, so we need 1614 // to flush again, just to make sure everything is clear. 1615 $this->flush(); 1616 if ( $stripped_query !== $query ) { 1617 $this->insert_id = 0; 1618 return false; 1619 } 1620 } 1621 1622 $this->check_current_query = true; 1564 1623 // Keep track of the last query for debug.. 1565 1624 $this->last_query = $query; … … 1731 1790 */ 1732 1791 function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) { 1733 if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) ) 1792 if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) ) { 1734 1793 return false; 1794 } 1795 1796 $data = $this->process_fields( $table, $data, $format ); 1797 if ( false === $data ) { 1798 return false; 1799 } 1800 1801 $formats = $values = array(); 1802 foreach ( $data as $value ) { 1803 $formats[] = $value['format']; 1804 $values[] = $value['value']; 1805 } 1806 1807 $fields = '`' . implode( '`, `', array_keys( $data ) ) . '`'; 1808 $formats = implode( ', ', $formats ); 1809 1810 $sql = "$type INTO `$table` ($fields) VALUES ($formats)"; 1811 1735 1812 $this->insert_id = 0; 1736 $formats = $format = (array) $format; 1737 $fields = array_keys( $data ); 1738 $formatted_fields = array(); 1739 foreach ( $fields as $field ) { 1740 if ( !empty( $format ) ) 1741 $form = ( $form = array_shift( $formats ) ) ? $form : $format[0]; 1742 elseif ( isset( $this->field_types[$field] ) ) 1743 $form = $this->field_types[$field]; 1744 else 1745 $form = '%s'; 1746 $formatted_fields[] = $form; 1747 } 1748 $sql = "{$type} INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES (" . implode( ",", $formatted_fields ) . ")"; 1749 return $this->query( $this->prepare( $sql, $data ) ); 1813 $this->check_current_query = false; 1814 return $this->query( $this->prepare( $sql, $values ) ); 1750 1815 } 1751 1816 … … 1770 1835 */ 1771 1836 public function update( $table, $data, $where, $format = null, $where_format = null ) { 1772 if ( ! is_array( $data ) || ! is_array( $where ) ) 1837 if ( ! is_array( $data ) || ! is_array( $where ) ) { 1773 1838 return false; 1774 1775 $formats = $format = (array) $format; 1776 $bits = $wheres = array(); 1777 foreach ( (array) array_keys( $data ) as $field ) { 1778 if ( !empty( $format ) ) 1779 $form = ( $form = array_shift( $formats ) ) ? $form : $format[0]; 1780 elseif ( isset($this->field_types[$field]) ) 1781 $form = $this->field_types[$field]; 1782 else 1783 $form = '%s'; 1784 $bits[] = "`$field` = {$form}"; 1785 } 1786 1787 $where_formats = $where_format = (array) $where_format; 1788 foreach ( (array) array_keys( $where ) as $field ) { 1789 if ( !empty( $where_format ) ) 1790 $form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[0]; 1791 elseif ( isset( $this->field_types[$field] ) ) 1792 $form = $this->field_types[$field]; 1793 else 1794 $form = '%s'; 1795 $wheres[] = "`$field` = {$form}"; 1796 } 1797 1798 $sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres ); 1799 return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) ); 1839 } 1840 1841 $data = $this->process_fields( $table, $data, $format ); 1842 if ( false === $data ) { 1843 return false; 1844 } 1845 $where = $this->process_fields( $table, $where, $where_format ); 1846 if ( false === $where ) { 1847 return false; 1848 } 1849 1850 $fields = $conditions = $values = array(); 1851 foreach ( $data as $field => $value ) { 1852 $fields[] = "`$field` = " . $value['format']; 1853 $values[] = $value['value']; 1854 } 1855 foreach ( $where as $field => $value ) { 1856 $conditions[] = "`$field` = " . $value['format']; 1857 $values[] = $value['value']; 1858 } 1859 1860 $fields = implode( ', ', $fields ); 1861 $conditions = implode( ' AND ', $conditions ); 1862 1863 $sql = "UPDATE `$table` SET $fields WHERE $conditions"; 1864 1865 $this->check_current_query = false; 1866 return $this->query( $this->prepare( $sql, $values ) ); 1800 1867 } 1801 1868 … … 1817 1884 */ 1818 1885 public function delete( $table, $where, $where_format = null ) { 1819 if ( ! is_array( $where ) ) 1886 if ( ! is_array( $where ) ) { 1820 1887 return false; 1821 1822 $wheres = array(); 1823 1824 $where_formats = $where_format = (array) $where_format; 1825 1826 foreach ( array_keys( $where ) as $field ) { 1827 if ( !empty( $where_format ) ) { 1828 $form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[0]; 1888 } 1889 1890 $where = $this->process_fields( $table, $where, $where_format ); 1891 if ( false === $where ) { 1892 return false; 1893 } 1894 1895 $conditions = $values = array(); 1896 foreach ( $where as $field => $value ) { 1897 $conditions[] = "`$field` = " . $value['format']; 1898 $values[] = $value['value']; 1899 } 1900 1901 $conditions = implode( ' AND ', $conditions ); 1902 1903 $sql = "DELETE FROM `$table` WHERE $conditions"; 1904 1905 $this->check_current_query = false; 1906 return $this->query( $this->prepare( $sql, $values ) ); 1907 } 1908 1909 /** 1910 * Processes arrays of field/value pairs and field formats. 1911 * 1912 * This is a helper method for wpdb's CRUD methods, which take field/value 1913 * pairs for inserts, updates, and where clauses. This method first pairs 1914 * each value with a format. Then it determines the charset of that field, 1915 * using that to determine if any invalid text would be stripped. If text is 1916 * stripped, then field processing is rejected and the query fails. 1917 * 1918 * @since 4.2.0 1919 * @access protected 1920 * 1921 * @param string $table Table name. 1922 * @param array $data Field/value pair. 1923 * @param mixed $format Format for each field. 1924 * @return array|bool Returns an array of fields that contain paired values 1925 * and formats. Returns false for invalid values. 1926 */ 1927 protected function process_fields( $table, $data, $format ) { 1928 $data = $this->process_field_formats( $data, $format ); 1929 $data = $this->process_field_charsets( $data, $table ); 1930 if ( false === $data ) { 1931 return false; 1932 } 1933 1934 $converted_data = $this->strip_invalid_text( $data ); 1935 1936 if ( $data !== $converted_data ) { 1937 return false; 1938 } 1939 1940 return $data; 1941 } 1942 1943 /** 1944 * Prepares arrays of value/format pairs as passed to wpdb CRUD methods. 1945 * 1946 * @since 4.2.0 1947 * @access protected 1948 * 1949 * @param array $data Array of fields to values. 1950 * @param mixed $format Formats to be mapped to the values in $data. 1951 * @return array Array, keyed by field names with values being an array 1952 * of 'value' and 'format' keys. 1953 */ 1954 protected function process_field_formats( $data, $format ) { 1955 $formats = $original_formats = (array) $format; 1956 1957 foreach ( $data as $field => $value ) { 1958 $value = array( 1959 'value' => $value, 1960 'format' => '%s', 1961 ); 1962 1963 if ( ! empty( $format ) ) { 1964 $value['format'] = array_shift( $formats ); 1965 if ( ! $value['format'] ) { 1966 $value['format'] = reset( $original_formats ); 1967 } 1829 1968 } elseif ( isset( $this->field_types[ $field ] ) ) { 1830 $form = $this->field_types[ $field ]; 1969 $value['format'] = $this->field_types[ $field ]; 1970 } 1971 1972 $data[ $field ] = $value; 1973 } 1974 1975 return $data; 1976 } 1977 1978 /** 1979 * Adds field charsets to field/value/format arrays generated by 1980 * the {@see wpdb::process_field_formats()} method. 1981 * 1982 * @since 4.2.0 1983 * @access protected 1984 * 1985 * @param array $data As it comes from the {@see wpdb::process_field_formats()} method. 1986 * @param string $table Table name. 1987 * @return The same array as $data with additional 'charset' keys. 1988 */ 1989 protected function process_field_charsets( $data, $table ) { 1990 foreach ( $data as $field => $value ) { 1991 if ( '%d' === $value['format'] || '%f' === $value['format'] ) { 1992 // We can skip this field if we know it isn't a string. 1993 // This checks %d/%f versus ! %s because it's sprintf() could take more. 1994 $value['charset'] = false; 1995 } elseif ( $this->check_ascii( $value['value'] ) ) { 1996 // If it's ASCII, then we don't need the charset. We can skip this field. 1997 $value['charset'] = false; 1831 1998 } else { 1832 $form = '%s'; 1833 } 1834 1835 $wheres[] = "$field = $form"; 1836 } 1837 1838 $sql = "DELETE FROM $table WHERE " . implode( ' AND ', $wheres ); 1839 return $this->query( $this->prepare( $sql, $where ) ); 1999 $value['charset'] = $this->get_col_charset( $table, $field ); 2000 if ( is_wp_error( $value['charset'] ) ) { 2001 return false; 2002 } 2003 2004 // This isn't ASCII. Don't have strip_invalid_text() re-check. 2005 $value['ascii'] = false; 2006 } 2007 2008 $data[ $field ] = $value; 2009 } 2010 2011 return $data; 1840 2012 } 1841 2013 … … 1856 2028 public function get_var( $query = null, $x = 0, $y = 0 ) { 1857 2029 $this->func_call = "\$db->get_var(\"$query\", $x, $y)"; 2030 2031 if ( $this->check_safe_collation( $query ) ) { 2032 $this->check_current_query = false; 2033 } 1858 2034 1859 2035 if ( $query ) { … … 1885 2061 public function get_row( $query = null, $output = OBJECT, $y = 0 ) { 1886 2062 $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; 2063 2064 if ( $this->check_safe_collation( $query ) ) { 2065 $this->check_current_query = false; 2066 } 2067 1887 2068 if ( $query ) { 1888 2069 $this->query( $query ); … … 1922 2103 */ 1923 2104 public function get_col( $query = null , $x = 0 ) { 2105 if ( $this->check_safe_collation( $query ) ) { 2106 $this->check_current_query = false; 2107 } 2108 1924 2109 if ( $query ) { 1925 2110 $this->query( $query ); … … 1949 2134 public function get_results( $query = null, $output = OBJECT ) { 1950 2135 $this->func_call = "\$db->get_results(\"$query\", $output)"; 2136 2137 if ( $this->check_safe_collation( $query ) ) { 2138 $this->check_current_query = false; 2139 } 1951 2140 1952 2141 if ( $query ) { … … 1992 2181 1993 2182 /** 2183 * Retrieves the character set for the given table. 2184 * 2185 * @since 4.2.0 2186 * @access protected 2187 * 2188 * @param string $table Table name. 2189 * @return string|WP_Error Table character set, {@see WP_Error} object if it couldn't be found. 2190 */ 2191 protected function get_table_charset( $table ) { 2192 $tablekey = strtolower( $table ); 2193 2194 /** 2195 * Filter the table charset value before the DB is checked. 2196 * 2197 * Passing a non-null value to the filter will effectively short-circuit 2198 * checking the DB for the charset, returning that value instead. 2199 * 2200 * @since 4.2.0 2201 * 2202 * @param string $charset The character set to use. Default null. 2203 * @param string $table The name of the table being checked. 2204 */ 2205 $charset = apply_filters( 'pre_get_table_charset', null, $table ); 2206 if ( null !== $charset ) { 2207 return $charset; 2208 } 2209 2210 if ( isset( $this->table_charset[ $tablekey ] ) ) { 2211 return $this->table_charset[ $tablekey ]; 2212 } 2213 2214 $charsets = $columns = array(); 2215 $results = $this->get_results( "SHOW FULL COLUMNS FROM `$table`" ); 2216 if ( ! $results ) { 2217 return new WP_Error( 'wpdb_get_table_charset_failure' ); 2218 } 2219 2220 foreach ( $results as $column ) { 2221 $columns[ strtolower( $column->Field ) ] = $column; 2222 } 2223 2224 $this->col_meta[ $tablekey ] = $columns; 2225 2226 foreach ( $columns as $column ) { 2227 if ( ! empty( $column->Collation ) ) { 2228 list( $charset ) = explode( '_', $column->Collation ); 2229 $charsets[ strtolower( $charset ) ] = true; 2230 } 2231 2232 list( $type ) = explode( '(', $column->Type ); 2233 2234 // A binary/blob means the whole query gets treated like this. 2235 if ( in_array( strtoupper( $type ), array( 'BINARY', 'VARBINARY', 'TINYBLOB', 'MEDIUMBLOB', 'BLOB', 'LONGBLOB' ) ) ) { 2236 $this->table_charset[ $tablekey ] = 'binary'; 2237 return 'binary'; 2238 } 2239 } 2240 2241 // utf8mb3 is an alias for utf8. 2242 if ( isset( $charsets['utf8mb3'] ) ) { 2243 $charsets['utf8'] = true; 2244 unset( $charsets['utf8mb3'] ); 2245 } 2246 2247 // Check if we have more than one charset in play. 2248 $count = count( $charsets ); 2249 if ( 1 === $count ) { 2250 $charset = key( $charsets ); 2251 } elseif ( 0 === $count ) { 2252 // No charsets, assume this table can store whatever. 2253 $charset = false; 2254 } else { 2255 // More than one charset. Remove latin1 if present and recalculate. 2256 unset( $charsets['latin1'] ); 2257 $count = count( $charsets ); 2258 if ( 1 === $count ) { 2259 // Only one charset (besides latin1). 2260 $charset = key( $charsets ); 2261 } elseif ( 2 === $count && isset( $charsets['utf8'], $charsets['utf8mb4'] ) ) { 2262 // Two charsets, but they're utf8 and utf8mb4, use utf8. 2263 $charset = 'utf8'; 2264 } else { 2265 // Two mixed character sets. ascii. 2266 $charset = 'ascii'; 2267 } 2268 } 2269 2270 $this->table_charset[ $tablekey ] = $charset; 2271 return $charset; 2272 } 2273 2274 /** 2275 * Retrieves the character set for the given column. 2276 * 2277 * @since 4.2.0 2278 * @access public 2279 * 2280 * @param string $table Table name. 2281 * @param string $column Column name. 2282 * @return mixed Column character set as a string. False if the column has no 2283 * character set. {@see WP_Error} object if there was an error. 2284 */ 2285 public function get_col_charset( $table, $column ) { 2286 $tablekey = strtolower( $table ); 2287 $columnkey = strtolower( $column ); 2288 2289 /** 2290 * Filter the column charset value before the DB is checked. 2291 * 2292 * Passing a non-null value to the filter will short-circuit 2293 * checking the DB for the charset, returning that value instead. 2294 * 2295 * @since 4.2.0 2296 * 2297 * @param string $charset The character set to use. Default null. 2298 * @param string $table The name of the table being checked. 2299 * @param string $column The name of the column being checked. 2300 */ 2301 $charset = apply_filters( 'pre_get_col_charset', null, $table, $column ); 2302 if ( null !== $charset ) { 2303 return $charset; 2304 } 2305 2306 // Skip this entirely if this isn't a MySQL database. 2307 if ( false === $this->is_mysql ) { 2308 return false; 2309 } 2310 2311 if ( empty( $this->table_charset[ $tablekey ] ) ) { 2312 // This primes column information for us. 2313 $table_charset = $this->get_table_charset( $table ); 2314 if ( is_wp_error( $table_charset ) ) { 2315 return $table_charset; 2316 } 2317 } 2318 2319 // If still no column information, return the table charset. 2320 if ( empty( $this->col_meta[ $tablekey ] ) ) { 2321 return $this->table_charset[ $tablekey ]; 2322 } 2323 2324 // If this column doesn't exist, return the table charset. 2325 if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) { 2326 return $this->table_charset[ $tablekey ]; 2327 } 2328 2329 // Return false when it's not a string column. 2330 if ( empty( $this->col_meta[ $tablekey ][ $columnkey ]->Collation ) ) { 2331 return false; 2332 } 2333 2334 list( $charset ) = explode( '_', $this->col_meta[ $tablekey ][ $columnkey ]->Collation ); 2335 return $charset; 2336 } 2337 2338 /** 2339 * Check if a string is ASCII. 2340 * 2341 * The negative regex is faster for non-ASCII strings, as it allows 2342 * the search to finish as soon as it encounters a non-ASCII character. 2343 * 2344 * @since 4.2.0 2345 * @access protected 2346 * 2347 * @param string $string String to check. 2348 * @return bool True if ASCII, false if not. 2349 */ 2350 protected function check_ascii( $string ) { 2351 if ( function_exists( 'mb_check_encoding' ) ) { 2352 if ( mb_check_encoding( $string, 'ASCII' ) ) { 2353 return true; 2354 } 2355 } elseif ( ! preg_match( '/[^\x00-\x7F]/', $string ) ) { 2356 return true; 2357 } 2358 2359 return false; 2360 } 2361 2362 /** 2363 * Check if the query is accessing a collation considered safe on the current version of MySQL. 2364 * 2365 * @since 4.2.0 2366 * @access protected 2367 * 2368 * @param string $query The query to check. 2369 * @return bool True if the collation is safe, false if it isn't. 2370 */ 2371 protected function check_safe_collation( $query ) { 2372 if ( $this->checking_collation ) { 2373 return true; 2374 } 2375 2376 // We don't need to check the collation for queries that don't read data. 2377 $query = ltrim( $query, "\r\n\t (" ); 2378 if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN)\s/i', $query ) ) { 2379 return true; 2380 } 2381 2382 // All-ASCII queries don't need extra checking. 2383 if ( $this->check_ascii( $query ) ) { 2384 return true; 2385 } 2386 2387 $table = $this->get_table_from_query( $query ); 2388 if ( ! $table ) { 2389 return false; 2390 } 2391 2392 $this->checking_collation = true; 2393 $collation = $this->get_table_charset( $table ); 2394 $this->checking_collation = false; 2395 2396 // Tables with no collation, or latin1 only, don't need extra checking. 2397 if ( false === $collation || 'latin1' === $collation ) { 2398 return true; 2399 } 2400 2401 $table = strtolower( $table ); 2402 if ( empty( $this->col_meta[ $table ] ) ) { 2403 return false; 2404 } 2405 2406 // If any of the columns don't have one of these collations, it needs more sanity checking. 2407 foreach( $this->col_meta[ $table ] as $col ) { 2408 if ( empty( $col->Collation ) ) { 2409 continue; 2410 } 2411 2412 if ( ! in_array( $col->Collation, array( 'utf8_general_ci', 'utf8_bin', 'utf8mb4_general_ci', 'utf8mb4_bin' ), true ) ) { 2413 return false; 2414 } 2415 } 2416 2417 return true; 2418 } 2419 2420 /** 2421 * Strips any invalid characters based on value/charset pairs. 2422 * 2423 * @since 4.2.0 2424 * @access protected 2425 * 2426 * @param array $data Array of value arrays. Each value array has the keys 2427 * 'value' and 'charset'. An optional 'ascii' key can be 2428 * set to false to avoid redundant ASCII checks. 2429 * @return array|WP_Error The $data parameter, with invalid characters removed from 2430 * each value. This works as a passthrough: any additional keys 2431 * such as 'field' are retained in each value array. If we cannot 2432 * remove invalid characters, a {@see WP_Error} object is returned. 2433 */ 2434 // If any of the columns don't have one of these collations, it needs more sanity checking. 2435 protected function strip_invalid_text( $data ) { 2436 // Some multibyte character sets that we can check in PHP. 2437 $mb_charsets = array( 2438 'ascii' => 'ASCII', 2439 'big5' => 'BIG-5', 2440 'eucjpms' => 'eucJP-win', 2441 'gb2312' => 'EUC-CN', 2442 'ujis' => 'EUC-JP', 2443 'utf32' => 'UTF-32', 2444 ); 2445 2446 $supported_charsets = array(); 2447 if ( function_exists( 'mb_list_encodings' ) ) { 2448 $supported_charsets = mb_list_encodings(); 2449 } 2450 2451 $db_check_string = false; 2452 2453 foreach ( $data as &$value ) { 2454 $charset = $value['charset']; 2455 2456 // Column isn't a string, or is latin1, which will will happily store anything. 2457 if ( false === $charset || 'latin1' === $charset ) { 2458 continue; 2459 } 2460 2461 if ( ! is_string( $value['value'] ) ) { 2462 continue; 2463 } 2464 2465 // ASCII is always OK. 2466 if ( ! isset( $value['ascii'] ) && $this->check_ascii( $value['value'] ) ) { 2467 continue; 2468 } 2469 2470 // Convert the text locally. 2471 if ( $supported_charsets ) { 2472 if ( isset( $mb_charsets[ $charset ] ) && in_array( $mb_charsets[ $charset ], $supported_charsets ) ) { 2473 $value['value'] = mb_convert_encoding( $value['value'], $mb_charsets[ $charset ], $mb_charsets[ $charset ] ); 2474 continue; 2475 } 2476 } 2477 2478 // utf8 can be handled by regex, which is a bunch faster than a DB lookup. 2479 if ( 'utf8' === $charset || 'utf8mb3' === $charset || 'utf8mb4' === $charset ) { 2480 $regex = '/ 2481 ( 2482 (?: [\x00-\x7F] # single-byte sequences 0xxxxxxx 2483 | [\xC2-\xDF][\x80-\xBF] # double-byte sequences 110xxxxx 10xxxxxx 2484 | \xE0[\xA0-\xBF][\x80-\xBF] # triple-byte sequences 1110xxxx 10xxxxxx * 2 2485 | [\xE1-\xEC][\x80-\xBF]{2} 2486 | \xED[\x80-\x9F][\x80-\xBF] 2487 | [\xEE-\xEF][\x80-\xBF]{2}'; 2488 2489 if ( 'utf8mb4' === $charset) { 2490 $regex .= ' 2491 | \xF0[\x90-\xBF][\x80-\xBF]{2} # four-byte sequences 11110xxx 10xxxxxx * 3 2492 | [\xF1-\xF3][\x80-\xBF]{3} 2493 | \xF4[\x80-\x8F][\x80-\xBF]{2} 2494 '; 2495 } 2496 2497 $regex .= '){1,50} # ...one or more times 2498 ) 2499 | . # anything else 2500 /x'; 2501 $value['value'] = preg_replace( $regex, '$1', $value['value'] ); 2502 continue; 2503 } 2504 2505 // We couldn't use any local conversions, send it to the DB. 2506 $value['db'] = $db_check_string = true; 2507 } 2508 unset( $value ); // Remove by reference. 2509 2510 if ( $db_check_string ) { 2511 $queries = array(); 2512 foreach ( $data as $col => $value ) { 2513 if ( ! empty( $value['db'] ) ) { 2514 if ( ! isset( $queries[ $value['charset'] ] ) ) { 2515 $queries[ $value['charset'] ] = array(); 2516 } 2517 2518 // Split the CONVERT() calls by charset, so we can make sure the connection is right 2519 $queries[ $value['charset'] ][ $col ] = $this->prepare( "CONVERT( %s USING {$value['charset']} )", $value['value'] ); 2520 } 2521 } 2522 2523 $connection_charset = $this->charset; 2524 foreach ( $queries as $charset => $query ) { 2525 if ( ! $query ) { 2526 continue; 2527 } 2528 2529 // Change the charset to match the string(s) we're converting 2530 if ( $charset !== $connection_charset ) { 2531 $connection_charset = $charset; 2532 $this->set_charset( $this->dbh, $charset ); 2533 } 2534 2535 $this->check_current_query = false; 2536 2537 $row = $this->get_row( "SELECT " . implode( ', ', $query ), ARRAY_N ); 2538 if ( ! $row ) { 2539 $this->set_charset( $this->dbh, $connection_charset ); 2540 return new WP_Error( 'wpdb_strip_invalid_text_failure' ); 2541 } 2542 2543 $cols = array_keys( $query ); 2544 $col_count = count( $cols ); 2545 for ( $ii = 0; $ii < $col_count; $ii++ ) { 2546 $data[ $cols[ $ii ] ]['value'] = $row[ $ii ]; 2547 } 2548 } 2549 2550 // Don't forget to change the charset back! 2551 if ( $connection_charset !== $this->charset ) { 2552 $this->set_charset( $this->dbh ); 2553 } 2554 } 2555 2556 return $data; 2557 } 2558 2559 /** 2560 * Strips any invalid characters from the query. 2561 * 2562 * @since 4.2.0 2563 * @access protected 2564 * 2565 * @param string $query Query to convert. 2566 * @return string|WP_Error The converted query, or a {@see WP_Error} object if the conversion fails. 2567 */ 2568 protected function strip_invalid_text_from_query( $query ) { 2569 $table = $this->get_table_from_query( $query ); 2570 if ( $table ) { 2571 $charset = $this->get_table_charset( $table ); 2572 if ( is_wp_error( $charset ) ) { 2573 return $charset; 2574 } 2575 2576 // We can't reliably strip text from tables containing binary/blob columns 2577 if ( 'binary' === $charset ) { 2578 return $query; 2579 } 2580 } else { 2581 $charset = $this->charset; 2582 } 2583 2584 $data = array( 2585 'value' => $query, 2586 'charset' => $charset, 2587 'ascii' => false, 2588 ); 2589 2590 $data = $this->strip_invalid_text( array( $data ) ); 2591 if ( is_wp_error( $data ) ) { 2592 return $data; 2593 } 2594 2595 return $data[0]['value']; 2596 } 2597 2598 /** 2599 * Strips any invalid characters from the string for a given table and column. 2600 * 2601 * @since 4.2.0 2602 * @access public 2603 * 2604 * @param string $table Table name. 2605 * @param string $column Column name. 2606 * @param string $value The text to check. 2607 * @return string|WP_Error The converted string, or a `WP_Error` object if the conversion fails. 2608 */ 2609 public function strip_invalid_text_for_column( $table, $column, $value ) { 2610 if ( ! is_string( $value ) || $this->check_ascii( $value ) ) { 2611 return $value; 2612 } 2613 2614 $charset = $this->get_col_charset( $table, $column ); 2615 if ( ! $charset ) { 2616 // Not a string column. 2617 return $value; 2618 } elseif ( is_wp_error( $charset ) ) { 2619 // Bail on real errors. 2620 return $charset; 2621 } 2622 2623 $data = array( 2624 $column => array( 2625 'value' => $value, 2626 'charset' => $charset, 2627 'ascii' => false, 2628 ) 2629 ); 2630 2631 $data = $this->strip_invalid_text( $data ); 2632 if ( is_wp_error( $data ) ) { 2633 return $data; 2634 } 2635 2636 return $data[ $column ]['value']; 2637 } 2638 2639 /** 2640 * Find the first table name referenced in a query. 2641 * 2642 * @since 4.2.0 2643 * @access protected 2644 * 2645 * @param string $query The query to search. 2646 * @return string|false $table The table name found, or false if a table couldn't be found. 2647 */ 2648 protected function get_table_from_query( $query ) { 2649 // Remove characters that can legally trail the table name. 2650 $query = rtrim( $query, ';/-#' ); 2651 2652 // Allow (select...) union [...] style queries. Use the first query's table name. 2653 $query = ltrim( $query, "\r\n\t (" ); 2654 2655 /* 2656 * Strip everything between parentheses except nested selects and use only 1,000 2657 * chars of the query. 2658 */ 2659 $query = preg_replace( '/\((?!\s*select)[^(]*?\)/is', '()', substr( $query, 0, 1000 ) ); 2660 2661 // Quickly match most common queries. 2662 if ( preg_match( '/^\s*(?:' 2663 . 'SELECT.*?\s+FROM' 2664 . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?' 2665 . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?' 2666 . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?' 2667 . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?' 2668 . ')\s+`?([\w-]+)`?/is', $query, $maybe ) ) { 2669 return $maybe[1]; 2670 } 2671 2672 // SHOW TABLE STATUS and SHOW TABLES 2673 if ( preg_match( '/^\s*(?:' 2674 . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' 2675 . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' 2676 . ')\W([\w-]+)\W/is', $query, $maybe ) ) { 2677 return $maybe[1]; 2678 } 2679 2680 // Big pattern for the rest of the table-related queries. 2681 if ( preg_match( '/^\s*(?:' 2682 . '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM' 2683 . '|DESCRIBE|DESC|EXPLAIN|HANDLER' 2684 . '|(?:LOCK|UNLOCK)\s+TABLE(?:S)?' 2685 . '|(?:RENAME|OPTIMIZE|BACKUP|RESTORE|CHECK|CHECKSUM|ANALYZE|REPAIR).*\s+TABLE' 2686 . '|TRUNCATE(?:\s+TABLE)?' 2687 . '|CREATE(?:\s+TEMPORARY)?\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?' 2688 . '|ALTER(?:\s+IGNORE)?\s+TABLE' 2689 . '|DROP\s+TABLE(?:\s+IF\s+EXISTS)?' 2690 . '|CREATE(?:\s+\w+)?\s+INDEX.*\s+ON' 2691 . '|DROP\s+INDEX.*\s+ON' 2692 . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE' 2693 . '|(?:GRANT|REVOKE).*ON\s+TABLE' 2694 . '|SHOW\s+(?:.*FROM|.*TABLE)' 2695 . ')\s+\(*\s*`?([\w-]+)`?\s*\)*/is', $query, $maybe ) ) { 2696 return $maybe[1]; 2697 } 2698 2699 return false; 2700 } 2701 2702 /** 1994 2703 * Load the column metadata from the last query. 1995 2704 * -
tags/4.1.2/tests/phpunit/tests/admin/includesScreen.php
r61362 r61362 38 38 39 39 function tearDown() { 40 parent::tearDown();41 40 unset( $GLOBALS['wp_taxonomies']['old-or-new'] ); 42 41 set_current_screen( 'front' ); 42 parent::tearDown(); 43 43 } 44 44 -
tags/4.1.2/tests/phpunit/tests/ajax/Autosave.php
r61362 r61362 47 47 */ 48 48 public function tearDown() { 49 wp_set_current_user( 0 ); 49 50 parent::tearDown(); 50 wp_set_current_user( 0 );51 51 } 52 52 -
tags/4.1.2/tests/phpunit/tests/ajax/Response.php
r61362 r61362 37 37 */ 38 38 public function tearDown() { 39 parent::tearDown();40 39 remove_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 ); 41 40 error_reporting( $this->_error_level ); 41 parent::tearDown(); 42 42 } 43 43 -
tags/4.1.2/tests/phpunit/tests/basic.php
r61362 r61362 14 14 15 15 function tearDown() { 16 $this->val = false; 16 17 parent::tearDown(); 17 $this->val = false;18 18 } 19 19 -
tags/4.1.2/tests/phpunit/tests/cache.php
r61362 r61362 15 15 16 16 function tearDown() { 17 $this->flush_cache(); 17 18 parent::tearDown(); 18 $this->flush_cache();19 19 } 20 20 -
tags/4.1.2/tests/phpunit/tests/canonical.php
r61362 r61362 24 24 25 25 public function tearDown() { 26 wp_set_current_user( self::$old_current_user ); 26 27 parent::tearDown(); 27 wp_set_current_user( self::$old_current_user );28 28 } 29 29 -
tags/4.1.2/tests/phpunit/tests/canonical/pageOnFront.php
r61362 r61362 27 27 function tearDown() { 28 28 global $wp_rewrite; 29 $wp_rewrite->init(); 29 30 parent::tearDown(); 30 $wp_rewrite->init();31 31 } 32 32 -
tags/4.1.2/tests/phpunit/tests/category.php
r61362 r61362 11 11 12 12 function tearDown() { 13 _unregister_taxonomy( 'test_tax_cat' ); 13 14 parent::tearDown(); 14 15 _unregister_taxonomy( 'test_tax_cat' );16 15 } 17 16 -
tags/4.1.2/tests/phpunit/tests/comment/getCommentsPagesCount.php
r61362 r61362 27 27 */ 28 28 function tearDown() { 29 parent::tearDown();30 29 update_option( 'page_comments', $this->option_page_comments ); 31 30 update_option( 'comments_per_page', $this->option_page_comments ); 32 31 update_option( 'thread_comments', $this->option_page_comments ); 33 32 update_option( 'posts_per_rss', $this->option_posts_per_rss ); 33 parent::tearDown(); 34 34 } 35 35 -
tags/4.1.2/tests/phpunit/tests/cron.php
r61362 r61362 14 14 15 15 function tearDown() { 16 parent::tearDown();17 16 // make sure the schedule is clear 18 17 _set_cron_array(array()); 18 parent::tearDown(); 19 19 } 20 20 -
tags/4.1.2/tests/phpunit/tests/customize/manager.php
r61362 r61362 17 17 18 18 function tearDown() { 19 parent::tearDown();20 19 $this->manager = null; 21 20 unset( $GLOBALS['wp_customize'] ); 21 parent::tearDown(); 22 22 } 23 23 -
tags/4.1.2/tests/phpunit/tests/customize/setting.php
r61362 r61362 27 27 28 28 function tearDown() { 29 parent::tearDown();30 29 $this->manager = null; 31 30 unset( $GLOBALS['wp_customize'] ); 31 parent::tearDown(); 32 32 } 33 33 -
tags/4.1.2/tests/phpunit/tests/db.php
r61362 r61362 233 233 $this->assertNotEmpty( $wpdb->dbh ); 234 234 } 235 236 /** 237 * @ticket 21212 238 */ 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 235 251 /** 236 252 * @ticket 18510 … … 505 521 $wpdb->suppress_errors( $suppress ); 506 522 } 523 524 /** 525 * @ticket 21212 526 */ 527 function data_get_table_from_query() { 528 $table = 'a_test_table_name'; 529 530 $queries = array( 531 // Basic 532 "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 // STATUS 565 "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 // Extended 573 "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_query 639 * @ticket 21212 640 */ 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_false 654 * @ticket 21212 655 */ 656 function test_get_table_from_query_false( $query ) { 657 $this->assertFalse( self::$_wpdb->get_table_from_query( $query ) ); 658 } 659 660 /** 661 * @ticket 21212 662 */ 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_types 676 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 third 703 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 $message 712 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_formats 720 * @ticket 21212 721 */ 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 21212 729 */ 730 function test_process_fields() { 731 global $wpdb; 732 733 if ( $wpdb->charset ) { 734 $expected_charset = $wpdb->charset; 735 } else { 736 $expected_charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' ); 737 } 738 739 if ( ! in_array( $expected_charset, array( 'utf8', 'utf8mb4', 'latin1' ) ) ) { 740 $this->markTestSkipped( "This test only works with utf8, utf8mb4 or latin1 character sets" ); 741 } 742 743 $data = array( 'post_content' => '¡foo foo foo!' ); 744 $expected = array( 745 'post_content' => array( 746 'value' => '¡foo foo foo!', 747 'format' => '%s', 748 'charset' => $expected_charset, 749 'ascii' => false, 750 ) 751 ); 752 753 $this->assertSame( $expected, self::$_wpdb->process_fields( $wpdb->posts, $data, null ) ); 754 } 755 756 /** 757 * @ticket 21212 758 * @depends test_process_fields 759 */ 760 function test_process_fields_on_nonexistent_table( $data ) { 761 self::$_wpdb->suppress_errors( true ); 762 $data = array( 'post_content' => '¡foo foo foo!' ); 763 $this->assertFalse( self::$_wpdb->process_fields( 'nonexistent_table', $data, null ) ); 764 self::$_wpdb->suppress_errors( false ); 765 } 766 767 /** 768 * @ticket 21212 769 */ 770 function test_pre_get_table_charset_filter() { 771 add_filter( 'pre_get_table_charset', array( $this, 'filter_pre_get_table_charset' ), 10, 2 ); 772 $charset = self::$_wpdb->get_table_charset( 'some_table' ); 773 remove_filter( 'pre_get_table_charset', array( $this, 'filter_pre_get_table_charset' ), 10 ); 774 775 $this->assertEquals( $charset, 'fake_charset' ); 776 } 777 function filter_pre_get_table_charset( $charset, $table ) { 778 return 'fake_charset'; 779 } 780 781 /** 782 * @ticket 21212 783 */ 784 function test_pre_get_col_charset_filter() { 785 add_filter( 'pre_get_col_charset', array( $this, 'filter_pre_get_col_charset' ), 10, 3 ); 786 $charset = self::$_wpdb->get_col_charset( 'some_table', 'some_col' ); 787 remove_filter( 'pre_get_col_charset', array( $this, 'filter_pre_get_col_charset' ), 10 ); 788 789 $this->assertEquals( $charset, 'fake_col_charset' ); 790 } 791 function filter_pre_get_col_charset( $charset, $table, $column ) { 792 return 'fake_col_charset'; 793 } 507 794 } 508 795 -
tags/4.1.2/tests/phpunit/tests/db/charset.php
r61362 r61362 1 <?php 2 3 require_once dirname( dirname( __FILE__ ) ) . '/db.php'; 4 5 /** 6 * Test WPDB methods 7 * 8 * @group wpdb 9 */ 10 class Tests_DB_Charset extends WP_UnitTestCase { 11 12 /** 13 * Our special WPDB 14 * @var resource 15 */ 16 protected static $_wpdb; 17 18 public static function setUpBeforeClass() { 19 self::$_wpdb = new wpdb_exposed_methods_for_testing(); 20 } 21 22 /** 23 * @ticket 21212 24 */ 25 function data_strip_invalid_text() { 26 $fields = array( 27 'latin1' => array( 28 // latin1. latin1 never changes. 29 'charset' => 'latin1', 30 'value' => "\xf0\x9f\x8e\xb7", 31 'expected' => "\xf0\x9f\x8e\xb7" 32 ), 33 'ascii' => array( 34 // ascii gets special treatment, make sure it's covered 35 'charset' => 'ascii', 36 'value' => 'Hello World', 37 'expected' => 'Hello World' 38 ), 39 'utf8' => array( 40 // utf8 only allows <= 3-byte chars 41 'charset' => 'utf8', 42 'value' => "H€llo\xf0\x9f\x98\x88World¢", 43 'expected' => 'H€lloWorld¢' 44 ), 45 'utf8mb3' => array( 46 // utf8mb3 should behave the same an utf8 47 'charset' => 'utf8mb3', 48 'value' => "H€llo\xf0\x9f\x98\x88World¢", 49 'expected' => 'H€lloWorld¢' 50 ), 51 'utf8mb4' => array( 52 // utf8mb4 allows 4-byte characters, too 53 'charset' => 'utf8mb4', 54 'value' => "H€llo\xf0\x9f\x98\x88World¢", 55 'expected' => "H€llo\xf0\x9f\x98\x88World¢" 56 ), 57 'koi8r' => array( 58 // koi8r is a character set that needs to be checked in MySQL 59 'charset' => 'koi8r', 60 'value' => "\xfdord\xf2ress", 61 'expected' => "\xfdord\xf2ress", 62 'db' => true 63 ), 64 'hebrew' => array( 65 // hebrew needs to be checked in MySQL, too 66 'charset' => 'hebrew', 67 'value' => "\xf9ord\xf7ress", 68 'expected' => "\xf9ord\xf7ress", 69 'db' => true 70 ), 71 'false' => array( 72 // false is a column with no character set (ie, a number column) 73 'charset' => false, 74 'value' => 100, 75 'expected' => 100 76 ), 77 ); 78 79 if ( function_exists( 'mb_convert_encoding' ) ) { 80 // big5 is a non-Unicode multibyte charset 81 $utf8 = "a\xe5\x85\xb1b"; // UTF-8 Character 20849 82 $big5 = mb_convert_encoding( $utf8, 'BIG-5', 'UTF-8' ); 83 $conv_utf8 = mb_convert_encoding( $big5, 'UTF-8', 'BIG-5' ); 84 // Make sure PHP's multibyte conversions are working correctly 85 $this->assertNotEquals( $utf8, $big5 ); 86 $this->assertEquals( $utf8, $conv_utf8 ); 87 88 $fields['big5'] = array( 89 'charset' => 'big5', 90 'value' => $big5, 91 'expected' => $big5 92 ); 93 } 94 95 // The data above is easy to edit. Now, prepare it for the data provider. 96 $data_provider = $multiple = $multiple_expected = array(); 97 foreach ( $fields as $test_case => $field ) { 98 $expected = $field; 99 $expected['value'] = $expected['expected']; 100 unset( $expected['expected'], $field['expected'] ); 101 102 // We're keeping track of these for our multiple-field test. 103 $multiple[] = $field; 104 $multiple_expected[] = $expected; 105 106 // strip_invalid_text() expects an array of fields. We're testing one field at a time. 107 $data = array( $field ); 108 $expected = array( $expected ); 109 110 // First argument is field data. Second is expected. Third is the message. 111 $data_provider[] = array( $data, $expected, $test_case ); 112 } 113 114 // Time for our test of multiple fields at once. 115 $data_provider[] = array( $multiple, $multiple_expected, 'multiple fields/charsets' ); 116 117 return $data_provider; 118 } 119 120 /** 121 * @dataProvider data_strip_invalid_text 122 * @ticket 21212 123 */ 124 function test_strip_invalid_text( $data, $expected, $message ) { 125 $actual = self::$_wpdb->strip_invalid_text( $data ); 126 $this->assertSame( $expected, $actual, $message ); 127 } 128 129 /** 130 * @ticket 21212 131 */ 132 function test_process_fields_failure() { 133 global $wpdb; 134 135 $charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' ); 136 if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) { 137 $this->markTestSkipped( 'This test requires a utf8 character set' ); 138 } 139 140 // \xf0\xff\xff\xff is invalid in utf8 and utf8mb4. 141 $data = array( 'post_content' => "H€llo\xf0\xff\xff\xffWorld¢" ); 142 $this->assertFalse( self::$_wpdb->process_fields( $wpdb->posts, $data, null ) ); 143 } 144 145 /** 146 * @ticket 21212 147 */ 148 function data_process_field_charsets() { 149 if ( $GLOBALS['wpdb']->charset ) { 150 $charset = $GLOBALS['wpdb']->charset; 151 } else { 152 $charset = $GLOBALS['wpdb']->get_col_charset( $GLOBALS['wpdb']->posts, 'post_content' ); 153 } 154 155 // 'value' and 'format' are $data, 'charset' ends up as part of $expected 156 157 $no_string_fields = array( 158 'post_parent' => array( 'value' => 10, 'format' => '%d', 'charset' => false ), 159 'comment_count' => array( 'value' => 0, 'format' => '%d', 'charset' => false ), 160 ); 161 162 $all_ascii_fields = array( 163 'post_content' => array( 'value' => 'foo foo foo!', 'format' => '%s', 'charset' => false ), 164 'post_excerpt' => array( 'value' => 'bar bar bar!', 'format' => '%s', 'charset' => false ), 165 ); 166 167 // This is the same data used in process_field_charsets_for_nonexistent_table() 168 $non_ascii_string_fields = array( 169 'post_content' => array( 'value' => '¡foo foo foo!', 'format' => '%s', 'charset' => $charset, 'ascii' => false ), 170 'post_excerpt' => array( 'value' => '¡bar bar bar!', 'format' => '%s', 'charset' => $charset, 'ascii' => false ), 171 ); 172 173 $vars = get_defined_vars(); 174 unset( $vars['charset'] ); 175 foreach ( $vars as $var_name => $var ) { 176 $data = $expected = $var; 177 foreach ( $data as &$datum ) { 178 // 'charset' and 'ascii' are part of the expected return only. 179 unset( $datum['charset'], $datum['ascii'] ); 180 } 181 182 $vars[ $var_name ] = array( $data, $expected, $var_name ); 183 } 184 185 return array_values( $vars ); 186 } 187 188 /** 189 * @dataProvider data_process_field_charsets 190 * @ticket 21212 191 */ 192 function test_process_field_charsets( $data, $expected, $message ) { 193 $actual = self::$_wpdb->process_field_charsets( $data, $GLOBALS['wpdb']->posts ); 194 $this->assertSame( $expected, $actual, $message ); 195 } 196 197 /** 198 * The test this test depends on first verifies that this 199 * would normally work against the posts table. 200 * 201 * @ticket 21212 202 * @depends test_process_field_charsets 203 */ 204 function test_process_field_charsets_on_nonexistent_table() { 205 $data = array( 'post_content' => array( 'value' => '¡foo foo foo!', 'format' => '%s' ) ); 206 self::$_wpdb->suppress_errors( true ); 207 $this->assertFalse( self::$_wpdb->process_field_charsets( $data, 'nonexistent_table' ) ); 208 self::$_wpdb->suppress_errors( false ); 209 } 210 211 /** 212 * @ticket 21212 213 */ 214 function test_check_ascii() { 215 $ascii = "\0\t\n\r '" . '!"#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'; 216 $this->assertTrue( self::$_wpdb->check_ascii( $ascii ) ); 217 } 218 219 /** 220 * @ticket 21212 221 */ 222 function test_check_ascii_false() { 223 $this->assertFalse( self::$_wpdb->check_ascii( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ¡©«' ) ); 224 } 225 226 /** 227 * @ticket 21212 228 */ 229 function test_strip_invalid_text_for_column() { 230 global $wpdb; 231 232 $charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' ); 233 if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) { 234 $this->markTestSkipped( 'This test requires a utf8 character set' ); 235 } 236 237 // Invalid 3-byte and 4-byte sequences 238 $value = "H€llo\xe0\x80\x80World\xf0\xff\xff\xff¢"; 239 $expected = "H€lloWorld¢"; 240 $actual = $wpdb->strip_invalid_text_for_column( $wpdb->posts, 'post_content', $value ); 241 $this->assertEquals( $expected, $actual ); 242 } 243 244 /** 245 * Set of table definitions for testing wpdb::get_table_charset and wpdb::get_column_charset 246 * @var array 247 */ 248 protected $table_and_column_defs = array( 249 array( 250 'definition' => '( a INT, b FLOAT )', 251 'table_expected' => false, 252 'column_expected' => array( 'a' => false, 'b' => false ) 253 ), 254 array( 255 'definition' => '( a VARCHAR(50) CHARACTER SET big5, b TEXT CHARACTER SET big5 )', 256 'table_expected' => 'big5', 257 'column_expected' => array( 'a' => 'big5', 'b' => 'big5' ) 258 ), 259 array( 260 'definition' => '( a VARCHAR(50) CHARACTER SET big5, b BINARY )', 261 'table_expected' => 'binary', 262 'column_expected' => array( 'a' => 'big5', 'b' => false ) 263 ), 264 array( 265 'definition' => '( a VARCHAR(50) CHARACTER SET latin1, b BLOB )', 266 'table_expected' => 'binary', 267 'column_expected' => array( 'a' => 'latin1', 'b' => false ) 268 ), 269 array( 270 'definition' => '( a VARCHAR(50) CHARACTER SET latin1, b TEXT CHARACTER SET koi8r )', 271 'table_expected' => 'koi8r', 272 'column_expected' => array( 'a' => 'latin1', 'b' => 'koi8r' ) 273 ), 274 array( 275 'definition' => '( a VARCHAR(50) CHARACTER SET utf8mb3, b TEXT CHARACTER SET utf8mb3 )', 276 'table_expected' => 'utf8', 277 'column_expected' => array( 'a' => 'utf8', 'b' => 'utf8' ) 278 ), 279 array( 280 'definition' => '( a VARCHAR(50) CHARACTER SET utf8, b TEXT CHARACTER SET utf8mb4 )', 281 'table_expected' => 'utf8', 282 'column_expected' => array( 'a' => 'utf8', 'b' => 'utf8mb4' ) 283 ), 284 array( 285 'definition' => '( a VARCHAR(50) CHARACTER SET big5, b TEXT CHARACTER SET koi8r )', 286 'table_expected' => 'ascii', 287 'column_expected' => array( 'a' => 'big5', 'b' => 'koi8r' ) 288 ), 289 ); 290 291 /** 292 * @ticket 21212 293 */ 294 function data_test_get_table_charset() { 295 $table_name = 'test_get_table_charset'; 296 297 $vars = array(); 298 foreach( $this->table_and_column_defs as $value ) { 299 $this_table_name = $table_name . '_' . rand_str( 5 ); 300 $drop = "DROP TABLE IF EXISTS $this_table_name"; 301 $create = "CREATE TABLE $this_table_name {$value['definition']}"; 302 $vars[] = array( $drop, $create, $this_table_name, $value['table_expected'] ); 303 } 304 305 return $vars; 306 } 307 308 /** 309 * @dataProvider data_test_get_table_charset 310 * @ticket 21212 311 */ 312 function test_get_table_charset( $drop, $create, $table, $expected_charset ) { 313 self::$_wpdb->query( $drop ); 314 315 if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) { 316 $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." ); 317 return; 318 } 319 320 self::$_wpdb->query( $create ); 321 322 $charset = self::$_wpdb->get_table_charset( $table ); 323 $this->assertEquals( $charset, $expected_charset ); 324 325 $charset = self::$_wpdb->get_table_charset( strtoupper( $table ) ); 326 $this->assertEquals( $charset, $expected_charset ); 327 328 self::$_wpdb->query( $drop ); 329 } 330 331 /** 332 * @ticket 21212 333 */ 334 function data_test_get_column_charset() { 335 $table_name = 'test_get_column_charset'; 336 337 $vars = array(); 338 foreach( $this->table_and_column_defs as $value ) { 339 $this_table_name = $table_name . '_' . rand_str( 5 ); 340 $drop = "DROP TABLE IF EXISTS $this_table_name"; 341 $create = "CREATE TABLE $this_table_name {$value['definition']}"; 342 $vars[] = array( $drop, $create, $this_table_name, $value['column_expected'] ); 343 } 344 345 return $vars; 346 } 347 348 /** 349 * @dataProvider data_test_get_column_charset 350 * @ticket 21212 351 */ 352 function test_get_column_charset( $drop, $create, $table, $expected_charset ) { 353 self::$_wpdb->query( $drop ); 354 355 if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) { 356 $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." ); 357 return; 358 } 359 360 self::$_wpdb->query( $create ); 361 362 foreach ( $expected_charset as $column => $charset ) { 363 $this->assertEquals( $charset, self::$_wpdb->get_col_charset( $table, $column ) ); 364 $this->assertEquals( $charset, self::$_wpdb->get_col_charset( strtoupper( $table ), strtoupper( $column ) ) ); 365 } 366 367 self::$_wpdb->query( $drop ); 368 } 369 370 /** 371 * @dataProvider data_test_get_column_charset 372 * @ticket 21212 373 */ 374 function test_get_column_charset_non_mysql( $drop, $create, $table, $columns ) { 375 self::$_wpdb->query( $drop ); 376 377 if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) { 378 $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." ); 379 return; 380 } 381 382 self::$_wpdb->is_mysql = false; 383 384 self::$_wpdb->query( $create ); 385 386 $columns = array_keys( $columns ); 387 foreach ( $columns as $column => $charset ) { 388 $this->assertEquals( false, self::$_wpdb->get_col_charset( $table, $column ) ); 389 } 390 391 self::$_wpdb->query( $drop ); 392 393 self::$_wpdb->is_mysql = true; 394 } 395 396 /** 397 * @ticket 21212 398 */ 399 function data_strip_invalid_text_from_query() { 400 $table_name = 'strip_invalid_text_from_query_table'; 401 $data = array( 402 array( 403 // binary tables don't get stripped 404 "( a VARCHAR(50) CHARACTER SET utf8, b BINARY )", // create 405 "('foo\xf0\x9f\x98\x88bar', 'foo')", // query 406 "('foo\xf0\x9f\x98\x88bar', 'foo')" // expected result 407 ), 408 array( 409 // utf8/utf8mb4 tables default to utf8 410 "( a VARCHAR(50) CHARACTER SET utf8, b VARCHAR(50) CHARACTER SET utf8mb4 )", 411 "('foo\xf0\x9f\x98\x88bar', 'foo')", 412 "('foobar', 'foo')" 413 ), 414 ); 415 416 foreach( $data as &$value ) { 417 $this_table_name = $table_name . '_' . rand_str( 5 ); 418 419 $value[0] = "CREATE TABLE $this_table_name {$value[0]}"; 420 $value[1] = "INSERT INTO $this_table_name VALUES {$value[1]}"; 421 $value[2] = "INSERT INTO $this_table_name VALUES {$value[2]}"; 422 $value[3] = "DROP TABLE IF EXISTS $this_table_name"; 423 } 424 unset( $value ); 425 426 return $data; 427 } 428 429 /** 430 * @dataProvider data_strip_invalid_text_from_query 431 * @ticket 21212 432 */ 433 function test_strip_invalid_text_from_query( $create, $query, $expected, $drop ) { 434 self::$_wpdb->query( $drop ); 435 436 if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) { 437 $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." ); 438 return; 439 } 440 441 self::$_wpdb->query( $create ); 442 443 $return = self::$_wpdb->strip_invalid_text_from_query( $query ); 444 $this->assertEquals( $expected, $return ); 445 446 self::$_wpdb->query( $drop ); 447 } 448 449 /** 450 * @ticket 21212 451 */ 452 function test_invalid_characters_in_query() { 453 global $wpdb; 454 455 $charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' ); 456 if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) { 457 $this->markTestSkipped( 'This test requires a utf8 character set' ); 458 } 459 460 $this->assertFalse( $wpdb->query( "INSERT INTO {$wpdb->posts} (post_content) VALUES ('foo\xf0\xff\xff\xffbar')" ) ); 461 } 462 463 /** 464 * @ticket 21212 465 */ 466 function data_table_collation_check() { 467 $table_name = 'table_collation_check'; 468 $data = array( 469 array( 470 // utf8_bin tables don't need extra sanity checking. 471 "( a VARCHAR(50) COLLATE utf8_bin )", // create 472 true // expected result 473 ), 474 array( 475 // Neither do utf8_general_ci tables. 476 "( a VARCHAR(50) COLLATE utf8_general_ci )", 477 true 478 ), 479 array( 480 // utf8_unicode_ci tables do. 481 "( a VARCHAR(50) COLLATE utf8_unicode_ci )", 482 false 483 ), 484 array( 485 // utf8_bin tables don't need extra sanity checking, 486 // except for when they're not just utf8_bin. 487 "( a VARCHAR(50) COLLATE utf8_bin, b VARCHAR(50) COLLATE big5_chinese_ci )", 488 false 489 ), 490 array( 491 // utf8_bin tables don't need extra sanity checking 492 // when the other columns aren't strings. 493 "( a VARCHAR(50) COLLATE utf8_bin, b INT )", 494 true 495 ), 496 ); 497 498 foreach( $data as &$value ) { 499 $this_table_name = $table_name . '_' . rand_str( 5 ); 500 501 $value[0] = "CREATE TABLE $this_table_name {$value[0]}"; 502 $value[2] = "SELECT * FROM $this_table_name WHERE a='\xf0\x9f\x98\x88'"; 503 $value[3] = "DROP TABLE IF EXISTS $this_table_name"; 504 $value[4] = array( 505 "SELECT * FROM $this_table_name WHERE a='foo'", 506 "SHOW FULL TABLES LIKE $this_table_name", 507 "DESCRIBE $this_table_name", 508 "DESC $this_table_name", 509 "EXPLAIN SELECT * FROM $this_table_name", 510 ); 511 } 512 unset( $value ); 513 514 return $data; 515 } 516 517 518 /** 519 * @dataProvider data_table_collation_check 520 * @ticket 21212 521 */ 522 function test_table_collation_check( $create, $expected, $query, $drop, $always_true ) { 523 self::$_wpdb->query( $drop ); 524 525 self::$_wpdb->query( $create ); 526 527 $return = self::$_wpdb->check_safe_collation( $query ); 528 $this->assertEquals( $expected, $return ); 529 530 foreach( $always_true as $true_query ) { 531 $return = self::$_wpdb->check_safe_collation( $true_query ); 532 $this->assertTrue( $return ); 533 } 534 535 self::$_wpdb->query( $drop ); 536 } 537 } -
tags/4.1.2/tests/phpunit/tests/formatting/SanitizeOrderby.php
r61362 r61362 1 1 <?php 2 2 3 /* // @todo These tests need to be rewritten for sanitize_sql_orderby 3 /** 4 * @group sanitize_sql_orderby 5 */ 4 6 class Tests_Formatting_SanitizeOrderby extends WP_UnitTestCase { 5 function test_empty() { 6 $cols = array('a' => 'a'); 7 $this->assertEquals( '', sanitize_sql_orderby('', $cols) ); 8 $this->assertEquals( '', sanitize_sql_orderby(' ', $cols) ); 9 $this->assertEquals( '', sanitize_sql_orderby("\t", $cols) ); 10 $this->assertEquals( '', sanitize_sql_orderby(null, $cols) ); 11 $this->assertEquals( '', sanitize_sql_orderby(0, $cols) ); 12 $this->assertEquals( '', sanitize_sql_orderby('+', $cols) ); 13 $this->assertEquals( '', sanitize_sql_orderby('-', $cols) ); 7 8 /** 9 * @covers ::sanitize_sql_orderby 10 * @dataProvider valid_orderbys 11 */ 12 function test_valid( $orderby ) { 13 $this->assertEquals( $orderby, sanitize_sql_orderby( $orderby ) ); 14 } 15 function valid_orderbys() { 16 return array( 17 array( '1' ), 18 array( '1 ASC' ), 19 array( '1 ASC, 2' ), 20 array( '1 ASC, 2 DESC' ), 21 array( '1 ASC, 2 DESC, 3' ), 22 array( ' 1 DESC' ), 23 array( 'field ASC' ), 24 array( 'field1 ASC, field2' ), 25 array( 'field_1 ASC, field_2 DESC' ), 26 array( 'field1, field2 ASC' ), 27 array( '`field1`' ), 28 array( '`field1` ASC' ), 29 array( '`field` ASC, `field2`' ), 30 array( 'RAND()' ), 31 array( ' RAND( ) ' ), 32 ); 14 33 } 15 34 16 function test_unknown_column() { 17 $cols = array('name' => 'post_name', 'date' => 'post_date'); 18 $this->assertEquals( '', sanitize_sql_orderby('unknown_column', $cols) ); 19 $this->assertEquals( '', sanitize_sql_orderby('+unknown_column', $cols) ); 20 $this->assertEquals( '', sanitize_sql_orderby('-unknown_column', $cols) ); 21 $this->assertEquals( '', sanitize_sql_orderby('-unknown1,+unknown2,unknown3', $cols) ); 22 $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('name,unknown_column', $cols) ); 23 $this->assertEquals( '', sanitize_sql_orderby('!@#$%^&*()_=~`\'",./', $cols) ); 35 /** 36 * @covers ::sanitize_sql_orderby 37 * @dataProvider invalid_orderbys 38 */ 39 function test_invalid( $orderby ) { 40 $this->assertFalse( sanitize_sql_orderby( $orderby ) ); 24 41 } 25 26 function test_valid() { 27 $cols = array('name' => 'post_name', 'date' => 'post_date', 'random' => 'rand()'); 28 $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('name', $cols) ); 29 $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('+name', $cols) ); 30 $this->assertEquals( 'post_name DESC', sanitize_sql_orderby('-name', $cols) ); 31 $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_sql_orderby('date,name', $cols) ); 32 $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_sql_orderby(' date , name ', $cols) ); 33 $this->assertEquals( 'post_name DESC, post_date ASC', sanitize_sql_orderby('-name,date', $cols) ); 34 $this->assertEquals( 'post_name ASC, post_date ASC', sanitize_sql_orderby('name ,+ date', $cols) ); 35 $this->assertEquals( 'rand() ASC', sanitize_sql_orderby('random', $cols) ); 42 function invalid_orderbys() { 43 return array( 44 array( '' ), 45 array( '1 2' ), 46 array( '1, 2 3' ), 47 array( '1 DESC, ' ), 48 array( 'field-1' ), 49 array( 'field DESC,' ), 50 array( 'field1 field2' ), 51 array( 'field RAND()' ), 52 array( 'RAND() ASC' ), 53 array( '`field1` ASC, `field2' ), 54 array( 'field, !@#$%^' ), 55 ); 36 56 } 37 57 } 38 */ -
tags/4.1.2/tests/phpunit/tests/image/base.php
r61362 r61362 23 23 */ 24 24 public function tearDown() { 25 remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 ); 25 26 parent::tearDown(); 26 27 remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );28 27 } 29 28 -
tags/4.1.2/tests/phpunit/tests/link.php
r61362 r61362 7 7 function tearDown() { 8 8 global $wp_rewrite; 9 $wp_rewrite->init(); 9 10 parent::tearDown(); 10 $wp_rewrite->init();11 11 } 12 12 -
tags/4.1.2/tests/phpunit/tests/mail.php
r61362 r61362 12 12 13 13 function tearDown() { 14 unset( $_SERVER['SERVER_NAME'] ); 14 15 parent::tearDown(); 15 unset( $_SERVER['SERVER_NAME'] );16 16 } 17 17 -
tags/4.1.2/tests/phpunit/tests/media.php
r61362 r61362 468 468 } 469 469 470 function test_wp_check_filetype() {471 $url = 'http://example.com/testFile.mp4?autoplay=true&otherstuff=false';472 $filetype = wp_check_filetype( $url );473 $expected = array(474 'ext' => 'mp4',475 'type' => 'video/mp4'476 );477 $this->assertEquals( $expected, $filetype );478 }479 470 } -
tags/4.1.2/tests/phpunit/tests/multisite/bootstrap.php
r61362 r61362 22 22 function tearDown() { 23 23 global $wpdb; 24 $wpdb->suppress_errors( $this->suppress ); 24 25 parent::tearDown(); 25 $wpdb->suppress_errors( $this->suppress );26 26 } 27 27 -
tags/4.1.2/tests/phpunit/tests/multisite/ms-files-rewriting.php
r61362 r61362 30 30 31 31 update_site_option( 'ms_files_rewriting', 0 ); 32 $wpdb->suppress_errors( $this->suppress ); 33 32 34 parent::tearDown(); 33 $wpdb->suppress_errors( $this->suppress );34 35 } 35 36 -
tags/4.1.2/tests/phpunit/tests/multisite/network.php
r61362 r61362 23 23 function tearDown() { 24 24 global $wpdb; 25 $wpdb->suppress_errors( $this->suppress ); 25 26 parent::tearDown(); 26 $wpdb->suppress_errors( $this->suppress );27 27 } 28 28 -
tags/4.1.2/tests/phpunit/tests/multisite/site.php
r61362 r61362 22 22 function tearDown() { 23 23 global $wpdb; 24 $wpdb->suppress_errors( $this->suppress ); 24 25 parent::tearDown(); 25 $wpdb->suppress_errors( $this->suppress );26 26 } 27 27 -
tags/4.1.2/tests/phpunit/tests/option/multisite.php
r61362 r61362 23 23 function tearDown() { 24 24 global $wpdb; 25 $wpdb->suppress_errors( $this->suppress ); 25 26 parent::tearDown(); 26 $wpdb->suppress_errors( $this->suppress );27 27 } 28 28 -
tags/4.1.2/tests/phpunit/tests/post.php
r61362 r61362 1032 1032 _unregister_post_type( 'post-type-1' ); 1033 1033 } 1034 1035 /** 1036 * @ticket 21212 1037 */ 1038 function test_utf8mb3_post_saves_with_emoji() { 1039 global $wpdb; 1040 $_wpdb = new wpdb_exposed_methods_for_testing(); 1041 1042 if ( 'utf8' !== $_wpdb->get_col_charset( $wpdb->posts, 'post_title' ) ) { 1043 $this->markTestSkipped( 'This test is only useful with the utf8 character set' ); 1044 } 1045 1046 require_once( ABSPATH . '/wp-admin/includes/post.php' ); 1047 1048 $post_id = $this->factory->post->create(); 1049 1050 $data = array( 1051 'post_ID' => $post_id, 1052 'post_title' => "foo\xf0\x9f\x98\x88bar", 1053 'post_content' => "foo\xf0\x9f\x98\x8ebaz", 1054 'post_excerpt' => "foo\xf0\x9f\x98\x90bat" 1055 ); 1056 1057 $expected = array( 1058 'post_title' => "foobar", 1059 'post_content' => "foobaz", 1060 'post_excerpt' => "foobat" 1061 ); 1062 1063 edit_post( $data ); 1064 1065 $post = get_post( $post_id ); 1066 1067 foreach( $expected as $field => $value ) { 1068 $this->assertEquals( $post->$field, $value ); 1069 } 1070 } 1034 1071 } -
tags/4.1.2/tests/phpunit/tests/post/meta.php
r61362 r61362 34 34 35 35 function tearDown() { 36 parent::tearDown();37 36 wp_delete_post($this->post_id); 38 37 wp_delete_post($this->post_id_2); 38 parent::tearDown(); 39 39 } 40 40 -
tags/4.1.2/tests/phpunit/tests/post/revisions.php
r61362 r61362 13 13 14 14 function tearDown() { 15 unset( $GLOBALS['wp_post_types'][ $this->post_type ] ); 15 16 parent::tearDown(); 16 unset( $GLOBALS['wp_post_types'][ $this->post_type ] );17 17 } 18 18 -
tags/4.1.2/tests/phpunit/tests/query/conditionals.php
r61362 r61362 35 35 function tearDown() { 36 36 global $wp_rewrite; 37 $wp_rewrite->init(); 38 37 39 parent::tearDown(); 38 $wp_rewrite->init();39 40 } 40 41 -
tags/4.1.2/tests/phpunit/tests/query/search.php
r61362 r61362 19 19 20 20 function tearDown() { 21 parent::tearDown();22 23 21 _unregister_post_type( $this->post_type ); 24 22 unset( $this->q ); 23 24 parent::tearDown(); 25 25 } 26 26 -
tags/4.1.2/tests/phpunit/tests/rewrite.php
r61362 r61362 23 23 function tearDown() { 24 24 global $wp_rewrite; 25 $wp_rewrite->init(); 26 25 27 parent::tearDown(); 26 $wp_rewrite->init();27 28 } 28 29 -
tags/4.1.2/tests/phpunit/tests/shortcode.php
r61362 r61362 21 21 function tearDown() { 22 22 global $shortcode_tags; 23 parent::tearDown();24 23 foreach ( $this->shortcodes as $shortcode ) 25 24 unset( $shortcode_tags[ $shortcode ] ); 25 parent::tearDown(); 26 26 } 27 27 -
tags/4.1.2/tests/phpunit/tests/user/capabilities.php
r61362 r61362 661 661 $author->remove_cap( 'foo' ); 662 662 $this->assertFalse ( isset( $author->caps['foo'] ) ); 663 } 664 665 function test_borked_current_user_can_for_blog() { 666 if ( ! is_multisite() ) { 667 $this->markTestSkipped( 'Test only runs in multisite' ); 668 return; 669 } 670 671 $orig_blog_id = get_current_blog_id(); 672 $blog_id = $this->factory->blog->create(); 673 674 $this->_nullify_current_user(); 675 676 add_action( 'switch_blog', array( $this, '_nullify_current_user_and_keep_nullifying_user' ) ); 677 678 current_user_can_for_blog( $blog_id, 'edit_posts' ); 679 680 $this->assertEquals( $orig_blog_id, get_current_blog_id() ); 681 } 682 683 function _nullify_current_user() { 684 // Prevents fatal errors in ::tearDown()'s and other uses of restore_current_blog() 685 $function_stack = wp_debug_backtrace_summary( null, 0, false ); 686 if ( in_array( 'restore_current_blog', $function_stack ) ) { 687 return; 688 } 689 $GLOBALS['current_user'] = null; 690 } 691 692 function _nullify_current_user_and_keep_nullifying_user() { 693 add_action( 'set_current_user', array( $this, '_nullify_current_user' ) ); 663 694 } 664 695 -
tags/4.1.2/tests/phpunit/tests/user/countUserPosts.php
r61362 r61362 58 58 59 59 public function tearDown() { 60 _unregister_post_type( 'wptests_pt' ); 60 61 parent::tearDown(); 61 _unregister_post_type( 'wptests_pt' );62 62 } 63 63 -
tags/4.1.2/tests/phpunit/tests/user/mapMetaCap.php
r61362 r61362 33 33 34 34 function tearDown() { 35 parent::tearDown();36 37 35 $GLOBALS['super_admins'] = $this->super_admins; 38 36 unset( $GLOBALS['wp_post_types'][ $this->post_type ] ); 37 parent::tearDown(); 39 38 } 40 39 -
tags/4.1.2/tests/phpunit/tests/user/multisite.php
r61362 r61362 23 23 function tearDown() { 24 24 global $wpdb; 25 $wpdb->suppress_errors( $this->suppress ); 25 26 parent::tearDown(); 26 $wpdb->suppress_errors( $this->suppress );27 27 } 28 28 -
tags/4.1.2/tests/phpunit/tests/xmlrpc/wp/getPage.php
r61362 r61362 25 25 26 26 function tearDown() { 27 wp_delete_post( $this->post_id ); 27 28 parent::tearDown(); 28 29 wp_delete_post( $this->post_id );30 29 } 31 30
Note: See TracChangeset
for help on using the changeset viewer.