Index: wp-testcase/test_query.php
===================================================================
--- wp-testcase/test_query.php	(revision 718)
+++ wp-testcase/test_query.php	(working copy)
@@ -564,4 +564,67 @@
 	}
 }
 
-?>
+/**
+ * Unit tests for the wpdb class
+ */
+class TestWPDB extends WPTestCase {
+
+	/**
+	 * Backup storage for $wpdb->real_escape
+	 * @var bool 
+	 */
+	private $_real_escape = true;
+	
+	/**
+	 * Backup $wpdb->real_escape
+	 * @global mixed $wpdb 
+	 */
+	public function setUp() {
+		global $wpdb;
+		$this->_real_escape = $wpdb->real_escape;
+	}
+
+	/**
+	 * Restore $wpdb->real_escape
+	 * @global mixed $wpdb 
+	 */
+	public function tearDown() {
+		global $wpdb;
+		$wpdb->real_escape = $this->_real_escape;
+	}
+
+	/**
+	 * Check the fallback logic for $wpdb->_real_escape when a connection to mysql isn't present.
+	 * @see http://us.php.net/mysql_real_escape_string
+	 * @global mixed $wpdb 
+	 */
+	public function test_real_escape() {
+		$this->knownWPBug( 20223 );
+		global $wpdb;
+		$strings = array(
+			'wordpress',
+			'word\press',
+			'word\\press',
+			'word\\\press',
+			'word\\\\press',
+			'word\'press',
+			'word\\\'press',
+			'word\\\\press',
+			'word"press',
+			'word\"press',
+			'word' . "\n" . 'press',
+			'word' . "\r" . 'press',
+			'word\x00press',
+			'word\x1apress',
+			'word\x00\x1a\x13\x10\\\'\"press',
+		);
+		foreach ( $strings as $string ) {
+			$wpdb->real_escape  = true;
+			$mysql_escape_query = $wpdb->prepare( "SELECT id FROM {$wpdb->users} WHERE user_login = '%s'", $wpdb->_real_escape( $string ) );
+			$wpdb->real_escape  = false;
+			$fake_escape_query  = $wpdb->prepare( "SELECT id FROM {$wpdb->users} WHERE user_login = '%s'", $wpdb->_real_escape( $string ) );
+			$this->assertEquals( $mysql_escape_query, $fake_escape_query );
+		}
+	}
+}
+
