Index: Gruntfile.js
===================================================================
--- Gruntfile.js	(revision 5671)
+++ Gruntfile.js	(working copy)
@@ -239,6 +239,10 @@
 				cmd: 'phpunit',
 				args: [ '-c', 'phpunit.xml.dist' ]
 			},
+			buddypress: {
+				cmd: 'phpunit',
+				args: [ '-c', 'tests/phpunit/buddypress.xml' ]
+			},
 			multisite: {
 				cmd: 'phpunit',
 				args: [ '-c', 'tests/phpunit/multisite.xml' ]
@@ -334,7 +338,7 @@
 	grunt.registerTask( 'release', [ 'build' ] );
 
 	// PHPUnit test task.
-	grunt.registerMultiTask( 'phpunit', 'Runs PHPUnit tests, including the ajax and multisite tests.', function() {
+	grunt.registerMultiTask( 'phpunit', 'Runs PHPUnit tests, including the BuddyPress and multisite tests.', function() {
 		grunt.util.spawn( {
 			cmd:  this.data.cmd,
 			args: this.data.args,
Index: phpunit.xml.dist
===================================================================
--- phpunit.xml.dist	(revision 5671)
+++ phpunit.xml.dist	(working copy)
@@ -7,8 +7,13 @@
 	convertWarningsToExceptions="true"
 	>
 	<testsuites>
-        <testsuite>
-            <directory suffix=".php">tests/phpunit/testcases/</directory>
-        </testsuite>
-    </testsuites>
+		<testsuite>
+			<directory suffix=".php">tests/phpunit/testcases/</directory>
+		</testsuite>
+	</testsuites>
+	<groups>
+		<exclude>
+			<group>buddypress</group>
+		</exclude>
+	</groups>
 </phpunit>
Index: src/includes/extend/buddypress/groups.php
===================================================================
--- src/includes/extend/buddypress/groups.php	(revision 5671)
+++ src/includes/extend/buddypress/groups.php	(working copy)
@@ -143,6 +143,9 @@
 			add_filter( 'bbp_current_user_can_access_create_topic_form', array( $this, 'form_permissions' ) );
 			add_filter( 'bbp_current_user_can_access_create_reply_form', array( $this, 'form_permissions' ) );
 		}
+
+		// Enforce forum privacy.
+		add_filter( 'bbp_is_forum_public', array( $this, 'enforce_forum_privacy' ), 10, 3 );
 	}
 
 	/**
@@ -1462,5 +1465,23 @@
 
 		return $args;
 	}
+
+	public function enforce_forum_privacy( $is_public, $forum_id, $check_ancestors ) {
+		$group_ids = bbp_get_forum_group_ids( $forum_id );
+
+		if ( ! empty( $group_ids ) ) {
+			foreach ( $group_ids as $group_id ) {
+				$group = groups_get_group( array( 'group_id' => $group_id ) );
+
+				// A single non-public group will force the forum to private.
+				if ( 'public' !== $group->status ) {
+					$is_public = false;
+					break;
+				}
+			}
+		}
+
+		return $is_public;
+	}
 }
 endif;
Index: tests/phpunit/bootstrap.php
===================================================================
--- tests/phpunit/bootstrap.php	(revision 5671)
+++ tests/phpunit/bootstrap.php	(working copy)
@@ -21,6 +21,16 @@
  * Load bbPress's PHPUnit test suite loader
  */
 function _load_loader() {
+
+	// Check if we're running the BuddyPress test suite
+	if ( defined( 'BBP_TESTS_BUDDYPRESS' ) ) {
+
+		// If BuddyPress is found, set it up and require it.
+		if ( defined( 'BP_TESTS_DIR' ) ) {
+			require BP_TESTS_DIR . '/includes/loader.php';
+		}
+	}
+
 	require( BBP_TESTS_DIR . '/includes/loader.php' );
 }
 tests_add_filter( 'muplugins_loaded', '_load_loader' );
@@ -30,3 +40,11 @@
 
 echo "Loading bbPress testcase...\n";
 require( BBP_TESTS_DIR . '/includes/testcase.php' );
+require( BBP_TESTS_DIR . '/includes/factory.php' );
+
+if ( defined( 'BBP_TESTS_BUDDYPRESS' ) ) {
+	echo "Loading BuddyPress testcase...\n";
+	require BP_TESTS_DIR . '/includes/testcase.php';
+} else {
+	echo "Not running BuddyPress tests. To execute these, use --group buddypress\n";
+}
Index: tests/phpunit/buddypress.xml
===================================================================
--- tests/phpunit/buddypress.xml	(revision 0)
+++ tests/phpunit/buddypress.xml	(working copy)
@@ -0,0 +1,22 @@
+<phpunit
+	bootstrap="bootstrap.php"
+	backupGlobals="false"
+	colors="true"
+	convertErrorsToExceptions="true"
+	convertNoticesToExceptions="true"
+	convertWarningsToExceptions="true"
+	>
+	<php>
+		<const name="BBP_TESTS_BUDDYPRESS" value="1" />
+	</php>
+	<testsuites>
+		<testsuite>
+			<directory suffix=".php">./testcases/</directory>
+		</testsuite>
+	</testsuites>
+	<groups>
+		<include>
+			<group>buddypress</group>
+		</include>
+	</groups>
+</phpunit>
Index: tests/phpunit/includes/define-constants.php
===================================================================
--- tests/phpunit/includes/define-constants.php	(revision 5671)
+++ tests/phpunit/includes/define-constants.php	(working copy)
@@ -52,3 +52,11 @@
 } else {
 	die( "wp-tests-config.php could not be found.\n" );
 }
+
+// Determine whether BuddyPress is present.
+if ( ! defined( 'BP_TESTS_DIR' ) ) {
+	$wp_content_dir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) );
+	if ( file_exists( $wp_content_dir . '/buddypress/tests/phpunit/bootstrap.php' ) ) {
+		define( 'BP_TESTS_DIR', $wp_content_dir . '/buddypress/tests/phpunit' );
+	}
+}
Index: tests/phpunit/includes/factory.php
===================================================================
--- tests/phpunit/includes/factory.php	(revision 5671)
+++ tests/phpunit/includes/factory.php	(working copy)
@@ -1,7 +1,37 @@
 <?php
 
 class BBP_UnitTest_Factory extends WP_UnitTest_Factory {
-	function __construct() {
+
+	public $forum = null;
+
+	public function __construct() {
 		parent::__construct();
+
+		$this->forum = new BBP_UnitTest_Factory_For_Forum( $this );
 	}
 }
+
+class BBP_UnitTest_Factory_For_Forum extends WP_UnitTest_Factory_For_Thing {
+
+	public function __construct( $factory = null ) {
+		parent::__construct( $factory );
+
+		$this->default_generation_definitions = array(
+			'post_title'   => new WP_UnitTest_Generator_Sequence( 'Forum %s' ),
+			'post_content' => new WP_UnitTest_Generator_Sequence( 'Content of Forum %s' ),
+		);
+	}
+
+	public function create_object( $args ) {
+		return bbp_insert_forum( $args );
+	}
+
+	public function update_object( $forum_id, $fields ) {
+		$fields['forum_id'] = $forum_id;
+		return bbp_update_forum( $fields );
+	}
+
+	public function get_object_by_id( $forum_id ) {
+		return bbp_get_forum( $forum_id );
+	}
+}
Index: tests/phpunit/includes/loader.php
===================================================================
--- tests/phpunit/includes/loader.php	(revision 5671)
+++ tests/phpunit/includes/loader.php	(working copy)
@@ -5,3 +5,5 @@
 
 echo "Determining installation type...\n";
 system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( WP_TESTS_CONFIG_PATH ) . ' ' . escapeshellarg( WP_TESTS_DIR ) . ' ' . $multisite );
+
+require dirname( __FILE__ ) . '/../../../src/bbpress.php';
Index: tests/phpunit/includes/testcase.php
===================================================================
--- tests/phpunit/includes/testcase.php	(revision 5671)
+++ tests/phpunit/includes/testcase.php	(working copy)
@@ -29,6 +29,10 @@
 		}
 
 		$this->factory = new BBP_UnitTest_Factory;
+
+		if ( class_exists( 'BP_UnitTest_Factory' ) ) {
+			$this->bp_factory = new BP_UnitTest_Factory();
+		}
 	}
 
 	function clean_up_global_scope() {
Index: tests/phpunit/multisite.xml
===================================================================
--- tests/phpunit/multisite.xml	(revision 5671)
+++ tests/phpunit/multisite.xml	(working copy)
@@ -14,4 +14,9 @@
 			<directory suffix=".php">./testcases/</directory>
 		</testsuite>
 	</testsuites>
+	<groups>
+		<exclude>
+			<group>buddypress</group>
+		</exclude>
+	</groups>
 </phpunit>
