Ticket #2782: 2782.diff
File 2782.diff, 6.8 KB (added by , 10 years ago) |
---|
-
src/includes/extend/buddypress/groups.php
diff --git src/includes/extend/buddypress/groups.php src/includes/extend/buddypress/groups.php index c07202e..d6fa24d 100644
class BBP_Forums_Group_Extension extends BP_Group_Extension { 143 143 add_filter( 'bbp_current_user_can_access_create_topic_form', array( $this, 'form_permissions' ) ); 144 144 add_filter( 'bbp_current_user_can_access_create_reply_form', array( $this, 'form_permissions' ) ); 145 145 } 146 147 // Enforce forum privacy. 148 add_filter( 'bbp_is_forum_public', array( $this, 'enforce_forum_privacy' ), 10, 3 ); 146 149 } 147 150 148 151 /** … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1462 1465 1463 1466 return $args; 1464 1467 } 1468 1469 public function enforce_forum_privacy( $is_public, $forum_id, $check_ancestors ) { 1470 $group_ids = bbp_get_forum_group_ids( $forum_id ); 1471 1472 if ( ! empty( $group_ids ) ) { 1473 foreach ( $group_ids as $group_id ) { 1474 $group = groups_get_group( array( 'group_id' => $group_id ) ); 1475 1476 // A single non-public group will force the forum to private. 1477 if ( 'public' !== $group->status ) { 1478 $is_public = false; 1479 break; 1480 } 1481 } 1482 } 1483 1484 return $is_public; 1485 } 1465 1486 } 1466 1487 endif; -
tests/phpunit/bootstrap.php
diff --git tests/phpunit/bootstrap.php tests/phpunit/bootstrap.php index 7c981a3..c0489d6 100644
if ( ! file_exists( WP_TESTS_DIR . '/includes/functions.php' ) ) { 21 21 * Load bbPress's PHPUnit test suite loader 22 22 */ 23 23 function _load_loader() { 24 // If BuddyPress is found, set it up and require it. 25 if ( defined( 'BP_TESTS_DIR' ) ) { 26 require BP_TESTS_DIR . '/includes/loader.php'; 27 } 24 28 require( BBP_TESTS_DIR . '/includes/loader.php' ); 25 29 } 26 30 tests_add_filter( 'muplugins_loaded', '_load_loader' ); … … require( WP_TESTS_DIR . '/includes/bootstrap.php' ); 30 34 31 35 echo "Loading bbPress testcase...\n"; 32 36 require( BBP_TESTS_DIR . '/includes/testcase.php' ); 37 require( BBP_TESTS_DIR . '/includes/factory.php' ); 38 39 if ( defined( 'BP_TESTS_DIR' ) ) { 40 echo "Loading BuddyPress testcase...\n"; 41 require BP_TESTS_DIR . '/includes/testcase.php'; 42 } -
tests/phpunit/includes/define-constants.php
diff --git tests/phpunit/includes/define-constants.php tests/phpunit/includes/define-constants.php index 7c5bac3..fba9961 100755
if ( file_exists( WP_ROOT_DIR . '/wp-tests-config.php' ) ) { 52 52 } else { 53 53 die( "wp-tests-config.php could not be found.\n" ); 54 54 } 55 56 // Determine whether BuddyPress is present. 57 if ( ! defined( 'BP_TESTS_DIR' ) ) { 58 $wp_content_dir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ); 59 if ( file_exists( $wp_content_dir . '/buddypress/tests/phpunit/bootstrap.php' ) ) { 60 define( 'BP_TESTS_DIR', $wp_content_dir . '/buddypress/tests/phpunit' ); 61 } 62 } -
tests/phpunit/includes/factory.php
diff --git tests/phpunit/includes/factory.php tests/phpunit/includes/factory.php index 261d216..c6631da 100755
1 1 <?php 2 2 3 3 class BBP_UnitTest_Factory extends WP_UnitTest_Factory { 4 function __construct() { 4 public $forum = null; 5 6 public function __construct() { 5 7 parent::__construct(); 8 9 $this->forum = new BBP_UnitTest_Factory_For_Forum( $this ); 10 } 11 } 12 13 class BBP_UnitTest_Factory_For_Forum extends WP_UnitTest_Factory_For_Thing { 14 public function __construct( $factory = null ) { 15 parent::__construct( $factory ); 16 17 $this->default_generation_definitions = array( 18 'post_title' => new WP_UnitTest_Generator_Sequence( 'Forum %s' ), 19 'post_content' => new WP_UnitTest_Generator_Sequence( 'Content of Forum %s' ), 20 ); 21 } 22 23 public function create_object( $args ) { 24 return bbp_insert_forum( $args ); 25 } 26 27 public function update_object( $forum_id, $fields ) { 28 $fields['forum_id'] = $forum_id; 29 return bbp_update_forum( $fields ); 30 } 31 32 public function get_object_by_id( $forum_id ) { 33 return get_post( $forum_id ); 6 34 } 7 35 } -
tests/phpunit/includes/loader.php
diff --git tests/phpunit/includes/loader.php tests/phpunit/includes/loader.php index 3bc9c7e..d0c987e 100755
$multisite = (int) ( defined( 'WP_TESTS_MULTISITE') && WP_TESTS_MULTISITE ); 5 5 6 6 echo "Determining installation type...\n"; 7 7 system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( WP_TESTS_CONFIG_PATH ) . ' ' . escapeshellarg( WP_TESTS_DIR ) . ' ' . $multisite ); 8 9 require dirname( __FILE__ ) . '/../../../src/bbpress.php'; -
tests/phpunit/includes/testcase.php
diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php index 7cda2f9..4294952 100755
class BBP_UnitTestCase extends WP_UnitTestCase { 29 29 } 30 30 31 31 $this->factory = new BBP_UnitTest_Factory; 32 33 if ( class_exists( 'BP_UnitTest_Factory' ) ) { 34 $this->bp_factory = new BP_UnitTest_Factory(); 35 } 32 36 } 33 37 34 38 function clean_up_global_scope() { -
new file tests/phpunit/testcases/extend/buddypress/groups.php
diff --git tests/phpunit/testcases/extend/buddypress/groups.php tests/phpunit/testcases/extend/buddypress/groups.php new file mode 100644 index 0000000..a47c0d6
- + 1 <?php 2 3 /** 4 * @group extend 5 * @group buddypress 6 * @group groups 7 */ 8 class BBP_Tests_Extend_BuddyPress_Groups extends BBP_UnitTestCase { 9 public function setUp() { 10 parent::setUp(); 11 12 if ( ! function_exists( 'buddypress' ) ) { 13 return; 14 } 15 } 16 17 /** 18 * Copied from `BBP_Forums_Group_Extension::new_forum()`. 19 */ 20 private function attach_forum_to_group( $forum_id, $group_id ) { 21 bbp_add_forum_id_to_group( $group_id, $forum_id ); 22 bbp_add_group_id_to_forum( $forum_id, $group_id ); 23 } 24 25 /** 26 * @ticket BBP2327 27 */ 28 public function test_bbp_is_forum_public_should_be_true_for_public_group_forums() { 29 $g = $this->bp_factory->group->create( array( 30 'status' => 'public', 31 ) ); 32 33 $f = $this->factory->forum->create(); 34 35 $this->attach_forum_to_group( $f, $g ); 36 37 $this->assertTrue( bbp_is_forum_public( $f ) ); 38 } 39 40 /** 41 * @ticket BBP2327 42 */ 43 public function test_bbp_is_forum_public_should_be_false_for_private_group_forums() { 44 $g = $this->bp_factory->group->create( array( 45 'status' => 'private', 46 ) ); 47 48 $f = $this->factory->forum->create(); 49 50 $this->attach_forum_to_group( $f, $g ); 51 52 $this->assertFalse( bbp_is_forum_public( $f ) ); 53 } 54 55 /** 56 * @ticket BBP2327 57 */ 58 public function test_bbp_is_forum_public_should_be_false_for_hidden_group_forums() { 59 $g = $this->bp_factory->group->create( array( 60 'status' => 'hidden', 61 ) ); 62 63 $f = $this->factory->forum->create(); 64 65 $this->attach_forum_to_group( $f, $g ); 66 67 $this->assertFalse( bbp_is_forum_public( $f ) ); 68 } 69 }