Skip to:
Content

bbPress.org

Ticket #2782: 2782.2.diff

File 2782.2.diff, 7.4 KB (added by netweb, 10 years ago)
  • Gruntfile.js

     
    239239                                cmd: 'phpunit',
    240240                                args: [ '-c', 'phpunit.xml.dist' ]
    241241                        },
     242                        buddypress: {
     243                                cmd: 'phpunit',
     244                                args: [ '-c', 'tests/phpunit/buddypress.xml' ]
     245                        },
    242246                        multisite: {
    243247                                cmd: 'phpunit',
    244248                                args: [ '-c', 'tests/phpunit/multisite.xml' ]
     
    334338        grunt.registerTask( 'release', [ 'build' ] );
    335339
    336340        // PHPUnit test task.
    337         grunt.registerMultiTask( 'phpunit', 'Runs PHPUnit tests, including the ajax and multisite tests.', function() {
     341        grunt.registerMultiTask( 'phpunit', 'Runs PHPUnit tests, including the BuddyPress and multisite tests.', function() {
    338342                grunt.util.spawn( {
    339343                        cmd:  this.data.cmd,
    340344                        args: this.data.args,
  • phpunit.xml.dist

     
    77        convertWarningsToExceptions="true"
    88        >
    99        <testsuites>
    10         <testsuite>
    11             <directory suffix=".php">tests/phpunit/testcases/</directory>
    12         </testsuite>
    13     </testsuites>
     10                <testsuite>
     11                        <directory suffix=".php">tests/phpunit/testcases/</directory>
     12                </testsuite>
     13        </testsuites>
     14        <groups>
     15                <exclude>
     16                        <group>buddypress</group>
     17                </exclude>
     18        </groups>
    1419</phpunit>
  • src/includes/extend/buddypress/groups.php

     
    143143                        add_filter( 'bbp_current_user_can_access_create_topic_form', array( $this, 'form_permissions' ) );
    144144                        add_filter( 'bbp_current_user_can_access_create_reply_form', array( $this, 'form_permissions' ) );
    145145                }
     146
     147                // Enforce forum privacy.
     148                add_filter( 'bbp_is_forum_public', array( $this, 'enforce_forum_privacy' ), 10, 3 );
    146149        }
    147150
    148151        /**
     
    14621465
    14631466                return $args;
    14641467        }
     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        }
    14651486}
    14661487endif;
  • tests/phpunit/bootstrap.php

     
    2121 * Load bbPress's PHPUnit test suite loader
    2222 */
    2323function _load_loader() {
     24
     25        // Check if we're running the BuddyPress test suite
     26        if ( defined( 'BBP_TESTS_BUDDYPRESS' ) ) {
     27
     28                // If BuddyPress is found, set it up and require it.
     29                if ( defined( 'BP_TESTS_DIR' ) ) {
     30                        require BP_TESTS_DIR . '/includes/loader.php';
     31                }
     32        }
     33
    2434        require( BBP_TESTS_DIR . '/includes/loader.php' );
    2535}
    2636tests_add_filter( 'muplugins_loaded', '_load_loader' );
     
    3040
    3141echo "Loading bbPress testcase...\n";
    3242require( BBP_TESTS_DIR . '/includes/testcase.php' );
     43require( BBP_TESTS_DIR . '/includes/factory.php' );
     44
     45if ( defined( 'BBP_TESTS_BUDDYPRESS' ) ) {
     46        echo "Loading BuddyPress testcase...\n";
     47        require BP_TESTS_DIR . '/includes/testcase.php';
     48} else {
     49        echo "Not running BuddyPress tests. To execute these, use --group buddypress\n";
     50}
  • tests/phpunit/buddypress.xml

     
     1<phpunit
     2        bootstrap="bootstrap.php"
     3        backupGlobals="false"
     4        colors="true"
     5        convertErrorsToExceptions="true"
     6        convertNoticesToExceptions="true"
     7        convertWarningsToExceptions="true"
     8        >
     9        <php>
     10                <const name="BBP_TESTS_BUDDYPRESS" value="1" />
     11        </php>
     12        <testsuites>
     13                <testsuite>
     14                        <directory suffix=".php">./testcases/</directory>
     15                </testsuite>
     16        </testsuites>
     17        <groups>
     18                <include>
     19                        <group>buddypress</group>
     20                </include>
     21        </groups>
     22</phpunit>
  • tests/phpunit/includes/define-constants.php

     
    5252} else {
    5353        die( "wp-tests-config.php could not be found.\n" );
    5454}
     55
     56// Determine whether BuddyPress is present.
     57if ( ! 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

     
    11<?php
    22
    33class BBP_UnitTest_Factory extends WP_UnitTest_Factory {
    4         function __construct() {
     4
     5        public $forum = null;
     6
     7        public function __construct() {
    58                parent::__construct();
     9
     10                $this->forum = new BBP_UnitTest_Factory_For_Forum( $this );
    611        }
    712}
     13
     14class BBP_UnitTest_Factory_For_Forum extends WP_UnitTest_Factory_For_Thing {
     15
     16        public function __construct( $factory = null ) {
     17                parent::__construct( $factory );
     18
     19                $this->default_generation_definitions = array(
     20                        'post_title'   => new WP_UnitTest_Generator_Sequence( 'Forum %s' ),
     21                        'post_content' => new WP_UnitTest_Generator_Sequence( 'Content of Forum %s' ),
     22                );
     23        }
     24
     25        public function create_object( $args ) {
     26                return bbp_insert_forum( $args );
     27        }
     28
     29        public function update_object( $forum_id, $fields ) {
     30                $fields['forum_id'] = $forum_id;
     31                return bbp_update_forum( $fields );
     32        }
     33
     34        public function get_object_by_id( $forum_id ) {
     35                return bbp_get_forum( $forum_id );
     36        }
     37}
  • tests/phpunit/includes/loader.php

     
    55
    66echo "Determining installation type...\n";
    77system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( WP_TESTS_CONFIG_PATH ) . ' ' . escapeshellarg( WP_TESTS_DIR ) . ' ' . $multisite );
     8
     9require dirname( __FILE__ ) . '/../../../src/bbpress.php';
  • tests/phpunit/includes/testcase.php

     
    2929                }
    3030
    3131                $this->factory = new BBP_UnitTest_Factory;
     32
     33                if ( class_exists( 'BP_UnitTest_Factory' ) ) {
     34                        $this->bp_factory = new BP_UnitTest_Factory();
     35                }
    3236        }
    3337
    3438        function clean_up_global_scope() {
  • tests/phpunit/multisite.xml

     
    1414                        <directory suffix=".php">./testcases/</directory>
    1515                </testsuite>
    1616        </testsuites>
     17        <groups>
     18                <exclude>
     19                        <group>buddypress</group>
     20                </exclude>
     21        </groups>
    1722</phpunit>