<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[32237] branches/3.9/tests/phpunit/tests: Add some unit tests missed in [32182] to the 3.9 branch.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/32237">32237</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/32237","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>pento</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-04-21 06:49:10 +0000 (Tue, 21 Apr 2015)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Add some unit tests missed in <a href="https://core.trac.wordpress.org/changeset/32182">[32182]</a> to the 3.9 branch.</pre>

<h3>Added Paths</h3>
<ul>
<li>branches/3.9/tests/phpunit/tests/db/</li>
<li><a href="#branches39testsphpunittestsdbcharsetphp">branches/3.9/tests/phpunit/tests/db/charset.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branches39testsphpunittestsdbcharsetphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: branches/3.9/tests/phpunit/tests/db/charset.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/3.9/tests/phpunit/tests/db/charset.php                           (rev 0)
+++ branches/3.9/tests/phpunit/tests/db/charset.php     2015-04-21 06:49:10 UTC (rev 32237)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,525 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+require_once dirname( dirname( __FILE__ ) ) . '/db.php';
+
+/**
+ * Test WPDB methods
+ *
+ * @group wpdb
+ */
+class Tests_DB_Charset extends WP_UnitTestCase {
+
+       /**
+        * Our special WPDB
+        * @var resource
+        */
+       protected static $_wpdb;
+
+       public static function setUpBeforeClass() {
+               self::$_wpdb = new wpdb_exposed_methods_for_testing();
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function data_strip_invalid_text() {
+               $fields = array(
+                       'latin1' => array(
+                               // latin1. latin1 never changes.
+                               'charset'  => 'latin1',
+                               'value'    => "\xf0\x9f\x8e\xb7",
+                               'expected' => "\xf0\x9f\x8e\xb7"
+                       ),
+                       'ascii' => array(
+                               // ascii gets special treatment, make sure it's covered
+                               'charset'  => 'ascii',
+                               'value'    => 'Hello World',
+                               'expected' => 'Hello World'
+                       ),
+                       'utf8' => array(
+                               // utf8 only allows <= 3-byte chars
+                               'charset'  => 'utf8',
+                               'value'    => "H€llo\xf0\x9f\x98\x88World¢",
+                               'expected' => 'H€lloWorld¢'
+                       ),
+                       'utf8mb3' => array(
+                               // utf8mb3 should behave the same an utf8
+                               'charset'  => 'utf8mb3',
+                               'value'    => "H€llo\xf0\x9f\x98\x88World¢",
+                               'expected' => 'H€lloWorld¢'
+                       ),
+                       'utf8mb4' => array(
+                               // utf8mb4 allows 4-byte characters, too
+                               'charset'  => 'utf8mb4',
+                               'value'    => "H€llo\xf0\x9f\x98\x88World¢",
+                               'expected' => "H€llo\xf0\x9f\x98\x88World¢"
+                       ),
+                       'koi8r' => array(
+                               // koi8r is a character set that needs to be checked in MySQL
+                               'charset'  => 'koi8r',
+                               'value'    => "\xfdord\xf2ress",
+                               'expected' => "\xfdord\xf2ress",
+                               'db'       => true
+                       ),
+                       'hebrew' => array(
+                               // hebrew needs to be checked in MySQL, too
+                               'charset'  => 'hebrew',
+                               'value'    => "\xf9ord\xf7ress",
+                               'expected' => "\xf9ord\xf7ress",
+                               'db'       => true
+                       ),
+                       'false' => array(
+                               // false is a column with no character set (ie, a number column)
+                               'charset'  => false,
+                               'value'    => 100,
+                               'expected' => 100
+                       ),
+               );
+
+               if ( function_exists( 'mb_convert_encoding' ) ) {
+                       // big5 is a non-Unicode multibyte charset
+                       $utf8 = "a\xe5\x85\xb1b"; // UTF-8 Character 20849
+                       $big5 = mb_convert_encoding( $utf8, 'BIG-5', 'UTF-8' );
+                       $conv_utf8 = mb_convert_encoding( $big5, 'UTF-8', 'BIG-5' );
+                       // Make sure PHP's multibyte conversions are working correctly
+                       $this->assertNotEquals( $utf8, $big5 );
+                       $this->assertEquals( $utf8, $conv_utf8 );
+
+                       $fields['big5'] = array(
+                               'charset'  => 'big5',
+                               'value'    => $big5,
+                               'expected' => $big5
+                       );
+               }
+
+               // The data above is easy to edit. Now, prepare it for the data provider.
+               $data_provider = $multiple = $multiple_expected = array();
+               foreach ( $fields as $test_case => $field ) {
+                       $expected = $field;
+                       $expected['value'] = $expected['expected'];
+                       unset( $expected['expected'], $field['expected'] );
+
+                       // We're keeping track of these for our multiple-field test.
+                       $multiple[] = $field;
+                       $multiple_expected[] = $expected;
+
+                       // strip_invalid_text() expects an array of fields. We're testing one field at a time.
+                       $data = array( $field );
+                       $expected = array( $expected );
+
+                       // First argument is field data. Second is expected. Third is the message.
+                       $data_provider[] = array( $data, $expected, $test_case );
+               }
+
+               // Time for our test of multiple fields at once.
+               $data_provider[] = array( $multiple, $multiple_expected, 'multiple fields/charsets' );
+
+               return $data_provider;
+       }
+
+       /**
+        * @dataProvider data_strip_invalid_text
+        * @ticket 21212
+        */
+       function test_strip_invalid_text( $data, $expected, $message ) {
+               $actual = self::$_wpdb->strip_invalid_text( $data );
+               $this->assertSame( $expected, $actual, $message );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_process_fields_failure() {
+               global $wpdb;
+
+               $charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' );
+               if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
+                       $this->markTestSkipped( 'This test requires a utf8 character set' );
+               }
+
+               // \xf0\xff\xff\xff is invalid in utf8 and utf8mb4.
+               $data = array( 'post_content' => "H€llo\xf0\xff\xff\xffWorld¢" );
+               $this->assertFalse( self::$_wpdb->process_fields( $wpdb->posts, $data, null ) );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function data_process_field_charsets() {
+               if ( $GLOBALS['wpdb']->charset ) {
+                       $charset = $GLOBALS['wpdb']->charset;
+               } else {
+                       $charset = $GLOBALS['wpdb']->get_col_charset( $GLOBALS['wpdb']->posts, 'post_content' );
+               }
+
+               // 'value' and 'format' are $data, 'charset' ends up as part of $expected
+
+               $no_string_fields = array(
+                       'post_parent' => array( 'value' => 10, 'format' => '%d', 'charset' => false ),
+                       'comment_count' => array( 'value' => 0, 'format' => '%d', 'charset' => false ),
+               );
+
+               $all_ascii_fields = array(
+                       'post_content' => array( 'value' => 'foo foo foo!', 'format' => '%s', 'charset' => false ),
+                       'post_excerpt' => array( 'value' => 'bar bar bar!', 'format' => '%s', 'charset' => false ),
+               );
+
+               // This is the same data used in process_field_charsets_for_nonexistent_table()
+               $non_ascii_string_fields = array(
+                       'post_content' => array( 'value' => '¡foo foo foo!', 'format' => '%s', 'charset' => $charset, 'ascii' => false ),
+                       'post_excerpt' => array( 'value' => '¡bar bar bar!', 'format' => '%s', 'charset' => $charset, 'ascii' => false ),
+               );
+
+               $vars = get_defined_vars();
+               unset( $vars['charset'] );
+               foreach ( $vars as $var_name => $var ) {
+                       $data = $expected = $var;
+                       foreach ( $data as &$datum ) {
+                               // 'charset' and 'ascii' are part of the expected return only.
+                               unset( $datum['charset'], $datum['ascii'] );
+                       }
+
+                       $vars[ $var_name ] = array( $data, $expected, $var_name );
+               }
+
+               return array_values( $vars );
+       }
+
+       /**
+        * @dataProvider data_process_field_charsets
+        * @ticket 21212
+        */
+       function test_process_field_charsets( $data, $expected, $message ) {
+               $actual = self::$_wpdb->process_field_charsets( $data, $GLOBALS['wpdb']->posts );
+               $this->assertSame( $expected, $actual, $message );
+       }
+
+       /**
+        * The test this test depends on first verifies that this
+        * would normally work against the posts table.
+        *
+        * @ticket 21212
+        * @depends test_process_field_charsets
+        */
+       function test_process_field_charsets_on_nonexistent_table() {
+               $data = array( 'post_content' => array( 'value' => '¡foo foo foo!', 'format' => '%s' ) );
+               self::$_wpdb->suppress_errors( true );
+               $this->assertFalse( self::$_wpdb->process_field_charsets( $data, 'nonexistent_table' ) );
+               self::$_wpdb->suppress_errors( false );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_check_ascii() {
+               $ascii = "\0\t\n\r '" . '!"#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
+               $this->assertTrue( self::$_wpdb->check_ascii( $ascii ) );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_check_ascii_false() {
+               $this->assertFalse( self::$_wpdb->check_ascii( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ¡©«' ) );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strip_invalid_text_for_column() {
+               global $wpdb;
+
+               $charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' );
+               if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
+                       $this->markTestSkipped( 'This test requires a utf8 character set' );
+               }
+
+               // Invalid 3-byte and 4-byte sequences
+               $value = "H€llo\xe0\x80\x80World\xf0\xff\xff\xff¢";
+               $expected = "H€lloWorld¢";
+               $actual = $wpdb->strip_invalid_text_for_column( $wpdb->posts, 'post_content', $value );
+               $this->assertEquals( $expected, $actual );
+       }
+
+       /**
+        * Set of table definitions for testing wpdb::get_table_charset and wpdb::get_column_charset
+        * @var array
+        */
+       protected $table_and_column_defs = array(
+               array(
+                       'definition'      => '( a INT, b FLOAT )',
+                       'table_expected'  => false,
+                       'column_expected' => array( 'a' => false, 'b' => false )
+               ),
+               array(
+                       'definition'      => '( a VARCHAR(50) CHARACTER SET big5, b TEXT CHARACTER SET big5 )',
+                       'table_expected'  => 'big5',
+                       'column_expected' => array( 'a' => 'big5', 'b' => 'big5' )
+               ),
+               array(
+                       'definition'      => '( a VARCHAR(50) CHARACTER SET big5, b BINARY )',
+                       'table_expected'  => 'binary',
+                       'column_expected' => array( 'a' => 'big5', 'b' => false )
+               ),
+               array(
+                       'definition'      => '( a VARCHAR(50) CHARACTER SET latin1, b BLOB )',
+                       'table_expected'  => 'binary',
+                       'column_expected' => array( 'a' => 'latin1', 'b' => false )
+               ),
+               array(
+                       'definition'      => '( a VARCHAR(50) CHARACTER SET latin1, b TEXT CHARACTER SET koi8r )',
+                       'table_expected'  => 'koi8r',
+                       'column_expected' => array( 'a' => 'latin1', 'b' => 'koi8r' )
+               ),
+               array(
+                       'definition'      => '( a VARCHAR(50) CHARACTER SET utf8mb3, b TEXT CHARACTER SET utf8mb3 )',
+                       'table_expected'  => 'utf8',
+                       'column_expected' => array( 'a' => 'utf8', 'b' => 'utf8' )
+               ),
+               array(
+                       'definition'      => '( a VARCHAR(50) CHARACTER SET utf8, b TEXT CHARACTER SET utf8mb4 )',
+                       'table_expected'  => 'utf8',
+                       'column_expected' => array( 'a' => 'utf8', 'b' => 'utf8mb4' )
+               ),
+               array(
+                       'definition'      => '( a VARCHAR(50) CHARACTER SET big5, b TEXT CHARACTER SET koi8r )',
+                       'table_expected'  => 'ascii',
+                       'column_expected' => array( 'a' => 'big5', 'b' => 'koi8r' )
+               ),
+       );
+
+       /**
+        * @ticket 21212
+        */
+       function data_test_get_table_charset() {
+               $table_name = 'test_get_table_charset';
+
+               $vars = array();
+               foreach( $this->table_and_column_defs as $value ) {
+                       $this_table_name = $table_name . '_' . rand_str( 5 );
+                       $drop = "DROP TABLE IF EXISTS $this_table_name";
+                       $create = "CREATE TABLE $this_table_name {$value['definition']}";
+                       $vars[] = array( $drop, $create, $this_table_name, $value['table_expected'] );
+               }
+
+               return $vars;
+       }
+
+       /**
+        * @dataProvider data_test_get_table_charset
+        * @ticket 21212
+        */
+       function test_get_table_charset( $drop, $create, $table, $expected_charset ) {
+               self::$_wpdb->query( $drop );
+
+               if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) {
+                       $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." );
+                       return;
+               }
+
+               self::$_wpdb->query( $create );
+
+               $charset = self::$_wpdb->get_table_charset( $table );
+               $this->assertEquals( $charset, $expected_charset );
+
+               $charset = self::$_wpdb->get_table_charset( strtoupper( $table ) );
+               $this->assertEquals( $charset, $expected_charset );
+
+               self::$_wpdb->query( $drop );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function data_test_get_column_charset() {
+               $table_name = 'test_get_column_charset';
+
+               $vars = array();
+               foreach( $this->table_and_column_defs as $value ) {
+                       $this_table_name = $table_name . '_' . rand_str( 5 );
+                       $drop = "DROP TABLE IF EXISTS $this_table_name";
+                       $create = "CREATE TABLE $this_table_name {$value['definition']}";
+                       $vars[] = array( $drop, $create, $this_table_name, $value['column_expected'] );
+               }
+
+               return $vars;
+       }
+
+       /**
+        * @dataProvider data_test_get_column_charset
+        * @ticket 21212
+        */
+       function test_get_column_charset( $drop, $create, $table, $expected_charset ) {
+               self::$_wpdb->query( $drop );
+
+               if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) {
+                       $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." );
+                       return;
+               }
+
+               self::$_wpdb->query( $create );
+
+               foreach ( $expected_charset as $column => $charset ) {
+                       $this->assertEquals( $charset, self::$_wpdb->get_col_charset( $table, $column ) );
+                       $this->assertEquals( $charset, self::$_wpdb->get_col_charset( strtoupper( $table ), strtoupper( $column ) ) );
+               }
+
+               self::$_wpdb->query( $drop );
+       }
+
+       /**
+        * @dataProvider data_test_get_column_charset
+        * @ticket 21212
+        */
+       function test_get_column_charset_non_mysql( $drop, $create, $table, $columns ) {
+               self::$_wpdb->query( $drop );
+
+               if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) {
+                       $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." );
+                       return;
+               }
+
+               self::$_wpdb->is_mysql = false;
+
+               self::$_wpdb->query( $create );
+
+               $columns = array_keys( $columns );
+               foreach ( $columns as $column => $charset ) {
+                       $this->assertEquals( false, self::$_wpdb->get_col_charset( $table, $column ) );
+               }
+
+               self::$_wpdb->query( $drop );
+
+               self::$_wpdb->is_mysql = true;
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function data_strip_invalid_text_from_query() {
+               $table_name = 'strip_invalid_text_from_query_table';
+               $data = array(
+                       array(
+                               // binary tables don't get stripped
+                               "( a VARCHAR(50) CHARACTER SET utf8, b BINARY )", // create
+                               "('foo\xf0\x9f\x98\x88bar', 'foo')",              // query
+                               "('foo\xf0\x9f\x98\x88bar', 'foo')"               // expected result
+                       ),
+                       array(
+                               // utf8/utf8mb4 tables default to utf8
+                               "( a VARCHAR(50) CHARACTER SET utf8, b VARCHAR(50) CHARACTER SET utf8mb4 )",
+                               "('foo\xf0\x9f\x98\x88bar', 'foo')",
+                               "('foobar', 'foo')"
+                       ),
+               );
+
+               foreach( $data as &$value ) {
+                       $this_table_name = $table_name . '_' . rand_str( 5 );
+
+                       $value[0] = "CREATE TABLE $this_table_name {$value[0]}";
+                       $value[1] = "INSERT INTO $this_table_name VALUES {$value[1]}";
+                       $value[2] = "INSERT INTO $this_table_name VALUES {$value[2]}";
+                       $value[3] = "DROP TABLE IF EXISTS $this_table_name";
+               }
+               unset( $value );
+
+               return $data;
+       }
+
+       /**
+        * @dataProvider data_strip_invalid_text_from_query
+        * @ticket 21212
+        */
+       function test_strip_invalid_text_from_query( $create, $query, $expected, $drop ) {
+               self::$_wpdb->query( $drop );
+
+               if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) {
+                       $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." );
+                       return;
+               }
+
+               self::$_wpdb->query( $create );
+
+               $return = self::$_wpdb->strip_invalid_text_from_query( $query );
+               $this->assertEquals( $expected, $return );
+
+               self::$_wpdb->query( $drop );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_invalid_characters_in_query() {
+               global $wpdb;
+
+               $charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' );
+               if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
+                       $this->markTestSkipped( 'This test requires a utf8 character set' );
+               }
+
+               $this->assertFalse( $wpdb->query( "INSERT INTO {$wpdb->posts} (post_content) VALUES ('foo\xf0\xff\xff\xffbar')" ) );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function data_table_collation_check() {
+               $table_name = 'table_collation_check';
+               $data = array(
+                       array(
+                               // utf8_bin tables don't need extra sanity checking.
+                               "( a VARCHAR(50) COLLATE utf8_bin )", // create
+                               true                                  // expected result
+                       ),
+                       array(
+                               // Neither do utf8_general_ci tables.
+                               "( a VARCHAR(50) COLLATE utf8_general_ci )",
+                               true
+                       ),
+                       array(
+                               // utf8_unicode_ci tables do.
+                               "( a VARCHAR(50) COLLATE utf8_unicode_ci )",
+                               false
+                       ),
+                       array(
+                               // utf8_bin tables don't need extra sanity checking,
+                               // except for when they're not just utf8_bin.
+                               "( a VARCHAR(50) COLLATE utf8_bin, b VARCHAR(50) COLLATE big5_chinese_ci )",
+                               false
+                       ),
+                       array(
+                               // utf8_bin tables don't need extra sanity checking
+                               // when the other columns aren't strings.
+                               "( a VARCHAR(50) COLLATE utf8_bin, b INT )",
+                               true
+                       ),
+               );
+
+               foreach( $data as &$value ) {
+                       $this_table_name = $table_name . '_' . rand_str( 5 );
+
+                       $value[0] = "CREATE TABLE $this_table_name {$value[0]}";
+                       $value[2] = "SELECT * FROM $this_table_name";
+                       $value[3] = "DROP TABLE IF EXISTS $this_table_name";
+               }
+               unset( $value );
+
+               return $data;
+       }
+
+
+       /**
+        * @dataProvider data_table_collation_check
+        * @ticket 21212
+        */
+       function test_table_collation_check( $create, $expected, $query, $drop ) {
+               self::$_wpdb->query( $drop );
+
+               self::$_wpdb->query( $create );
+
+               $return = self::$_wpdb->check_safe_collation( $query );
+               $this->assertEquals( $expected, $return );
+
+               self::$_wpdb->query( $drop );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: branches/3.9/tests/phpunit/tests/db/charset.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svnexecutable"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:executable</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+*
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>

</body>
</html>