diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php
index 6d6e177..6aca8f7 100644
--- tests/phpunit/tests/functions.php
+++ tests/phpunit/tests/functions.php
@@ -281,6 +281,9 @@ class Tests_Functions extends WP_UnitTestCase {
 			admin_url( 'edit.php?baz&za=1' ),
 			admin_url( 'edit.php?baz=1&za=1' ),
 			admin_url( 'edit.php?baz=0&za=0' ),
+			'/?baz=1&qux=2',
+			'/?baz=1&amp;qux=2',
+			'/?baz=1&#038;qux=2',
 		);
 
 		foreach ( $qs_urls as $url ) {
@@ -291,12 +294,26 @@ class Tests_Functions extends WP_UnitTestCase {
 			$this->assertEquals( "$url&foo=2", add_query_arg( array( 'foo' => '1', 'foo' => '2' ), $url ) );
 			$this->assertEquals( "$url&foo=1&bar=2", add_query_arg( array( 'foo' => '1', 'bar' => '2' ), $url ) );
 
+			$url_with_frag = $url . '#frag';
+
+			$this->assertEquals( "$url&foo=1#frag", add_query_arg( 'foo', '1', $url_with_frag ) );
+			$this->assertEquals( "$url&foo=1#frag", add_query_arg( array( 'foo' => '1' ), $url_with_frag ) );
+			$this->assertEquals( "$url&foo=2#frag", add_query_arg( array( 'foo' => '1', 'foo' => '2' ), $url_with_frag ) );
+			$this->assertEquals( "$url&foo=1&bar=2#frag", add_query_arg( array( 'foo' => '1', 'bar' => '2' ), $url_with_frag ) );
+
 			$_SERVER['REQUEST_URI'] = $url;
 
 			$this->assertEquals( "$url&foo=1", add_query_arg( 'foo', '1' ) );
 			$this->assertEquals( "$url&foo=1", add_query_arg( array( 'foo' => '1' ) ) );
 			$this->assertEquals( "$url&foo=2", add_query_arg( array( 'foo' => '1', 'foo' => '2' ) ) );
 			$this->assertEquals( "$url&foo=1&bar=2", add_query_arg( array( 'foo' => '1', 'bar' => '2' ) ) );
+
+			$_SERVER['REQUEST_URI'] = $url_with_frag;
+
+			$this->assertEquals( "$url&foo=1#frag", add_query_arg( 'foo', '1' ) );
+			$this->assertEquals( "$url&foo=1#frag", add_query_arg( array( 'foo' => '1' ) ) );
+			$this->assertEquals( "$url&foo=2#frag", add_query_arg( array( 'foo' => '1', 'foo' => '2' ) ) );
+			$this->assertEquals( "$url&foo=1&bar=2#frag", add_query_arg( array( 'foo' => '1', 'bar' => '2' ) ) );
 		}
 
 		$_SERVER['REQUEST_URI'] = $old_req_uri;
@@ -461,12 +478,12 @@ class Tests_Functions extends WP_UnitTestCase {
 				'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25',
 				true,
 			),
-			// Android 2.2, Android Webkit Browser 
+			// Android 2.2, Android Webkit Browser
 			array(
 				'Mozilla/5.0 (Android 2.2; Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4',
 				true,
 			),
-			// BlackBerry 9900, BlackBerry browser 
+			// BlackBerry 9900, BlackBerry browser
 			array(
 				'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+',
 				true,
