Index: tests/includes/testcase.php
===================================================================
--- tests/includes/testcase.php
+++ tests/includes/testcase.php
@@ -23,6 +23,7 @@ class BP_UnitTestCase extends WP_UnitTestCase {
 		buddypress()->current_user          = new stdClass();
 		buddypress()->displayed_user        = new stdClass();
 		buddypress()->loggedin_user         = new stdClass();
+		buddypress()->avatar                = new stdClass();
 
 		parent::clean_up_global_scope();
 	}
@@ -36,9 +37,6 @@ class BP_UnitTestCase extends WP_UnitTestCase {
 	}
 
 	function go_to( $url ) {
-		// Set this for bp_core_set_uri_globals()
-		$GLOBALS['_SERVER']['REQUEST_URI'] = $url = str_replace( network_home_url(), '', $url );
-
 		// note: the WP and WP_Query classes like to silently fetch parameters
 		// from all over the place (globals, GET, etc), which makes it tricky
 		// to run them more than once without very carefully clearing everything
@@ -48,6 +46,9 @@ class BP_UnitTestCase extends WP_UnitTestCase {
 		}
 		$parts = parse_url($url);
 		if (isset($parts['scheme'])) {
+			// set the HTTP_HOST
+			$GLOBALS['_SERVER']['HTTP_HOST'] = $parts['host'];
+
 			$req = $parts['path'];
 			if (isset($parts['query'])) {
 				$req .= '?' . $parts['query'];
@@ -68,10 +69,56 @@ class BP_UnitTestCase extends WP_UnitTestCase {
 			unset( $_SERVER['HTTPS'] );
 		}
 
-		$_SERVER['REQUEST_URI'] = $req;
+		$GLOBALS['_SERVER']['REQUEST_URI'] = $req;
 		unset($_SERVER['PATH_INFO']);
 
-		$this->flush_cache();
+		// setup $current_site and $current_blog globals for multisite based on
+		// REQUEST_URI; mostly copied from /wp-includes/ms-settings.php
+		if ( is_multisite() ) {
+			$domain = addslashes( $_SERVER['HTTP_HOST'] );
+			if ( false !== strpos( $domain, ':' ) ) {
+				if ( substr( $domain, -3 ) == ':80' ) {
+					$domain = substr( $domain, 0, -3 );
+					$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
+				} elseif ( substr( $domain, -4 ) == ':443' ) {
+					$domain = substr( $domain, 0, -4 );
+					$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
+				}
+			}
+
+			$domain = rtrim( $domain, '.' );
+			$cookie_domain = $domain;
+			if ( substr( $cookie_domain, 0, 4 ) == 'www.' )
+				$cookie_domain = substr( $cookie_domain, 4 );
+
+			$path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $GLOBALS['_SERVER']['REQUEST_URI'] );
+			$path = str_replace ( '/wp-admin/', '/', $path );
+			$path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
+
+			$GLOBALS['current_site'] = wpmu_current_site();
+			if ( ! isset( $GLOBALS['current_site']->blog_id ) )
+				$GLOBALS['current_site']->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $GLOBALS['current_site']->domain, $GLOBALS['current_site']->path ) );
+
+			// unit tests only support subdirectory install at the moment
+			// removed object cache references
+			if ( ! is_subdomain_install() ) {
+				$blogname = htmlspecialchars( substr( $GLOBALS['_SERVER']['REQUEST_URI'], strlen( $path ) ) );
+				if ( false !== strpos( $blogname, '/' ) )
+					$blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
+				if ( false !== strpos( $blogname, '?' ) )
+					$blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
+				$reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
+				if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
+					$path .= $blogname . '/';
+
+				$GLOBALS['current_blog'] = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false );
+
+				unset($reserved_blognames);
+			}
+
+			$GLOBALS['blog_id'] = $GLOBALS['current_blog']->blog_id;
+		}
+
 		unset($GLOBALS['wp_query'], $GLOBALS['wp_the_query']);
 		$GLOBALS['wp_the_query'] =& new WP_Query();
 		$GLOBALS['wp_query'] =& $GLOBALS['wp_the_query'];
@@ -87,8 +134,18 @@ class BP_UnitTestCase extends WP_UnitTestCase {
 
 		$GLOBALS['wp']->main($parts['query']);
 
+		// nuke BP! kaboom!
+		unset( $GLOBALS['bp'] );
+
+		// reload BP
+		$GLOBALS['bp'] = buddypress();
+
+		// unset some variables that need to be reloaded
+		// this doesn't quite work yet due to reliance on defines
+		unset( $GLOBALS['bp']->avatar->url, $GLOBALS['bp']->avatar->upload_path );
+
 		// For BuddyPress, James.
-		do_action( 'bp_init' );
+		do_action( 'init' );
 	}
 
 	protected function checkRequirements() {
Index: tests/testcases/core/avatars.php
new file mode 100644
===================================================================
--- tests/testcases/core/avatars.php 
+++ tests/testcases/core/avatars.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * @group core
+ * @group avatars
+ */
+class BP_Tests_Avatars extends BP_UnitTestCase {
+	protected $old_current_user = 0;
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->old_current_user = get_current_user_id();
+		$this->administrator    = $this->factory->user->create( array( 'role' => 'administrator' ) );
+		wp_set_current_user( $this->administrator );
+	}
+
+	public function tearDown() {
+		parent::tearDown();
+		wp_set_current_user( $this->old_current_user );
+	}
+
+	/**
+	 * @ticket 4948
+	 */
+	function test_avatars_on_non_root_blog() {
+		// Do not pass 'Go', do not collect $200
+		if ( ! is_multisite() ) {
+			return;
+		}
+
+		// switch to BP root blog if necessary
+		if ( bp_get_root_blog_id() != get_current_blog_id() ) {
+			switch_to_blog( get_current_blog_id() );
+		}
+
+		// get BP root blog's upload directory data
+		$upload_dir = wp_upload_dir();
+		
+		restore_current_blog();
+
+		// create new subsite
+		$blog_id = $this->factory->blog->create( array(
+			'user_id' => $this->administrator,
+			'path'    => PATH_CURRENT_SITE . 'test_blogname/',
+			'title'   => 'Test Title'
+		) );
+
+		// emulate a page load on the new sub-site
+		$this->go_to( get_blogaddress_by_name('test_blogname') );;
+		
+		// test to see if the upload dir is correct
+		$this->assertEquals( bp_core_avatar_url(), $upload_dir['baseurl'] );
+	}
+}
