Skip to:
Content

BuddyPress.org

Changeset 14026


Ignore:
Timestamp:
09/27/2024 09:11:27 PM (6 months ago)
Author:
espellcaste
Message:

Include the V2 of the BP REST API in BuddyPress core.

We are officially deprecating the V1 of the BP REST API. And bundling the new, default, V2 of the BP REST API inside BuddyPress core. Previously, the V1 was developed as a plugin in a separate repo (https://github.com/buddypress/BP-REST).

  • One of the main differences between the V1 and V2 is how objects are returned. Single items are no longer returned as an array;
  • We have a new BP_Test_REST_Controller_Testcase for testing the new API endpoints;
  • We changed the names of our controllers to follow our autoloader rules;
  • Removed the BP-REST plugin from wp-env and from our release script;
  • And we added notices for the deprecated V1 API (endpoints and files).

Props imath & I. ;)

Fixes #8200
See #9145
Closes https://github.com/buddypress/buddypress/pull/337

Location:
trunk
Files:
66 added
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/.wp-env.json

    r13684 r14026  
    11{
    22    "core": "WordPress/WordPress#master",
    3     "plugins": [".", "buddypress/BP-REST#master"],
     3    "plugins": ["."],
    44    "config": {
    55        "WP_DEBUG": true,
  • trunk/Gruntfile.js

    r13850 r14026  
    7676                 *
    7777                 * @param {String} filepath
    78                  * @returns {Bool}
     78                 * @returns {Boolean}
    7979                 */
    8080                filter: function( filepath ) {
     
    9191
    9292                    // Match only the filename passed from cli
    93                     if ( filepath === file || ( -1 !== index && index === filepath.length - ( file.length + 1 ) ) ) {
    94                         return true;
    95                     }
    96 
    97                     return false;
     93                    return filepath === file || (-1 !== index && index === filepath.length - (file.length + 1));
    9894                }
    9995            }
     
    199195        clean: {
    200196            all: [ BUILD_DIR ],
    201             bp_rest: [ BUILD_DIR + 'bp-rest/' ],
    202197            bp_admin_modern_js: [ 'dist/' ],
    203198            cli: [
     
    225220                ]
    226221            },
    227             bp_rest_components: {
    228                 cwd: BUILD_DIR + 'bp-rest/includes/',
    229                 dest: BUILD_DIR,
    230                 dot: true,
    231                 expand: true,
    232                 src: ['**/bp-activity/**', '**/bp-blogs/**', '**/bp-friends/**', '**/bp-groups/**', '**/bp-members/**', '**/bp-messages/**', '**/bp-notifications/**', '**/bp-settings/**', '**/bp-xprofile/**'],
    233                 options: {
    234                     process : function( content ) {
    235                         return content.replace( /\@since 0\.1\.0/g, '@since 5.0.0' );
    236                     }
    237                 }
    238             },
    239             bp_rest_core: {
    240                 cwd: BUILD_DIR + 'bp-rest/includes/',
    241                 dest: BUILD_DIR + 'bp-core/classes/',
    242                 dot: true,
    243                 expand: true,
    244                 flatten: true,
    245                 filter: 'isFile',
    246                 src: ['**', '!functions.php', '!**/bp-activity/**', '!**/bp-blogs/**', '!**/bp-friends/**', '!**/bp-groups/**', '!**/bp-members/**', '!**/bp-messages/**', '!**/bp-notifications/**', '!**/bp-settings/**', '!**/bp-xprofile/**'],
    247                 options: {
    248                     process : function( content ) {
    249                         return content.replace( /\@since 0\.1\.0/g, '@since 5.0.0' );
    250                     }
    251                 }
    252             },
    253222            bp_admin_modern_js: {
    254223                cwd: 'dist/',
     
    351320                command: 'composer run phpcompat',
    352321                stdout: true
    353             },
    354             rest_api: {
    355                 command: 'npm run download:rest',
    356                 cwd: BUILD_DIR,
    357                 stdout: false
    358322            },
    359323            makepot: {
     
    409373    grunt.registerTask( 'commit', ['src', 'checktextdomain', 'imagemin', 'phplint', 'exec:phpcs_escape', 'exec:phpcompat'] );
    410374    grunt.registerTask( 'commit:blocks', ['commit', 'exec:blocks_src', 'exec:modernJS_src'] );
    411     grunt.registerTask( 'bp_rest', [ 'exec:rest_api', 'copy:bp_rest_components', 'copy:bp_rest_core', 'clean:bp_rest' ] );
    412     grunt.registerTask( 'build', ['commit:blocks', 'clean:all', 'copy:files', 'uglify:core', 'jsvalidate:build', 'cssmin', 'bp_rest', 'makepot', 'exec:cli', 'clean:cli'] );
     375    grunt.registerTask( 'build', ['commit:blocks', 'clean:all', 'copy:files', 'uglify:core', 'jsvalidate:build', 'cssmin', 'makepot', 'exec:cli', 'clean:cli'] );
    413376    grunt.registerTask( 'release', ['build'] );
    414377    grunt.registerTask( 'move:admin:js', [ 'copy:bp_admin_modern_js', 'clean:bp_admin_modern_js' ] );
  • trunk/docs/contributor/code/README.md

    r13769 r14026  
    111111```
    112112
    113 You should see that your `~/Plugins/buddypress` directory now contains 1 or 2 more sub directories: `/node_modules` and `/vendor` if you installed the composer packages.
     113You should see that your `~/Plugins/buddypress` directory now contains 1 or 2 more subdirectories: `/node_modules` and `/vendor` if you installed the composer packages.
    114114
    115115![Check installs](../assets/code-003-install-tools.png)
     
    121121```
    122122
    123 The first time you’ll execute this command it will take some time to run and you’ll see that 2 downloads will start:
    124 
    125 - [BP REST](https://github.com/buddypress/BP-REST): it’s the plugin we use to develop the BP REST API.
     123The first time you’ll execute this command it will take some time to run, and you’ll see that the following download will start:
     124
    126125- [WordPress](https://core.trac.wordpress.org/browser/trunk): it’s the WordPress development version.
    127126
     
    176175### Customizing your BuddyPress local development environment
    177176
    178 To develop BuddyPress we use the development version of [WordPress](https://core.trac.wordpress.org/browser/trunk), the development version of the [BP REST API](https://github.com/buddypress/BP-REST) and we set two debugging constants:
     177To develop BuddyPress we use the development version of [WordPress](https://core.trac.wordpress.org/browser/trunk), and we set two debugging constants:
    179178
    180179```php
     
    190189{
    191190    "core": "WordPress/WordPress#master",
    192     "plugins": [ ".", "buddypress/BP-REST#master", "buddypress/bp-classic#trunk" ],
     191    "plugins": [ ".", "buddypress/bp-classic#trunk" ],
    193192    "config": {
    194193        "WP_DEBUG": true,
     
    206205## Patching BuddyPress
    207206
    208 Let’s work with a real bug example (It might has been fixed when you’ll read this page!) to understand how to suggest a fix to the BuddyPress development team. First, open the `~/Plugins/buddypress` directory into your favorite code editor.
     207Let’s work with a real bug example (It might have been fixed when you’ll read this page!) to understand how to suggest a fix to the BuddyPress development team. First, open the `~/Plugins/buddypress` directory into your favorite code editor.
    209208
    210209![BP in VSCode](../assets/code-004-vscode-bp.png)
  • trunk/package.json

    r13953 r14026  
    5656        "test-php-multisite": "npm run wp-env run cli -- --env-cwd=wp-content/plugins/buddypress composer test_multi",
    5757        "test-php-multisite:group": "npm run wp-env run cli -- --env-cwd=wp-content/plugins/buddypress composer test_multi -- -- --group ",
    58         "download:cli": "curl -L -o 'cli-archive.zip' https://github.com/buddypress/wp-cli-buddypress/archive/3.0.1.zip && unzip -qq cli-archive.zip && mv wp-cli-buddypress-3.0.1 build/cli && rm cli-archive.zip",
    59         "download:rest": "curl -L -o 'rest-archive.zip' https://github.com/buddypress/BP-REST/archive/master.zip && unzip -qq rest-archive.zip && mv BP-REST-master build/bp-rest && rm rest-archive.zip"
     58        "download:cli": "curl -L -o 'cli-archive.zip' https://github.com/buddypress/wp-cli-buddypress/archive/3.0.1.zip && unzip -qq cli-archive.zip && mv wp-cli-buddypress-3.0.1 build/cli && rm cli-archive.zip"
    6059    },
    6160    "keywords": [
  • trunk/phpcs.xml.dist

    r14016 r14026  
    6363        <exclude name="WordPress.DB.DirectDatabaseQuery.SchemaChange" />
    6464        <exclude name="WordPress.DB.DirectDatabaseQuery.DirectQuery" />
    65 
    6665    </rule>
    6766</ruleset>
  • trunk/phpunit.xml.dist

    r13859 r14026  
    1010        <testsuite name="default">
    1111            <directory suffix=".php">./tests/phpunit/testcases/</directory>
     12
     13            <exclude>./tests/phpunit/testcases/blogs/test-controller.php</exclude>
     14            <exclude>./tests/phpunit/testcases/blogs/test-blog-avatar-controller.php</exclude>
    1215        </testsuite>
    1316    </testsuites>
  • trunk/src/bp-activity/classes/class-bp-activity-component.php

    r13689 r14026  
    3333            array(
    3434                'adminbar_myaccount_order' => 10,
    35                 'search_query_arg' => 'activity_search',
    36                 'features' => array( 'embeds' )
     35                'search_query_arg'         => 'activity_search',
     36                'features'                 => array( 'embeds' ),
    3737            )
    3838        );
     
    152152
    153153            if ( bp_is_active( 'friends' ) ) {
    154                 $filenames[bp_get_friends_slug()] = 'friends';
     154                $filenames[ bp_get_friends_slug() ] = 'friends';
    155155            }
    156156
    157157            if ( bp_is_active( 'groups' ) ) {
    158                 $filenames[bp_get_groups_slug()] = 'groups';
     158                $filenames[ bp_get_groups_slug() ] = 'groups';
    159159            }
    160160
     
    210210        // Fetch the default directory title.
    211211        $default_directory_titles = bp_core_get_directory_page_default_titles();
    212         $default_directory_title  = $default_directory_titles[$this->id];
     212        $default_directory_title  = $default_directory_titles[ $this->id ];
    213213
    214214        // All globals for activity component.
     
    231231                'bp/latest-activities' => array(
    232232                    'widget_classnames' => array( 'wp-block-bp-latest-activities', 'buddypress' ),
    233                 )
     233                ),
    234234            ),
    235235        );
     
    258258            'screen_function'     => 'bp_activity_screen_my_activity',
    259259            'default_subnav_slug' => 'just-me',
    260             'item_css_id'         => $this->id
     260            'item_css_id'         => $this->id,
    261261        );
    262262
     
    267267            'parent_slug'     => $slug,
    268268            'screen_function' => 'bp_activity_screen_my_activity',
    269             'position'        => 10
     269            'position'        => 10,
    270270        );
    271271
     
    312312                'screen_function' => 'bp_activity_screen_groups',
    313313                'position'        => 50,
    314                 'item_css_id'     => 'activity-groups'
     314                'item_css_id'     => 'activity-groups',
    315315            );
    316316        }
     
    409409                    'title'    => _x( 'Groups', 'My Account Activity sub nav', 'buddypress' ),
    410410                    'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug, bp_get_groups_slug() ) ) ),
    411                     'position' => 50
     411                    'position' => 50,
    412412                );
    413413            }
     
    421421     *
    422422     * @since 1.5.0
    423      *
    424423     */
    425424    public function setup_title() {
     
    432431                $bp->bp_options_title = _x( 'My Activity', 'Page and <title>', 'buddypress' );
    433432            } else {
    434                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    435                     'item_id' => bp_displayed_user_id(),
    436                     'type'    => 'thumb',
    437                     'alt'     => sprintf(
     433                $bp->bp_options_avatar = bp_core_fetch_avatar(
     434                    array(
     435                        'item_id' => bp_displayed_user_id(),
     436                        'type'    => 'thumb',
     437                        'alt'     => sprintf(
    438438                        /* translators: %s: member name */
    439                         __( 'Profile picture of %s', 'buddypress' ),
    440                         bp_get_displayed_user_fullname()
    441                     ),
    442                 ) );
     439                            __( 'Profile picture of %s', 'buddypress' ),
     440                            bp_get_displayed_user_fullname()
     441                        ),
     442                    )
     443                );
    443444                $bp->bp_options_title  = bp_get_displayed_user_fullname();
    444445            }
     
    456457
    457458        // Global groups.
    458         wp_cache_add_global_groups( array(
    459             'bp_activity',
    460             'bp_activity_comments',
    461             'activity_meta'
    462         ) );
     459        wp_cache_add_global_groups(
     460            array(
     461                'bp_activity',
     462                'bp_activity_comments',
     463                'activity_meta',
     464            )
     465        );
    463466
    464467        parent::setup_cache_groups();
     
    525528     */
    526529    public function rest_api_init( $controllers = array() ) {
    527         parent::rest_api_init( array( 'BP_REST_Activity_Endpoint' ) );
     530        parent::rest_api_init( array( 'BP_Activity_REST_Controller' ) );
    528531    }
    529532
     
    548551            $blocks['bp/embed-activity'] = array(
    549552                'metadata' => trailingslashit( buddypress()->plugin_dir ) . 'bp-activity/blocks/embed-activity',
    550 
    551553            );
    552554        }
  • trunk/src/bp-blogs/bp-blogs-filters.php

    r13476 r14026  
    190190    return $retval;
    191191}
     192
     193/**
     194 * Filter the Blog url in the WP_REST_Request::from_url().
     195 *
     196 * First part in embedding the latest blog post.
     197 *
     198 * @link https://github.com/buddypress/BP-REST/pull/395
     199 *
     200 * @param WP_REST_Request $request Request used to generate the response.
     201 * @param string          $url     URL being requested.
     202 * @return WP_REST_Request
     203 */
     204function bp_filter_rest_request_blog_url( $request, $url ) {
     205
     206    if ( ! bp_is_active( 'blogs' ) || empty( $url ) ) {
     207        return $request;
     208    }
     209
     210    // Get url info.
     211    $bits      = wp_parse_url( $url );
     212    $home_bits = wp_parse_url( get_home_url() );
     213
     214    if ( empty( $bits['host'] ) || empty( $home_bits['host'] ) ) {
     215        return $request;
     216    }
     217
     218    // Bail early if the request URL is the same as the current site.
     219    if ( $bits['host'] === $home_bits['host'] ) {
     220        return $request;
     221    }
     222
     223    // Create a fake request to bypass the current logic.
     224    $request = new WP_REST_Request( 'GET', $bits['path'] );
     225    $request->set_query_params( array( 'bp_blogs_url' => $url ) );
     226
     227    return $request;
     228}
     229add_filter( 'rest_request_from_url', 'bp_filter_rest_request_blog_url', 10, 2 );
     230
     231/**
     232 * Output BuddyPress blog response.
     233 *
     234 * Second part in embedding the latest blog post.
     235 *
     236 * @link https://github.com/buddypress/BP-REST/pull/395
     237 *
     238 * @param WP_REST_Response $response Response generated by the request.
     239 * @param WP_REST_Server   $instance Server instance.
     240 * @param WP_REST_Request  $request  Request used to generate the response.
     241 * @return WP_REST_Response
     242 */
     243function bp_rest_post_dispatch( $response, $instance, $request ) {
     244    if (
     245        ! bp_is_active( 'blogs' )
     246        || 404 !== $response->get_status()
     247        || 'embed' !== $request->get_param( 'context' )
     248        || empty( $request->get_param( 'bp_blogs_url' ) )
     249        || empty( $request->get_route() )
     250    ) {
     251        return $response;
     252    }
     253
     254    // Get domain from url.
     255    $bits = wp_parse_url( $request->get_param( 'bp_blogs_url' ) );
     256
     257    // We need those two to proceed.
     258    if ( empty( $bits['host'] ) || empty( $bits['path'] ) ) {
     259        return $response;
     260    }
     261
     262    // Request route and requested URL path should match.
     263    if ( $request->get_route() !== $bits['path'] ) {
     264        return $response;
     265    }
     266
     267    // Get site using the domain.
     268    $site = get_site_by_path( $bits['host'], $bits['path'] );
     269
     270    if ( ! $site instanceof WP_Site || empty( $site->blog_id ) ) {
     271        return $response;
     272    }
     273
     274    switch_to_blog( absint( $site->blog_id ) );
     275
     276    $response = rest_do_request(
     277        new WP_REST_Request(
     278            'GET',
     279            str_replace(
     280                '/wp-json',
     281                '',
     282                $request->get_route()
     283            )
     284        )
     285    );
     286
     287    restore_current_blog();
     288
     289    // Return it, regardless if it was successful.
     290    return $response;
     291}
     292add_filter( 'rest_post_dispatch', 'bp_rest_post_dispatch', 10, 3 );
  • trunk/src/bp-blogs/bp-blogs-template.php

    r13970 r14026  
    374374        $alt_attribute = __( 'Site icon for the blog', 'buddypress' );
    375375
    376         if ( ! $blogs_template && isset( $args['blog_id'] ) && $args['blog_id'] ) {
     376        $has_current_blog = isset( $blogs_template ) && isset( $blogs_template->blog->blog_id );
     377
     378        if ( false === $has_current_blog && isset( $args['blog_id'] ) && $args['blog_id'] ) {
    377379            $blog_id = (int) $args['blog_id'];
    378         } else {
     380        } else if ( true === $has_current_blog ) {
    379381            $blog_id = bp_get_blog_id();
    380382
    381383            /* translators: %s is the blog name */
    382384            $alt_attribute = sprintf( __( 'Site icon for %s', 'buddypress' ), bp_get_blog_name() );
     385        } else {
     386            $blog_id = 0;
    383387        }
    384388
  • trunk/src/bp-blogs/classes/class-bp-blogs-component.php

    r14010 r14026  
    512512    public function rest_api_init( $controllers = array() ) {
    513513        if ( is_multisite() ) {
    514             $controllers = array( 'BP_REST_Blogs_Endpoint' );
     514            $controllers = array( 'BP_Blogs_REST_Controller' );
    515515
    516516            // Support to Blog Avatar.
    517517            if ( bp_is_active( 'blogs', 'site-icon' ) ) {
    518                 $controllers[] = 'BP_REST_Attachments_Blog_Avatar_Endpoint';
     518                $controllers[] = 'BP_Blogs_Avatar_REST_Controller';
    519519            }
    520520        }
  • trunk/src/bp-blogs/classes/class-bp-blogs-recent-posts-widget.php

    r13802 r14026  
    1212defined( 'ABSPATH' ) || exit;
    1313
    14 _deprecated_file( basename( __FILE__ ), '12.0.0', '', esc_html__( 'BuddyPress does not include Legacy Widgets anymore, you can restore it using the BP Classic plugin', 'buddypress' ) );
     14_deprecated_file(
     15    basename( __FILE__ ),
     16    '12.0.0',
     17    '',
     18    esc_html__( 'BuddyPress does not include Legacy Widgets anymore, you can restore it using the BP Classic plugin', 'buddypress' )
     19);
    1520
    1621/**
  • trunk/src/bp-core/bp-core-functions.php

    r14013 r14026  
    50075007    /*
    50085008     * If the constant is not defined, put our logic in place so that only the
    5009      * 2 last versions deprecated functions will be loaded for upgraded installs.
     5009     * 2 last versions deprecated functions will be loaded for upgraded installations.
    50105010     */
    50115011    $initial_version        = (float) bp_get_initial_version();
     
    50135013    $load_latest_deprecated = $initial_version < $current_major_version;
    50145014
    5015     // New installs.
     5015    // New installations.
    50165016    if ( ! $load_latest_deprecated ) {
    50175017        // Run some additional checks if PHPUnit is running.
     
    50195019            $deprecated_files = array_filter(
    50205020                array_map(
    5021                     function( $file ) {
    5022                         if ( false !== strpos( $file, '.php' ) ) {
     5021                    function ( $file ) {
     5022                        if ( str_contains( $file, '.php' ) ) {
    50235023                            return (float) str_replace( '.php', '', $file );
    5024                         };
     5024                        }
     5025
     5026                        return null;
    50255027                    },
    50265028                    scandir( buddypress()->plugin_dir . 'bp-core/deprecated' )
  • trunk/src/bp-core/bp-core-rest-api.php

    r14013 r14026  
    1212
    1313/**
    14  * Is the BP REST plugin is active?
     14 * Is the BP REST plugin active?
    1515 *
    1616 * @since 5.0.0
     
    2323
    2424/**
    25  * Should we use the REST Endpoints of built BuddyPress?
     25 * Should we use BuddyPress core REST Endpoints?
    2626 *
    2727 * If the BP REST plugin is active, it overrides BuddyPress REST endpoints.
    28  * This allows us to carry on maintaining all the BP REST API endpoints from
    29  * the BP REST plugin on GitHub.
    30  *
    31  * @since 5.0.0
    32  *
    33  * @return bool Whether to use the REST Endpoints of built BuddyPress.
     28 *
     29 * @since 5.0.0
     30 *
     31 * @return bool Whether to use BuddyPress core REST endpoints.
    3432 */
    3533function bp_rest_in_buddypress() {
    36     return ! bp_is_running_from_src_subdirectory() && ! bp_rest_is_plugin_active();
     34    return ! bp_rest_is_plugin_active();
    3735}
    3836
     
    5553     * @param bool $api_is_available True if the BP REST API is available. False otherwise.
    5654     */
    57     return apply_filters( 'bp_rest_api_is_available', bp_rest_in_buddypress() ) || bp_rest_is_plugin_active();
    58 }
    59 
    60 /**
    61  * Register the jQuery.ajax wrapper for BP REST API requests.
    62  *
    63  * @since 5.0.0
    64  * @deprecated 10.0.0
    65  */
    66 function bp_rest_api_register_request_script() {
    67     if ( ! bp_rest_api_is_available() ) {
    68         return;
    69     }
    70 
    71     wp_register_script(
    72         'bp-api-request',
    73         sprintf( '%1$sbp-core/js/bp-api-request%2$s.js', buddypress()->plugin_url, bp_core_get_minified_asset_suffix() ),
    74         array( 'jquery', 'wp-api-request' ),
    75         bp_get_version(),
    76         true
    77     );
    78 
    79     wp_localize_script(
    80         'bp-api-request',
    81         'bpApiSettings',
    82         array(
    83             'unexpectedError'   => __( 'An unexpected error occured. Please try again.', 'buddypress' ),
    84             'deprecatedWarning' => __( 'The bp.apiRequest function is deprecated since BuddyPress 10.0.0, please use wp.apiRequest instead.', 'buddypress' ),
    85         )
    86     );
    87 }
    88 add_action( 'bp_init', 'bp_rest_api_register_request_script' );
     55    return apply_filters( 'bp_rest_api_is_available', ( bp_rest_in_buddypress() || bp_rest_is_plugin_active() ) );
     56}
    8957
    9058/**
     
    11179 *
    11280 * @since 5.0.0
     81 * @since 15.0.0 Version is now v2.
    11382 *
    11483 * @return string
     
    12089     *
    12190     * @since 5.0.0
    122      *
    123      * @param string $version BuddyPress core version.
     91     * @since 15.0.0 Default version is now v2.
     92     *
     93     * @param string $bp_version BuddyPress REST API version.
    12494     */
    125     return apply_filters( 'bp_rest_version', 'v1' );
     95    return apply_filters( 'bp_rest_version', 'v2' );
    12696}
    12797
     
    198168 *
    199169 * @param string $value Comma-separated list of group types.
    200  * @return array|null
     170 * @return array|null|string
    201171 */
    202172function bp_rest_sanitize_member_types( $value ) {
     
    210180    $valid_types        = array_intersect( $types, $registered_types );
    211181
    212     return ( ! empty( $valid_types ) ) ? $valid_types : null;
     182    return ! empty( $valid_types ) ? $valid_types : null;
    213183}
    214184
     
    219189 *
    220190 * @param  mixed $value Mixed value.
    221  * @return WP_Error|bool
     191 * @return WP_Error|true
    222192 */
    223193function bp_rest_validate_member_types( $value ) {
     
    244214        }
    245215    }
     216
     217    return true;
    246218}
    247219
     
    251223 * @since 5.0.0
    252224 *
    253  * @param string $value Comma-separated list of group types.
     225 * @param string $group_types Comma-separated list of group types.
    254226 * @return array|null
    255227 */
    256 function bp_rest_sanitize_group_types( $value ) {
    257     if ( empty( $value ) ) {
     228function bp_rest_sanitize_group_types( $group_types ) {
     229    if ( empty( $group_types ) ) {
    258230        return null;
    259231    }
    260232
    261     $types       = explode( ',', $value );
     233    $types       = explode( ',', $group_types );
    262234    $valid_types = array_intersect( $types, bp_groups_get_group_types() );
    263235
     
    270242 * @since 5.0.0
    271243 *
    272  * @param  mixed $value Mixed value.
     244 * @param  mixed $group_types Mixed value.
    273245 * @return WP_Error|bool
    274246 */
    275 function bp_rest_validate_group_types( $value ) {
    276     if ( empty( $value ) ) {
     247function bp_rest_validate_group_types( $group_types ) {
     248    if ( empty( $group_types ) ) {
    277249        return true;
    278250    }
    279251
    280     $types            = explode( ',', $value );
     252    $types            = explode( ',', $group_types );
    281253    $registered_types = bp_groups_get_group_types();
    282254    foreach ( $types as $type ) {
     
    293265        }
    294266    }
     267
     268    return true;
    295269}
    296270
     
    388362    return isset( $registered_fields[ $attribute ] );
    389363}
     364
     365/**
     366 * Filter the WP REST API response to return a 404 if the request is for the V1 of the BP REST API.
     367 *
     368 * @param mixed           $result Response to replace the requested version with. Can be anything
     369 *                                a normal endpoint can return, or null to not hijack the request.
     370 * @param WP_REST_Server  $server Server instance.
     371 * @param WP_REST_Request $request Request used to generate the response.
     372 *
     373 * @return mixed
     374 */
     375function bp_rest_api_v1_dispatch_error( $result, $server, $request ) {
     376
     377    // Bail early if the BP REST plugin is active.
     378    if ( bp_rest_is_plugin_active() ) {
     379        return $result;
     380    }
     381
     382    $route = $request->get_route();
     383
     384    if ( empty( $route ) || ! str_contains( $route, 'buddypress/v1' ) ) {
     385        return $result;
     386    }
     387
     388    return new WP_Error(
     389        'rest_no_route',
     390        __( 'The V1 of the BuddyPress REST API is no longer supported, use the V2 instead.', 'buddypress' ),
     391        array( 'status' => 404 )
     392    );
     393}
     394add_filter( 'rest_pre_dispatch', 'bp_rest_api_v1_dispatch_error', 10, 3 );
     395
     396/**
     397 * Register the jQuery.ajax wrapper for BP REST API requests.
     398 *
     399 * @since 5.0.0
     400 * @deprecated 10.0.0
     401 */
     402function bp_rest_api_register_request_script() {
     403    if ( ! bp_rest_api_is_available() ) {
     404        return;
     405    }
     406
     407    wp_register_script(
     408        'bp-api-request',
     409        sprintf( '%1$sbp-core/js/bp-api-request%2$s.js', buddypress()->plugin_url, bp_core_get_minified_asset_suffix() ),
     410        array( 'jquery', 'wp-api-request' ),
     411        bp_get_version(),
     412        true
     413    );
     414
     415    wp_localize_script(
     416        'bp-api-request',
     417        'bpApiSettings',
     418        array(
     419            'unexpectedError'   => __( 'An unexpected error occurred. Please try again.', 'buddypress' ),
     420            'deprecatedWarning' => __( 'The bp.apiRequest function is deprecated since BuddyPress 10.0.0, please use wp.apiRequest instead.', 'buddypress' ),
     421        )
     422    );
     423}
     424add_action( 'bp_init', 'bp_rest_api_register_request_script' );
  • trunk/src/bp-core/classes/class-bp-component.php

    r13943 r14026  
    247247     *
    248248     * @param string $id   Unique ID. Letters, numbers, and underscores only.
    249      * @param string $name Unique name. This should be a translatable name, eg.
    250      *                     __( 'Groups', 'buddypress' ).
     249     * @param string $name Unique name. This should be a translatable name, e.g. __( 'Groups', 'buddypress' ).
    251250     * @param string $path The file path for the component's files. Used by {@link BP_Component::includes()}.
    252251     * @param array  $params {
     
    314313     *                                           if one is found, otherwise an empty string.
    315314     *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
    316      *     @type array    $rewrite_ids           The list of rewrited IDs to use for the component.
     315     *     @type array    $rewrite_ids           The list of rewritten IDs to use for the component.
    317316     *     @type string   $directory_title       The title to use for the directory page.
    318317     *     @type callable $notification_callback The callable function that formats the component's notifications.
     
    530529
    531530                foreach ( $paths as $path ) {
     531
    532532                    if ( @is_file( $slashed_path . $path ) ) {
    533533                        require $slashed_path . $path;
     
    623623        // Register BP REST Endpoints.
    624624        if ( bp_rest_in_buddypress() && bp_rest_api_is_available() ) {
    625             add_action( 'bp_rest_api_init', array( $this, 'rest_api_init' ), 10 );
     625            add_action( 'bp_rest_api_init', array( $this, 'rest_api_init' ) );
    626626        }
    627627
     
    14161416             * @since 5.0.0
    14171417             *
    1418              * @param array $controllers The list of BP REST API controllers to load.
     1418             * @param string[] $controllers The list of BP REST API controllers to load.
    14191419             */
    14201420            $controllers = (array) apply_filters( 'bp_' . $this->id . '_rest_api_controllers', $controllers );
     
    14251425                }
    14261426
     1427                if ( ! class_exists( $controller ) ) {
     1428                    _doing_it_wrong(
     1429                        __METHOD__,
     1430                        sprintf(
     1431                            // translators: %s: REST API controller class name.
     1432                            esc_html__( 'The REST API controller class %s does not exist.', 'buddypress' ),
     1433                            esc_attr( $controller )
     1434                        ),
     1435                        '15.0.0'
     1436                    );
     1437                }
     1438
    14271439                $component_controller = new $controller();
    14281440                $component_controller->register_routes();
  • trunk/src/bp-core/classes/class-bp-core.php

    r13979 r14026  
    441441     */
    442442    public function rest_api_init( $controllers = array() ) {
    443         $controllers = array(
    444             'BP_REST_Components_Endpoint',
    445         );
     443        $controllers = array( 'BP_Core_Components_REST_Controller' );
    446444
    447445        parent::rest_api_init( $controllers );
  • trunk/src/bp-core/classes/class-bp-rest-attachments-group-avatar-endpoint.php

    r12607 r14026  
    1 <?php
    2 /**
    3  * BP REST: BP_REST_Attachments_Group_Avatar_Endpoint class
    4  *
    5  * @package BuddyPress
    6  * @deprecated 6.0.0
    7  */
    8 
    9 defined( 'ABSPATH' ) || exit;
    10 
    11 _deprecated_file( basename( __FILE__ ), '6.0.0', 'bp-groups/classes/class-bp-rest-attachments-group-avatar-endpoint.php' );
    12 
    13 /** BP_REST_Attachments_Group_Avatar_Endpoint class */
    14 require_once trailingslashit( constant( 'BP_PLUGIN_DIR' ) . constant( 'BP_SOURCE_SUBDIRECTORY' ) ) . 'bp-groups/classes/class-bp-rest-attachments-group-avatar-endpoint.php';
  • trunk/src/bp-core/classes/class-bp-rest-attachments-member-avatar-endpoint.php

    r12607 r14026  
    1 <?php
    2 /**
    3  * BP REST: BP_REST_Attachments_Member_Avatar_Endpoint class
    4  *
    5  * @package BuddyPress
    6  * @deprecated 6.0.0
    7  */
    8 
    9 defined( 'ABSPATH' ) || exit;
    10 
    11 _deprecated_file( basename( __FILE__ ), '6.0.0', 'bp-members/classes/class-class-bp-rest-attachments-member-avatar-endpoint.php' );
    12 
    13 /** BP_REST_Attachments_Member_Avatar_Endpoint class */
    14 require_once trailingslashit( constant( 'BP_PLUGIN_DIR' ) . constant( 'BP_SOURCE_SUBDIRECTORY' ) ) . 'bp-members/classes/class-bp-rest-attachments-member-avatar-endpoint.php';
  • trunk/src/bp-friends/classes/class-bp-friends-component.php

    r13503 r14026  
    140140                'bp/friends' => array(
    141141                    'widget_classnames' => array( 'widget_bp_core_friends_widget', 'buddypress' ),
    142                 )
     142                ),
    143143            ),
    144144        );
     
    160160     */
    161161    public function register_nav( $main_nav = array(), $sub_nav = array() ) {
    162         $slug   = bp_get_friends_slug();
     162        $slug = bp_get_friends_slug();
    163163
    164164        $main_nav = array(
     
    306306                $bp->bp_options_title = __( 'Friendships', 'buddypress' );
    307307            } else {
    308                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    309                     'item_id' => bp_displayed_user_id(),
    310                     'type'    => 'thumb',
    311                     'alt'     => sprintf(
     308                $bp->bp_options_avatar = bp_core_fetch_avatar(
     309                    array(
     310                        'item_id' => bp_displayed_user_id(),
     311                        'type'    => 'thumb',
     312                        'alt'     => sprintf(
    312313                        /* translators: %s: member name */
    313                         __( 'Profile picture of %s', 'buddypress' ),
    314                         bp_get_displayed_user_fullname()
    315                     ),
    316                 ) );
    317                 $bp->bp_options_title = bp_get_displayed_user_fullname();
     314                            __( 'Profile picture of %s', 'buddypress' ),
     315                            bp_get_displayed_user_fullname()
     316                        ),
     317                    )
     318                );
     319                $bp->bp_options_title  = bp_get_displayed_user_fullname();
    318320            }
    319321        }
     
    330332
    331333        // Global groups.
    332         wp_cache_add_global_groups( array(
    333             'bp_friends_requests',
    334             'bp_friends_friendships', // Individual friendship objects are cached here by ID.
    335             'bp_friends_friendships_for_user' // All friendship IDs for a single user.
    336         ) );
     334        wp_cache_add_global_groups(
     335            array(
     336                'bp_friends_requests',
     337                'bp_friends_friendships', // Individual friendship objects are cached here by ID.
     338                'bp_friends_friendships_for_user', // All friendship IDs for a single user.
     339            )
     340        );
    337341
    338342        parent::setup_cache_groups();
     
    348352     */
    349353    public function rest_api_init( $controllers = array() ) {
    350         parent::rest_api_init( array( 'BP_REST_Friends_Endpoint' ) );
     354        parent::rest_api_init( array( 'BP_Friends_REST_Controller' ) );
    351355    }
    352356
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r13689 r14026  
    338338
    339339        // Check the parsed query is consistent with the Group’s registered screens.
    340         add_action( 'bp_parse_query',  array( $this, 'check_parsed_query' ), 999, 0 );
     340        add_action( 'bp_parse_query', array( $this, 'check_parsed_query' ), 999, 0 );
    341341    }
    342342
     
    448448         * @param array $value Array of valid group statuses.
    449449         */
    450         $this->valid_status = apply_filters( 'groups_valid_status', array(
    451             'public',
    452             'private',
    453             'hidden'
    454         ) );
     450        $this->valid_status = apply_filters(
     451            'groups_valid_status',
     452            array(
     453                'public',
     454                'private',
     455                'hidden',
     456            )
     457        );
    455458
    456459        // Auto join group when non group member performs group activity.
     
    483486            'table_name'           => $bp->table_prefix . 'bp_groups',
    484487            'table_name_members'   => $bp->table_prefix . 'bp_groups_members',
    485             'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta'
     488            'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta',
    486489        );
    487490
     
    493496        // Fetch the default directory title.
    494497        $default_directory_titles = bp_core_get_directory_page_default_titles();
    495         $default_directory_title  = $default_directory_titles[$this->id];
     498        $default_directory_title  = $default_directory_titles[ $this->id ];
    496499
    497500        // All globals for groups component.
     
    610613         * action variables.
    611614         */
    612         if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) )  {
     615        if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) ) {
    613616            unset( $bp->canonical_stack['action'] );
    614617        }
     
    635638            'screen_function'     => 'groups_screen_my_groups',
    636639            'default_subnav_slug' => 'my-groups',
    637             'item_css_id'         => $this->id
     640            'item_css_id'         => $this->id,
    638641        );
    639642
     
    645648            'screen_function' => 'groups_screen_my_groups',
    646649            'position'        => 10,
    647             'item_css_id'     => 'groups-my-groups'
     650            'item_css_id'     => 'groups-my-groups',
    648651        );
    649652
     
    709712                    'screen_function'     => 'groups_screen_group_home',
    710713                    'default_subnav_slug' => $this->default_extension,
    711                     'item_css_id'         => $this->id
     714                    'item_css_id'         => $this->id,
    712715                ),
    713716                'groups'
     
    824827
    825828                /** This action is documented in bp-groups/bp-groups-loader.php */
    826                 do_action( 'groups_setup_nav');
     829                do_action( 'groups_setup_nav' );
    827830            }
    828831        }
     
    852855            if ( bp_is_active( 'groups', 'invitations' ) ) {
    853856                // Pending group invites.
    854                 $count   = groups_get_invite_count_for_user();
     857                $count = groups_get_invite_count_for_user();
    855858                if ( $count ) {
    856859                    $title = sprintf(
     
    907910                        )
    908911                    ),
    909                     'position' => 90
     912                    'position' => 90,
    910913                );
    911914            }
     
    925928            $bp = buddypress();
    926929
    927             if ( bp_is_my_profile() && !bp_is_single_item() ) {
     930            if ( bp_is_my_profile() && ! bp_is_single_item() ) {
    928931                $bp->bp_options_title = _x( 'Memberships', 'My Groups page <title>', 'buddypress' );
    929932
    930             } elseif ( !bp_is_my_profile() && !bp_is_single_item() ) {
    931                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    932                     'item_id' => bp_displayed_user_id(),
    933                     'type'    => 'thumb',
    934                     'alt'     => sprintf(
     933            } elseif ( ! bp_is_my_profile() && ! bp_is_single_item() ) {
     934                $bp->bp_options_avatar = bp_core_fetch_avatar(
     935                    array(
     936                        'item_id' => bp_displayed_user_id(),
     937                        'type'    => 'thumb',
     938                        'alt'     => sprintf(
    935939                        /* translators: %s: member name */
    936                         __( 'Profile picture of %s', 'buddypress' ),
    937                         bp_get_displayed_user_fullname()
    938                     ),
    939                 ) );
    940                 $bp->bp_options_title = bp_get_displayed_user_fullname();
    941 
    942             // We are viewing a single group, so set up the
    943             // group navigation menu using the $this->current_group global.
     940                            __( 'Profile picture of %s', 'buddypress' ),
     941                            bp_get_displayed_user_fullname()
     942                        ),
     943                    )
     944                );
     945                $bp->bp_options_title  = bp_get_displayed_user_fullname();
     946
     947                // We are viewing a single group, so set up the
     948                // group navigation menu using the $this->current_group global.
    944949            } elseif ( bp_is_single_item() ) {
    945950                $bp->bp_options_title  = $this->current_group->name;
    946                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    947                     'item_id'    => $this->current_group->id,
    948                     'object'     => 'group',
    949                     'type'       => 'thumb',
    950                     'avatar_dir' => 'group-avatars',
    951                     'alt'        => __( 'Group Profile Photo', 'buddypress' )
    952                 ) );
     951                $bp->bp_options_avatar = bp_core_fetch_avatar(
     952                    array(
     953                        'item_id'    => $this->current_group->id,
     954                        'object'     => 'group',
     955                        'type'       => 'thumb',
     956                        'avatar_dir' => 'group-avatars',
     957                        'alt'        => __( 'Group Profile Photo', 'buddypress' ),
     958                    )
     959                );
    953960
    954961                if ( empty( $bp->bp_options_avatar ) ) {
     
    10281035
    10291036        $rewrite_rules = array(
    1030             'directory_type'      => array(
     1037            'directory_type'               => array(
    10311038                'regex' => $this->root_slug . '/' . bp_get_groups_group_type_base() . '/([^/]+)/?$',
    10321039                'order' => 50,
    10331040                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['directory_type'] . '=$matches[1]',
    10341041            ),
    1035             'create_single_item' => array(
     1042            'create_single_item'           => array(
    10361043                'regex' => $this->root_slug . '/' . $create_slug . '/?$',
    10371044                'order' => 40,
     
    10401047            'create_single_item_variables' => array(
    10411048                'regex' => $this->root_slug . '/' . $create_slug . '/(.+?)/?$',
    1042                 'order' =>30,
     1049                'order' => 30,
    10431050                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['create_single_item'] . '=1&' . $this->rewrite_ids['create_single_item_variables'] . '=$matches[1]',
    10441051            ),
     
    12391246    public function rest_api_init( $controllers = array() ) {
    12401247        $controllers = array(
    1241             'BP_REST_Groups_Endpoint',
    1242             'BP_REST_Group_Membership_Endpoint',
    1243             'BP_REST_Group_Invites_Endpoint',
    1244             'BP_REST_Group_Membership_Request_Endpoint',
    1245             'BP_REST_Attachments_Group_Avatar_Endpoint',
     1248            'BP_Groups_REST_Controller',
     1249            'BP_Groups_Avatar_REST_Controller',
     1250            'BP_Groups_Membership_REST_Controller',
     1251            'BP_Groups_Membership_Request_REST_Controller',
     1252            'BP_Groups_Invites_REST_Controller',
    12461253        );
    12471254
    12481255        // Support to Group Cover.
    12491256        if ( bp_is_active( 'groups', 'cover_image' ) ) {
    1250             $controllers[] = 'BP_REST_Attachments_Group_Cover_Endpoint';
     1257            $controllers[] = 'BP_Groups_Cover_REST_Controller';
    12511258        }
    12521259
     
    12661273        parent::blocks_init(
    12671274            array(
    1268                 'bp/group' => array(
     1275                'bp/group'          => array(
    12691276                    'metadata'        => trailingslashit( buddypress()->plugin_dir ) . 'bp-groups/blocks/group',
    12701277                    'render_callback' => 'bp_groups_render_group_block',
    12711278                ),
    1272                 'bp/groups' => array(
     1279                'bp/groups'         => array(
    12731280                    'metadata'        => trailingslashit( buddypress()->plugin_dir ) . 'bp-groups/blocks/groups',
    12741281                    'render_callback' => 'bp_groups_render_groups_block',
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r14011 r14026  
    121121         * bp-members/bp-members-template.php.
    122122         */
    123         $signup_allowed = apply_filters( 'bp_get_signup_allowed', (bool) bp_get_option( 'users_can_register' ) );
     123        $signup_allowed              = apply_filters( 'bp_get_signup_allowed', (bool) bp_get_option( 'users_can_register' ) );
    124124        $membership_requests_enabled = (bool) bp_get_option( 'bp-enable-membership-requests' );
    125125        if ( bp_is_active( 'members', 'membership_requests' ) && ! $signup_allowed && $membership_requests_enabled ) {
     
    166166
    167167            // Action - Delete avatar.
    168             if ( is_user_logged_in()&& bp_is_user_change_avatar() && bp_is_action_variable( 'delete-avatar', 0 ) ) {
     168            if ( is_user_logged_in() && bp_is_user_change_avatar() && bp_is_action_variable( 'delete-avatar', 0 ) ) {
    169169                require_once $this->path . 'bp-members/actions/delete-avatar.php';
    170170            }
     
    216216
    217217        // Check the parsed query is consistent with the Members navigation.
    218         add_action( 'bp_parse_query',  array( $this, 'check_parsed_query' ), 999, 0 );
     218        add_action( 'bp_parse_query', array( $this, 'check_parsed_query' ), 999, 0 );
    219219    }
    220220
     
    281281         */
    282282
    283         $bp->signup = new stdClass;
     283        $bp->signup = new stdClass();
    284284
    285285        /** Profiles Fallback ************************************************
     
    287287
    288288        if ( ! bp_is_active( 'xprofile' ) ) {
    289             $bp->profile       = new stdClass;
     289            $bp->profile       = new stdClass();
    290290            $bp->profile->slug = 'profile';
    291291            $bp->profile->id   = 'profile';
     
    295295         */
    296296
    297         $bp->members->invitations = new stdClass;
     297        $bp->members->invitations = new stdClass();
    298298    }
    299299
     
    328328        // Fetch the default directory title.
    329329        $default_directory_titles = bp_core_get_directory_page_default_titles();
    330         $default_directory_title  = $default_directory_titles[$this->id];
     330        $default_directory_title  = $default_directory_titles[ $this->id ];
    331331
    332332        // Override any passed args.
    333333        $args = array(
    334             'slug'            => $default_slug,
    335             'root_slug'       => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : $default_slug,
    336             'has_directory'   => true,
    337             'rewrite_ids'     => array(
     334            'slug'                  => $default_slug,
     335            'root_slug'             => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : $default_slug,
     336            'has_directory'         => true,
     337            'rewrite_ids'           => array(
    338338                'directory'                    => 'members',
    339339                'directory_type'               => 'members_type',
     
    346346                'member_activate_key'          => 'activate_key',
    347347            ),
    348             'directory_title' => isset( $bp->pages->members->title ) ? $bp->pages->members->title : $default_directory_title,
    349             'search_string'   => __( 'Search Members...', 'buddypress' ),
    350             'global_tables'   => array(
     348            'directory_title'       => isset( $bp->pages->members->title ) ? $bp->pages->members->title : $default_directory_title,
     349            'search_string'         => __( 'Search Members...', 'buddypress' ),
     350            'global_tables'         => array(
    351351                'table_name_invitations'   => bp_core_get_table_prefix() . 'bp_invitations',
    352352                'table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity',
     
    359359                    'widget_classnames' => array( 'widget_bp_core_members_widget', 'buddypress' ),
    360360                ),
    361                 'bp/online-members' => array(
     361                'bp/online-members'  => array(
    362362                    'widget_classnames' => array( 'widget_bp_core_whos_online_widget', 'buddypress' ),
    363363                ),
    364                 'bp/active-members' => array(
     364                'bp/active-members'  => array(
    365365                    'widget_classnames' => array( 'widget_bp_core_recently_active_widget', 'buddypress' ),
    366366                ),
     
    616616                $wp_admin_nav = array_merge( $wp_admin_nav, $this->get_avatar_cover_image_admin_navs() );
    617617
    618             /**
    619             * The xProfile is active.
    620             *
    621             * Add the Change Avatar and Change Cover Image Admin Bar items
    622             * to the xProfile Admin Bar Menu.
    623             */
     618                /**
     619                * The xProfile is active.
     620                *
     621                * Add the Change Avatar and Change Cover Image Admin Bar items
     622                * to the xProfile Admin Bar Menu.
     623                */
    624624            } else {
    625625                add_filter( 'bp_xprofile_admin_nav', array( $this, 'setup_xprofile_admin_nav' ), 2 );
     
    661661        } elseif ( bp_is_user() ) {
    662662            $bp->bp_options_title  = bp_get_displayed_user_fullname();
    663             $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    664                 'item_id' => bp_displayed_user_id(),
    665                 'type'    => 'thumb',
    666                 /* translators: %s: member name */
    667                 'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), $bp->bp_options_title )
    668             ) );
     663            $bp->bp_options_avatar = bp_core_fetch_avatar(
     664                array(
     665                    'item_id' => bp_displayed_user_id(),
     666                    'type'    => 'thumb',
     667                    /* translators: %s: member name */
     668                    'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), $bp->bp_options_title ),
     669                )
     670            );
    669671        }
    670672
     
    10621064    public function rest_api_init( $controllers = array() ) {
    10631065        $controllers = array(
    1064             'BP_REST_Members_Endpoint',
    1065             'BP_REST_Attachments_Member_Avatar_Endpoint',
     1066            'BP_Members_REST_Controller',
     1067            'BP_Members_Avatar_REST_Controller',
    10661068        );
    10671069
    10681070        if ( bp_is_active( 'members', 'cover_image' ) ) {
    1069             $controllers[] = 'BP_REST_Attachments_Member_Cover_Endpoint';
     1071            $controllers[] = 'BP_Members_Cover_REST_Controller';
    10701072        }
    10711073
    10721074        if ( bp_get_signup_allowed() ) {
    1073             $controllers[] = 'BP_REST_Signup_Endpoint';
     1075            $controllers[] = 'BP_Members_Signup_REST_Controller';
    10741076        }
    10751077
     
    10891091        parent::blocks_init(
    10901092            array(
    1091                 'bp/member' => array(
     1093                'bp/member'          => array(
    10921094                    'metadata'        => trailingslashit( buddypress()->plugin_dir ) . 'bp-members/blocks/member',
    10931095                    'render_callback' => 'bp_members_render_member_block',
    10941096                ),
    1095                 'bp/members' => array(
     1097                'bp/members'         => array(
    10961098                    'metadata'        => trailingslashit( buddypress()->plugin_dir ) . 'bp-members/blocks/members',
    10971099                    'render_callback' => 'bp_members_render_members_block',
  • trunk/src/bp-messages/classes/class-bp-messages-component.php

    r13551 r14026  
    4242            array(
    4343                'adminbar_myaccount_order' => 50,
    44                 'features'                 => array( 'star' )
     44                'features'                 => array( 'star' ),
    4545            )
    4646        );
     
    178178        // All globals for messaging component.
    179179        // Note that global_tables is included in this array.
    180         parent::setup_globals( array(
    181             'slug'                  => $default_slug,
    182             'has_directory'         => false,
    183             'notification_callback' => 'messages_format_notifications',
    184             'search_string'         => __( 'Search Messages...', 'buddypress' ),
    185             'global_tables'         => $global_tables,
    186             'meta_tables'           => $meta_tables
    187         ) );
     180        parent::setup_globals(
     181            array(
     182                'slug'                  => $default_slug,
     183                'has_directory'         => false,
     184                'notification_callback' => 'messages_format_notifications',
     185                'search_string'         => __( 'Search Messages...', 'buddypress' ),
     186                'global_tables'         => $global_tables,
     187                'meta_tables'           => $meta_tables,
     188            )
     189        );
    188190    }
    189191
     
    224226        if ( bp_is_active( $this->id, 'star' ) ) {
    225227            $sub_nav[] = array(
    226                 'name'                      => __( 'Starred', 'buddypress' ),
     228                'name'                     => __( 'Starred', 'buddypress' ),
    227229                'slug'                     => bp_get_messages_starred_slug(),
    228230                'parent_slug'              => $slug,
     
    325327            // Unread message count.
    326328            $count = messages_get_unread_count( bp_loggedin_user_id() );
    327             if ( !empty( $count ) ) {
     329            if ( ! empty( $count ) ) {
    328330                $title = sprintf(
    329331                    /* translators: %s: Unread message count for the current user */
     
    338340            } else {
    339341                $title = __( 'Messages', 'buddypress' );
    340                 $inbox = __( 'Inbox',    'buddypress' );
     342                $inbox = __( 'Inbox', 'buddypress' );
    341343            }
    342344
     
    413415                $bp->bp_options_title = __( 'My Messages', 'buddypress' );
    414416            } else {
    415                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    416                     'item_id' => bp_displayed_user_id(),
    417                     'type'    => 'thumb',
    418                     /* translators: %s: member name */
    419                     'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
    420                 ) );
    421                 $bp->bp_options_title = bp_get_displayed_user_fullname();
     417                $bp->bp_options_avatar = bp_core_fetch_avatar(
     418                    array(
     419                        'item_id' => bp_displayed_user_id(),
     420                        'type'    => 'thumb',
     421                        /* translators: %s: member name */
     422                        'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ),
     423                    )
     424                );
     425                $bp->bp_options_title  = bp_get_displayed_user_fullname();
    422426            }
    423427        }
     
    434438
    435439        // Global groups.
    436         wp_cache_add_global_groups( array(
    437             'bp_messages',
    438             'bp_messages_threads',
    439             'bp_messages_unread_count',
    440             'message_meta'
    441         ) );
     440        wp_cache_add_global_groups(
     441            array(
     442                'bp_messages',
     443                'bp_messages_threads',
     444                'bp_messages_unread_count',
     445                'message_meta',
     446            )
     447        );
    442448
    443449        parent::setup_cache_groups();
     
    455461        parent::rest_api_init(
    456462            array(
    457                 'BP_REST_Messages_Endpoint',
    458                 'BP_REST_Sitewide_Notices_Endpoint',
     463                'BP_Messages_REST_Controller',
     464                'BP_Messages_Sitewide_Notices_REST_Controller',
    459465            )
    460466        );
  • trunk/src/bp-notifications/classes/class-bp-notifications-component.php

    r13503 r14026  
    146146     */
    147147    public function register_nav( $main_nav = array(), $sub_nav = array() ) {
    148         $slug   = bp_get_notifications_slug();
     148        $slug = bp_get_notifications_slug();
    149149
    150150        // Add 'Notifications' to the main navigation.
     
    248248                );
    249249            } else {
    250                 $title  = _x( 'Notifications', 'My Account Notification',         'buddypress' );
    251                 $unread = _x( 'Unread',        'My Account Notification sub nav', 'buddypress' );
     250                $title  = _x( 'Notifications', 'My Account Notification', 'buddypress' );
     251                $unread = _x( 'Unread', 'My Account Notification sub nav', 'buddypress' );
    252252            }
    253253
     
    297297            } else {
    298298                $bp->bp_options_title  = bp_get_displayed_user_fullname();
    299                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    300                     'item_id' => bp_displayed_user_id(),
    301                     'type'    => 'thumb',
    302                     /* translators: %s: member name */
    303                     'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
    304                 ) );
     299                $bp->bp_options_avatar = bp_core_fetch_avatar(
     300                    array(
     301                        'item_id' => bp_displayed_user_id(),
     302                        'type'    => 'thumb',
     303                        /* translators: %s: member name */
     304                        'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ),
     305                    )
     306                );
    305307            }
    306308        }
     
    317319
    318320        // Global groups.
    319         wp_cache_add_global_groups( array(
    320             'bp_notifications',
    321             'notification_meta',
    322             'bp_notifications_unread_count',
    323             'bp_notifications_grouped_notifications',
    324         ) );
     321        wp_cache_add_global_groups(
     322            array(
     323                'bp_notifications',
     324                'notification_meta',
     325                'bp_notifications_unread_count',
     326                'bp_notifications_grouped_notifications',
     327            )
     328        );
    325329
    326330        parent::setup_cache_groups();
     
    336340     */
    337341    public function rest_api_init( $controllers = array() ) {
    338         parent::rest_api_init( array( 'BP_REST_Notifications_Endpoint' ) );
     342        parent::rest_api_init( array( 'BP_Notifications_REST_Controller' ) );
    339343    }
    340344}
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-component.php

    r13503 r14026  
    174174        // Register the visibility levels. See bp_xprofile_get_visibility_levels() to filter.
    175175        $this->visibility_levels = array(
    176             'public' => array(
    177                 'id'      => 'public',
     176            'public'     => array(
     177                'id'    => 'public',
    178178                'label' => _x( 'Everyone', 'Visibility level setting', 'buddypress' ),
    179179            ),
    180180            'adminsonly' => array(
    181                 'id'      => 'adminsonly',
     181                'id'    => 'adminsonly',
    182182                'label' => _x( 'Only Me', 'Visibility level setting', 'buddypress' ),
    183183            ),
    184             'loggedin' => array(
    185                 'id'      => 'loggedin',
     184            'loggedin'   => array(
     185                'id'    => 'loggedin',
    186186                'label' => _x( 'All Members', 'Visibility level setting', 'buddypress' ),
    187187            ),
     
    190190        if ( bp_is_active( 'friends' ) ) {
    191191            $this->visibility_levels['friends'] = array(
    192                 'id'    => 'friends',
    193                 'label' => _x( 'My Friends', 'Visibility level setting', 'buddypress' ),
     192                'id'    => 'friends',
     193                'label' => _x( 'My Friends', 'Visibility level setting', 'buddypress' ),
    194194            );
    195195        }
     
    252252        // Edit Profile.
    253253        $sub_nav[] = array(
    254             'name'                     => _x( 'Edit','Profile header sub menu', 'buddypress' ),
     254            'name'                     => _x( 'Edit', 'Profile header sub menu', 'buddypress' ),
    255255            'slug'                     => 'edit',
    256256            'parent_slug'              => $slug,
     
    342342                $bp->bp_options_title = _x( 'My Profile', 'Page title', 'buddypress' );
    343343            } else {
    344                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    345                     'item_id' => bp_displayed_user_id(),
    346                     'type'    => 'thumb',
    347 
    348                     /* translators: %s: member name */
    349                     'alt'     => sprintf( _x( 'Profile picture of %s', 'Avatar alt', 'buddypress' ), bp_get_displayed_user_fullname() ),
    350                 ) );
    351                 $bp->bp_options_title = bp_get_displayed_user_fullname();
     344                $bp->bp_options_avatar = bp_core_fetch_avatar(
     345                    array(
     346                        'item_id' => bp_displayed_user_id(),
     347                        'type'    => 'thumb',
     348
     349                        /* translators: %s: member name */
     350                        'alt'     => sprintf( _x( 'Profile picture of %s', 'Avatar alt', 'buddypress' ), bp_get_displayed_user_fullname() ),
     351                    )
     352                );
     353                $bp->bp_options_title  = bp_get_displayed_user_fullname();
    352354            }
    353355        }
     
    364366
    365367        // Global groups.
    366         wp_cache_add_global_groups( array(
    367             'bp_xprofile',
    368             'bp_xprofile_data',
    369             'bp_xprofile_fields',
    370             'bp_xprofile_groups',
    371             'xprofile_meta',
    372             'bp_user_mid',
    373         ) );
     368        wp_cache_add_global_groups(
     369            array(
     370                'bp_xprofile',
     371                'bp_xprofile_data',
     372                'bp_xprofile_fields',
     373                'bp_xprofile_groups',
     374                'xprofile_meta',
     375                'bp_user_mid',
     376            )
     377        );
    374378
    375379        parent::setup_cache_groups();
     
    405409     */
    406410    public function rest_api_init( $controllers = array() ) {
    407         parent::rest_api_init( array(
    408             'BP_REST_XProfile_Fields_Endpoint',
    409             'BP_REST_XProfile_Field_Groups_Endpoint',
    410             'BP_REST_XProfile_Data_Endpoint',
    411         ) );
     411        parent::rest_api_init(
     412            array(
     413                'BP_XProfile_Fields_REST_Controller',
     414                'BP_XProfile_Field_Groups_REST_Controller',
     415                'BP_XProfile_Data_REST_Controller',
     416            )
     417        );
    412418    }
    413419
  • trunk/src/class-buddypress.php

    r13953 r14026  
    657657                require $this->plugin_dir . sprintf( 'bp-core/deprecated/%s.php', number_format( $deprecated_functions_version, 1 ) );
    658658            }
    659         }
     659        }
    660660
    661661        // Load wp-cli module if PHP 5.6+.
     
    674674     * @since 2.5.0
    675675     *
    676      * @param string $class Classes to be autoloaded.
    677      * @return string Path of a class.
    678      */
    679     public function autoload( $class ) {
    680         $class_parts = explode( '_', strtolower( $class ) );
     676     * @param string $class_name Classes to be autoloaded.
     677     */
     678    public function autoload( $class_name ) {
     679        $class_parts = explode( '_', strtolower( $class_name ) );
    681680
    682681        if ( 'bp' !== $class_parts[0] ) {
     
    699698        // These classes don't have a name that matches their component.
    700699        $irregular_map = array(
    701             'BP_Akismet'                                 => 'activity',
    702             'BP_REST_Activity_Endpoint'                  => 'activity',
    703 
    704             'BP_REST_Blogs_Endpoint'                     => 'blogs',
    705             'BP_REST_Attachments_Blog_Avatar_Endpoint'   => 'blogs',
    706 
    707             'BP_Admin'                                   => 'core',
    708             'BP_Attachment_Avatar'                       => 'core',
    709             'BP_Attachment_Cover_Image'                  => 'core',
    710             'BP_Attachment'                              => 'core',
    711             'BP_Button'                                  => 'core',
    712             'BP_Block'                                   => 'core',
    713             'BP_Component'                               => 'core',
    714             'BP_Customizer_Control_Range'                => 'core',
    715             'BP_Date_Query'                              => 'core',
    716             'BP_Email_Delivery'                          => 'core',
    717             'BP_Email_Address'                           => 'core',
    718             'BP_Email_Recipient'                         => 'core',
    719             'BP_Email_Sender'                            => 'core',
    720             'BP_Email_Participant'                       => 'core',
    721             'BP_Email'                                   => 'core',
    722             'BP_Embed'                                   => 'core',
    723             'BP_Media_Extractor'                         => 'core',
    724             'BP_Members_Suggestions'                     => 'core',
    725             'BP_PHPMailer'                               => 'core',
    726             'BP_Recursive_Query'                         => 'core',
    727             'BP_Suggestions'                             => 'core',
    728             'BP_Theme_Compat'                            => 'core',
    729             'BP_User_Query'                              => 'core',
    730             'BP_Walker_Category_Checklist'               => 'core',
    731             'BP_Walker_Nav_Menu'                         => 'core',
    732             'BP_Invitation_Manager'                      => 'core',
    733             'BP_Invitation'                              => 'core',
    734             'BP_REST_Components_Endpoint'                => 'core',
    735             'BP_REST_Attachments'                        => 'core',
    736             'BP_Admin_Types'                             => 'core',
    737             'BP_Optout'                                  => 'core',
    738             'BP_Optouts_List_Table'                      => 'core',
    739 
    740             'BP_REST_Friends_Endpoint'                   => 'friends',
    741 
    742             'BP_Group_Extension'                         => 'groups',
    743             'BP_Group_Member_Query'                      => 'groups',
    744             'BP_REST_Groups_Endpoint'                    => 'groups',
    745             'BP_REST_Group_Membership_Endpoint'          => 'groups',
    746             'BP_REST_Group_Invites_Endpoint'             => 'groups',
    747             'BP_REST_Group_Membership_Request_Endpoint'  => 'groups',
    748             'BP_REST_Attachments_Group_Avatar_Endpoint'  => 'groups',
    749             'BP_REST_Attachments_Group_Cover_Endpoint'   => 'groups',
    750 
    751             'BP_Core_Members_Template'                   => 'members',
    752             'BP_Registration_Theme_Compat'               => 'members',
    753             'BP_Signup'                                  => 'members',
    754             'BP_REST_Members_Endpoint'                   => 'members',
    755             'BP_REST_Attachments_Member_Avatar_Endpoint' => 'members',
    756             'BP_REST_Attachments_Member_Cover_Endpoint'  => 'members',
    757             'BP_REST_Signup_Endpoint'                    => 'members',
    758             'BP_Members_Invitation_Manager'              => 'members',
    759             'BP_Members_Invitations_Template'            => 'members',
    760             'BP_Members_Invitations_Component'           => 'members',
    761 
    762             'BP_REST_Messages_Endpoint'                  => 'messages',
    763             'BP_REST_Sitewide_Notices_Endpoint'          => 'messages',
    764 
    765             'BP_REST_Notifications_Endpoint'             => 'notifications',
    766 
    767             'BP_REST_XProfile_Fields_Endpoint'           => 'xprofile',
    768             'BP_REST_XProfile_Field_Groups_Endpoint'     => 'xprofile',
    769             'BP_REST_XProfile_Data_Endpoint'             => 'xprofile',
     700            'BP_Akismet'                       => 'activity',
     701            'BP_Admin'                         => 'core',
     702            'BP_Attachment_Avatar'             => 'core',
     703            'BP_Attachment_Cover_Image'        => 'core',
     704            'BP_Attachment'                    => 'core',
     705            'BP_Button'                        => 'core',
     706            'BP_Block'                         => 'core',
     707            'BP_Component'                     => 'core',
     708            'BP_Customizer_Control_Range'      => 'core',
     709            'BP_Date_Query'                    => 'core',
     710            'BP_Email_Delivery'                => 'core',
     711            'BP_Email_Address'                 => 'core',
     712            'BP_Email_Recipient'               => 'core',
     713            'BP_Email_Sender'                  => 'core',
     714            'BP_Email_Participant'             => 'core',
     715            'BP_Email'                         => 'core',
     716            'BP_Embed'                         => 'core',
     717            'BP_Media_Extractor'               => 'core',
     718            'BP_Members_Suggestions'           => 'core',
     719            'BP_PHPMailer'                     => 'core',
     720            'BP_Recursive_Query'               => 'core',
     721            'BP_Suggestions'                   => 'core',
     722            'BP_Theme_Compat'                  => 'core',
     723            'BP_User_Query'                    => 'core',
     724            'BP_Walker_Category_Checklist'     => 'core',
     725            'BP_Walker_Nav_Menu'               => 'core',
     726            'BP_Invitation_Manager'            => 'core',
     727            'BP_Invitation'                    => 'core',
     728            'BP_REST_Attachments'              => 'core',
     729            'BP_Admin_Types'                   => 'core',
     730            'BP_Optout'                        => 'core',
     731            'BP_Optouts_List_Table'            => 'core',
     732            'BP_Group_Extension'               => 'groups',
     733            'BP_Group_Member_Query'            => 'groups',
     734            'BP_Core_Members_Template'         => 'members',
     735            'BP_Registration_Theme_Compat'     => 'members',
     736            'BP_Signup'                        => 'members',
     737            'BP_Members_Invitation_Manager'    => 'members',
     738            'BP_Members_Invitations_Template'  => 'members',
     739            'BP_Members_Invitations_Component' => 'members',
    770740        );
    771741
     
    773743
    774744        // First check to see if the class is one without a properly namespaced name.
    775         if ( isset( $irregular_map[ $class ] ) ) {
    776             $component = $irregular_map[ $class ];
    777 
    778         // Next chunk is usually the component name.
     745        if ( isset( $irregular_map[ $class_name ] ) ) {
     746            $component = $irregular_map[ $class_name ];
     747
     748            // Next chunk is usually the component name.
    779749        } elseif ( in_array( $class_parts[1], $components, true ) ) {
    780750            $component = $class_parts[1];
     
    786756
    787757        // Sanitize class name.
    788         $class = strtolower( str_replace( '_', '-', $class ) );
     758        $class = strtolower( str_replace( '_', '-', $class_name ) );
    789759
    790760        if ( 'bp-rest-attachments' === $class ) {
    791             $path = dirname( __FILE__ ) . "/bp-{$component}/classes/trait-attachments.php";
     761            $path = __DIR__ . "/bp-{$component}/classes/trait-attachments.php";
    792762        } else {
    793             $path = dirname( __FILE__ ) . "/bp-{$component}/classes/class-{$class}.php";
     763            $path = __DIR__ . "/bp-{$component}/classes/class-{$class}.php";
    794764        }
    795765
     
    878848            $this->db_version_raw = (int) $versions['1.6-single'];
    879849
    880         // If no 1.6-single exists, use the max of the others.
     850            // If no 1.6-single exists, use the max of the others.
    881851        } else {
    882852            $versions['1.2']        = get_site_option( 'bp-core-db-version' );
  • trunk/tests/phpunit/assets/bp-rest-api-controllers.php

    r13414 r14026  
    1 <?php
    2 /**
    3  * BP REST Controllers' mocks
    4  */
    5 
    6 class BP_REST_Mock_Class {
    7     public function __construct() {}
    8 
    9     public function register_routes( $controller = '' ) {
    10         array_push( buddypress()->unit_test_rest->controllers, $controller );
    11     }
    12 }
    13 
    14 /**
    15  * BP Member Cover Image REST Controller's mock.
    16  */
    17 #[AllowDynamicProperties]
    18 class BP_REST_Attachments_Member_Cover_Endpoint extends BP_REST_Mock_Class {
    19     public function __construct() {
    20         $this->namespace = bp_rest_namespace() . '/' . bp_rest_version();
    21         $this->rest_base = 'members';
    22     }
    23 
    24     public function register_routes( $controller = '' ) {
    25         parent::register_routes( 'BP_REST_Attachments_Member_Cover_Endpoint' );
    26     }
    27 }
    28 
    29 /**
    30  * BP Member Avatar REST Controller's mock.
    31  */
    32 #[AllowDynamicProperties]
    33 class BP_REST_Attachments_Member_Avatar_Endpoint extends BP_REST_Mock_Class {
    34     public function __construct() {
    35         $this->namespace = bp_rest_namespace() . '/' . bp_rest_version();
    36         $this->rest_base = 'members';
    37     }
    38 
    39     public function register_routes( $controller = '' ) {
    40         parent::register_routes( 'BP_REST_Attachments_Member_Avatar_Endpoint' );
    41     }
    42 }
    43 
    44 /**
    45  * BP Components REST Controller's mock.
    46  */
    47 #[AllowDynamicProperties]
    48 class BP_REST_Components_Endpoint extends BP_REST_Mock_Class {
    49     public function __construct() {
    50         $this->namespace = bp_rest_namespace() . '/' . bp_rest_version();
    51         $this->rest_base = 'components';
    52     }
    53 
    54     public function register_routes( $controller = '' ) {
    55         parent::register_routes( 'BP_REST_Components_Endpoint' );
    56     }
    57 }
    58 
    59 /**
    60  * BP Members REST Controller's mock.
    61  */
    62 #[AllowDynamicProperties]
    63 class BP_REST_Members_Endpoint extends BP_REST_Mock_Class {
    64     public function __construct() {
    65         $this->namespace = bp_rest_namespace() . '/' . bp_rest_version();
    66         $this->rest_base = 'members';
    67     }
    68 
    69     public function register_routes( $controller = '' ) {
    70         parent::register_routes( 'BP_REST_Members_Endpoint' );
    71     }
    72 }
  • trunk/tests/phpunit/bootstrap.php

    r13720 r14026  
    22const WP_TESTS_PHPUNIT_POLYFILLS_PATH = __DIR__ . '/../../vendor/yoast/phpunit-polyfills';
    33
    4 require( dirname( __FILE__ ) . '/includes/define-constants.php' );
     4require __DIR__ . '/includes/define-constants.php';
    55
    66if ( ! file_exists( WP_TESTS_DIR . '/includes/functions.php' ) ) {
     
    1717require WP_TESTS_DIR . '/includes/bootstrap.php';
    1818
    19 // Load the BP-specific testing tools
     19// Load the BP-specific testing tools.
    2020require BP_TESTS_DIR . '/includes/testcase.php';
    2121require BP_TESTS_DIR . '/includes/testcase-emails.php';
     22require BP_TESTS_DIR . '/includes/testcase-rest-controller.php';
     23
     24/**
     25 * Set component visibility.
     26 *
     27 * @param bool $visibility Visibility.
     28 */
     29function toggle_component_visibility( $visibility = true ) {
     30    $visibility = $visibility ? 'members' : 'anyone';
     31
     32    update_option(
     33        '_bp_community_visibility',
     34        array(
     35            'global'   => $visibility,
     36            'activity' => $visibility,
     37            'members'  => $visibility,
     38            'groups'   => $visibility,
     39            'blogs'    => $visibility,
     40        )
     41    );
     42}
  • trunk/tests/phpunit/testcases/activity/template.php

    r13980 r14026  
    99     */
    1010    public function test_user_can_delete() {
    11         $bp = buddypress();
    12         $u = self::factory()->user->create();
     11        $bp            = buddypress();
     12        $u             = self::factory()->user->create();
    1313        $original_user = bp_loggedin_user_id();
    1414        self::set_current_user( $u );
    1515
    16         $a = self::factory()->activity->create( array(
    17             'type' => 'activity_update',
    18             'user_id' => $u,
    19         ) );
     16        $a = self::factory()->activity->create(
     17            array(
     18                'type'    => 'activity_update',
     19                'user_id' => $u,
     20            )
     21        );
    2022
    2123        // User can delete his own items
     
    2830
    2931        // Miscellaneous user can't delete
    30         $misc_user = self::factory()->user->create( array( 'role' => 'subscriber' ) );
     32        $misc_user = self::factory()->user->create();
    3133        self::set_current_user( $misc_user );
    3234        $this->assertFalse( bp_activity_user_can_delete( $activity ) );
    3335
    3436        // Item admin can delete
    35         $is_single_item = $bp->is_single_item;
     37        $is_single_item     = $bp->is_single_item;
    3638        $bp->is_single_item = true;
    3739
    38         $is_item_admin = $bp->is_item_admin;
     40        $is_item_admin     = $bp->is_item_admin;
    3941        $bp->is_item_admin = true;
    4042
     
    4244
    4345        $bp->is_single_item = $is_single_item;
    44         $bp->is_item_admin = $is_item_admin;
     46        $bp->is_item_admin  = $is_item_admin;
    4547        self::set_current_user( $original_user );
    4648    }
     
    5254        // save the current user and override logged-in user
    5355        $old_user = get_current_user_id();
    54         $u = self::factory()->user->create();
     56        $u        = self::factory()->user->create();
    5557        self::set_current_user( $u );
    5658
    5759        // create an activity update for the user
    58         self::factory()->activity->create( array(
    59             'component' => buddypress()->activity->id,
    60             'type' => 'activity_update',
    61             'user_id' => $u,
    62         ) );
     60        self::factory()->activity->create(
     61            array(
     62                'component' => buddypress()->activity->id,
     63                'type'      => 'activity_update',
     64                'user_id'   => $u,
     65            )
     66        );
    6367
    6468        // start the activity loop
    6569        bp_has_activities( array( 'user_id' => $u ) );
    66         while ( bp_activities() ) : bp_the_activity();
     70        while ( bp_activities() ) :
     71            bp_the_activity();
    6772            // assert!
    6873            $this->assertTrue( bp_activity_user_can_delete() );
     
    8186     */
    8287    public function test_bp_has_activities_favorites_action_filter() {
    83         $user_id = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    84 
    85         $now = time();
    86 
    87         $a1 = self::factory()->activity->create( array(
    88             'type' => 'activity_update',
    89             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    90         ) );
    91 
    92         $a2 = self::factory()->activity->create( array(
    93             'type' => 'joined_group',
    94             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    95         ) );
     88        $user_id = self::factory()->user->create();
     89
     90        $now = time();
     91
     92        $a1 = self::factory()->activity->create(
     93            array(
     94                'type'          => 'activity_update',
     95                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     96            )
     97        );
     98
     99        $a2 = self::factory()->activity->create(
     100            array(
     101                'type'          => 'joined_group',
     102                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     103            )
     104        );
    96105
    97106        $current_user = bp_loggedin_user_id();
     
    107116
    108117        // Case 1: no action filter
    109         bp_has_activities( array(
    110             'user_id' => $user_id,
    111             'scope' => 'favorites',
    112         ) );
     118        bp_has_activities(
     119            array(
     120                'user_id' => $user_id,
     121                'scope'   => 'favorites',
     122            )
     123        );
    113124
    114125        // The formatting of $activities_template->activities is messed
     
    122133
    123134        // Case 2: action filter
    124         bp_has_activities( array(
    125             'user_id' => $user_id,
    126             'scope' => 'favorites',
    127             'action' => 'activity_update',
    128         ) );
     135        bp_has_activities(
     136            array(
     137                'user_id' => $user_id,
     138                'scope'   => 'favorites',
     139                'action'  => 'activity_update',
     140            )
     141        );
    129142
    130143        $ids = wp_list_pluck( $activities_template->activities, 'id' );
     
    151164
    152165        // activity item
    153         $a1 = self::factory()->activity->create( array(
    154             'user_id'   => $u1,
    155             'component' => 'activity',
    156             'type'      => 'activity_update',
    157             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    158         ) );
     166        $a1 = self::factory()->activity->create(
     167            array(
     168                'user_id'       => $u1,
     169                'component'     => 'activity',
     170                'type'          => 'activity_update',
     171                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     172            )
     173        );
    159174
    160175        // misc activity items
    161176
    162         self::factory()->activity->create( array(
    163             'user_id'   => $u2,
    164             'component' => 'activity',
    165             'type'      => 'activity_update',
    166             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    167         ) );
    168         self::factory()->activity->create( array(
    169             'user_id'   => $u2,
    170             'component' => 'groups',
    171             'item_id'   => 324,
    172             'type'      => 'activity_update',
    173             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    174         ) );
     177        self::factory()->activity->create(
     178            array(
     179                'user_id'       => $u2,
     180                'component'     => 'activity',
     181                'type'          => 'activity_update',
     182                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     183            )
     184        );
     185        self::factory()->activity->create(
     186            array(
     187                'user_id'       => $u2,
     188                'component'     => 'groups',
     189                'item_id'       => 324,
     190                'type'          => 'activity_update',
     191                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     192            )
     193        );
    175194
    176195        global $activities_template;
     
    178197        // grab just-me scope with no user ID
    179198        // user ID should fallback to logged-in user ID
    180         bp_has_activities( array(
    181             'user_id' => false,
    182             'scope' => 'just-me',
    183         ) );
     199        bp_has_activities(
     200            array(
     201                'user_id' => false,
     202                'scope'   => 'just-me',
     203            )
     204        );
    184205
    185206        // assert!
     
    204225        // mentioned activity item
    205226        $mention_username = '@' . bp_activity_get_user_mentionname( $u1 );
    206         $a1 = self::factory()->activity->create( array(
    207             'user_id' => $u2,
    208             'type'    => 'activity_update',
    209             'content' => "{$mention_username} - You rule, dude!",
    210             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    211         ) );
     227        $a1               = self::factory()->activity->create(
     228            array(
     229                'user_id'       => $u2,
     230                'type'          => 'activity_update',
     231                'content'       => "{$mention_username} - You rule, dude!",
     232                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     233            )
     234        );
    212235
    213236        // misc activity items
    214         self::factory()->activity->create( array(
    215             'user_id'   => $u1,
    216             'component' => 'blogs',
    217             'item_id'   => 1,
    218             'type'      => 'new_blog_post',
    219             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    220         ) );
    221         self::factory()->activity->create( array(
    222             'user_id'   => $u2,
    223             'component' => 'activity',
    224             'type'      => 'activity_update',
    225             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    226         ) );
    227         self::factory()->activity->create( array(
    228             'user_id'   => $u2,
    229             'component' => 'groups',
    230             'item_id'   => 324,
    231             'type'      => 'activity_update',
    232             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    233         ) );
     237        self::factory()->activity->create(
     238            array(
     239                'user_id'       => $u1,
     240                'component'     => 'blogs',
     241                'item_id'       => 1,
     242                'type'          => 'new_blog_post',
     243                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     244            )
     245        );
     246        self::factory()->activity->create(
     247            array(
     248                'user_id'       => $u2,
     249                'component'     => 'activity',
     250                'type'          => 'activity_update',
     251                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     252            )
     253        );
     254        self::factory()->activity->create(
     255            array(
     256                'user_id'       => $u2,
     257                'component'     => 'groups',
     258                'item_id'       => 324,
     259                'type'          => 'activity_update',
     260                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     261            )
     262        );
    234263
    235264        global $activities_template;
    236265
    237266        // grab activities from multiple scopes
    238         bp_has_activities( array(
    239             'user_id' => $u1,
    240             'scope' => 'mentions',
    241         ) );
     267        bp_has_activities(
     268            array(
     269                'user_id' => $u1,
     270                'scope'   => 'mentions',
     271            )
     272        );
    242273
    243274        // assert!
     
    264295
    265296        // friend status update
    266         $a1 = self::factory()->activity->create( array(
    267             'user_id' => $u2,
    268             'type' => 'activity_update',
    269             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    270         ) );
     297        $a1 = self::factory()->activity->create(
     298            array(
     299                'user_id'       => $u2,
     300                'type'          => 'activity_update',
     301                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     302            )
     303        );
    271304
    272305        // mentioned item by non-friend
    273306        $mention_username = '@' . bp_activity_get_user_mentionname( $u1 );
    274         $a2 = self::factory()->activity->create( array(
    275             'user_id'   => $u3,
    276             'component' => 'activity',
    277             'type'      => 'activity_update',
    278             'content'   => "{$mention_username} - Oy!",
    279             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    280         ) );
     307        $a2               = self::factory()->activity->create(
     308            array(
     309                'user_id'       => $u3,
     310                'component'     => 'activity',
     311                'type'          => 'activity_update',
     312                'content'       => "{$mention_username} - Oy!",
     313                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     314            )
     315        );
    281316
    282317        // misc activity items
    283         self::factory()->activity->create( array(
    284             'user_id'   => $u1,
    285             'component' => 'blogs',
    286             'item_id'   => 1,
    287             'type'      => 'new_blog_post',
    288             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    289         ) );
    290         self::factory()->activity->create( array(
    291             'user_id'   => $u3,
    292             'component' => 'activity',
    293             'type'      => 'activity_update',
    294             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    295         ) );
    296         self::factory()->activity->create( array(
    297             'user_id'   => $u3,
    298             'component' => 'groups',
    299             'item_id'   => 324,
    300             'type'      => 'activity_update',
    301             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    302         ) );
     318        self::factory()->activity->create(
     319            array(
     320                'user_id'       => $u1,
     321                'component'     => 'blogs',
     322                'item_id'       => 1,
     323                'type'          => 'new_blog_post',
     324                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     325            )
     326        );
     327        self::factory()->activity->create(
     328            array(
     329                'user_id'       => $u3,
     330                'component'     => 'activity',
     331                'type'          => 'activity_update',
     332                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     333            )
     334        );
     335        self::factory()->activity->create(
     336            array(
     337                'user_id'       => $u3,
     338                'component'     => 'groups',
     339                'item_id'       => 324,
     340                'type'          => 'activity_update',
     341                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     342            )
     343        );
    303344
    304345        global $activities_template;
    305346
    306347        // grab activities from multiple scopes
    307         bp_has_activities( array(
    308             'user_id' => $u1,
    309             'scope' => 'mentions,friends',
    310         ) );
     348        bp_has_activities(
     349            array(
     350                'user_id' => $u1,
     351                'scope'   => 'mentions,friends',
     352            )
     353        );
    311354
    312355        // assert!
     
    337380
    338381        // friend status update
    339         $a1 = self::factory()->activity->create( array(
    340             'user_id' => $u2,
    341             'type' => 'activity_update',
    342             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    343         ) );
     382        $a1 = self::factory()->activity->create(
     383            array(
     384                'user_id'       => $u2,
     385                'type'          => 'activity_update',
     386                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     387            )
     388        );
    344389
    345390        // group activity
    346         $a2 = self::factory()->activity->create( array(
    347             'user_id'   => $u3,
    348             'component' => 'groups',
    349             'item_id'   => $g1,
    350             'type'      => 'joined_group',
    351             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    352         ) );
     391        $a2 = self::factory()->activity->create(
     392            array(
     393                'user_id'       => $u3,
     394                'component'     => 'groups',
     395                'item_id'       => $g1,
     396                'type'          => 'joined_group',
     397                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     398            )
     399        );
    353400
    354401        // misc activity items
    355         self::factory()->activity->create( array(
    356             'user_id'   => $u3,
    357             'component' => 'blogs',
    358             'item_id'   => 1,
    359             'type'      => 'new_blog_post',
    360             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    361         ) );
    362         self::factory()->activity->create( array(
    363             'user_id'   => $u3,
    364             'component' => 'activity',
    365             'type'      => 'activity_update',
    366             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    367         ) );
     402        self::factory()->activity->create(
     403            array(
     404                'user_id'       => $u3,
     405                'component'     => 'blogs',
     406                'item_id'       => 1,
     407                'type'          => 'new_blog_post',
     408                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     409            )
     410        );
     411        self::factory()->activity->create(
     412            array(
     413                'user_id'       => $u3,
     414                'component'     => 'activity',
     415                'type'          => 'activity_update',
     416                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     417            )
     418        );
    368419
    369420        // Make sure we get a fake group ID.
    370421        global $wpdb, $bp;
    371422        $max_group_id = $wpdb->get_var( "SELECT id FROM {$bp->groups->table_name} ORDER BY id DESC LIMIT 1" );
    372         self::factory()->activity->create( array(
    373             'user_id'   => $u3,
    374             'component' => 'groups',
    375             'item_id'   => $max_group_id + 1,
    376             'type'      => 'activity_update',
    377             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    378         ) );
     423        self::factory()->activity->create(
     424            array(
     425                'user_id'       => $u3,
     426                'component'     => 'groups',
     427                'item_id'       => $max_group_id + 1,
     428                'type'          => 'activity_update',
     429                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     430            )
     431        );
    379432
    380433        global $activities_template;
    381434
    382435        // grab activities from multiple scopes
    383         bp_has_activities( array(
    384             'user_id' => $u1,
    385             'scope' => 'groups,friends',
    386         ) );
     436        bp_has_activities(
     437            array(
     438                'user_id' => $u1,
     439                'scope'   => 'groups,friends',
     440            )
     441        );
    387442
    388443        // assert!
     
    404459
    405460        // Create a random activity
    406         self::factory()->activity->create( array(
    407             'user_id' => $u1,
    408             'type' => 'activity_update',
    409             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    410         ) );
     461        self::factory()->activity->create(
     462            array(
     463                'user_id'       => $u1,
     464                'type'          => 'activity_update',
     465                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     466            )
     467        );
    411468
    412469        global $activities_template;
     
    414471
    415472        // grab activities from friends scope
    416         bp_has_activities( array(
    417             'user_id' => $u1,
    418             'scope' => 'friends',
    419         ) );
     473        bp_has_activities(
     474            array(
     475                'user_id' => $u1,
     476                'scope'   => 'friends',
     477            )
     478        );
    420479
    421480        // assert!
     
    437496
    438497        // Create a random activity
    439         self::factory()->activity->create( array(
    440             'user_id' => $u1,
    441             'type' => 'activity_update',
    442             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    443         ) );
     498        self::factory()->activity->create(
     499            array(
     500                'user_id'       => $u1,
     501                'type'          => 'activity_update',
     502                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     503            )
     504        );
    444505
    445506        global $activities_template;
     
    447508
    448509        // grab activities from favorites scope
    449         bp_has_activities( array(
    450             'user_id' => $u1,
    451             'scope' => 'favorites',
    452         ) );
     510        bp_has_activities(
     511            array(
     512                'user_id' => $u1,
     513                'scope'   => 'favorites',
     514            )
     515        );
    453516
    454517        // assert!
     
    470533
    471534        // Create a random activity
    472         self::factory()->activity->create( array(
    473             'user_id' => $u1,
    474             'type' => 'activity_update',
    475             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    476         ) );
     535        self::factory()->activity->create(
     536            array(
     537                'user_id'       => $u1,
     538                'type'          => 'activity_update',
     539                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     540            )
     541        );
    477542
    478543        global $activities_template;
     
    480545
    481546        // grab activities from groups scope
    482         bp_has_activities( array(
    483             'user_id' => $u1,
    484             'scope' => 'groups',
    485         ) );
     547        bp_has_activities(
     548            array(
     549                'user_id' => $u1,
     550                'scope'   => 'groups',
     551            )
     552        );
    486553
    487554        // assert!
     
    503570
    504571        // Create a random activity
    505         self::factory()->activity->create( array(
    506             'user_id' => $u1,
    507             'type' => 'activity_update',
    508             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    509         ) );
     572        self::factory()->activity->create(
     573            array(
     574                'user_id'       => $u1,
     575                'type'          => 'activity_update',
     576                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     577            )
     578        );
    510579
    511580        global $activities_template;
     
    513582
    514583        // grab activities from mentions scope
    515         bp_has_activities( array(
    516             'user_id' => $u1,
    517             'scope' => 'mentions',
    518         ) );
     584        bp_has_activities(
     585            array(
     586                'user_id' => $u1,
     587                'scope'   => 'mentions',
     588            )
     589        );
    519590
    520591        // assert!
     
    536607
    537608        // Friend's very fast status updates.
    538         $a1 = self::factory()->activity->create( array(
    539             'user_id' => $u2,
    540             'type' => 'activity_update',
    541             'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
    542         ) );
    543         $a2 = self::factory()->activity->create( array(
    544             'user_id' => $u2,
    545             'type' => 'activity_update',
    546             'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
    547         ) );
     609        $a1 = self::factory()->activity->create(
     610            array(
     611                'user_id'       => $u2,
     612                'type'          => 'activity_update',
     613                'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     614            )
     615        );
     616        $a2 = self::factory()->activity->create(
     617            array(
     618                'user_id'       => $u2,
     619                'type'          => 'activity_update',
     620                'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     621            )
     622        );
    548623
    549624        global $activities_template;
     
    551626
    552627        // Get activities in 'friends' scope
    553         bp_has_activities( array(
    554             'user_id' => $u1,
    555             'scope' => 'friends',
    556         ) );
     628        bp_has_activities(
     629            array(
     630                'user_id' => $u1,
     631                'scope'   => 'friends',
     632            )
     633        );
    557634
    558635        $found = $activities_template->activities;
     
    576653
    577654        // Two user join first user's group same time
    578         $a1 = self::factory()->activity->create( array(
    579             'user_id'   => $u2,
    580             'component' => 'groups',
    581             'item_id'   => $g1,
    582             'type'      => 'joined_group',
    583             'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
    584         ) );
    585         $a2 = self::factory()->activity->create( array(
    586             'user_id'   => $u3,
    587             'component' => 'groups',
    588             'item_id'   => $g1,
    589             'type'      => 'joined_group',
    590             'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
    591         ) );
     655        $a1 = self::factory()->activity->create(
     656            array(
     657                'user_id'       => $u2,
     658                'component'     => 'groups',
     659                'item_id'       => $g1,
     660                'type'          => 'joined_group',
     661                'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     662            )
     663        );
     664        $a2 = self::factory()->activity->create(
     665            array(
     666                'user_id'       => $u3,
     667                'component'     => 'groups',
     668                'item_id'       => $g1,
     669                'type'          => 'joined_group',
     670                'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     671            )
     672        );
    592673
    593674        global $activities_template;
     
    595676
    596677        // Get activities in 'groups' scope
    597         bp_has_activities( array(
    598             'user_id' => $u1,
    599             'scope' => 'groups',
    600         ) );
     678        bp_has_activities(
     679            array(
     680                'user_id' => $u1,
     681                'scope'   => 'groups',
     682            )
     683        );
    601684
    602685        $found = $activities_template->activities;
     
    619702        $now = time();
    620703
    621         $a1 = self::factory()->activity->create( array(
    622             'user_id'   => $u3,
    623             'component' => 'blogs',
    624             'item_id'   => 1,
    625             'type'      => 'new_blog_post',
    626             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    627         ) );
    628         $a2 = self::factory()->activity->create( array(
    629             'user_id'   => $u2,
    630             'component' => 'activity',
    631             'type'      => 'activity_update',
    632             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    633         ) );
     704        $a1 = self::factory()->activity->create(
     705            array(
     706                'user_id'       => $u3,
     707                'component'     => 'blogs',
     708                'item_id'       => 1,
     709                'type'          => 'new_blog_post',
     710                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     711            )
     712        );
     713        $a2 = self::factory()->activity->create(
     714            array(
     715                'user_id'       => $u2,
     716                'component'     => 'activity',
     717                'type'          => 'activity_update',
     718                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     719            )
     720        );
    634721
    635722        // misc activity items
    636         self::factory()->activity->create( array(
    637             'user_id'   => $u3,
    638             'component' => 'activity',
    639             'type'      => 'activity_update',
    640             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    641         ) );
    642         self::factory()->activity->create( array(
    643             'user_id'   => $u3,
    644             'component' => 'groups',
    645             'item_id'   => 324,
    646             'type'      => 'activity_update',
    647             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    648         ) );
    649 
    650         global $activities_template;
    651 
    652         bp_has_activities( array(
    653             'filter_query' => array(
    654                 'relation' => 'OR',
    655                 array(
    656                     'column' => 'component',
    657                     'value'  => 'blogs',
    658                 ),
    659                 array(
    660                     'relation' => 'AND',
     723        self::factory()->activity->create(
     724            array(
     725                'user_id'       => $u3,
     726                'component'     => 'activity',
     727                'type'          => 'activity_update',
     728                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     729            )
     730        );
     731        self::factory()->activity->create(
     732            array(
     733                'user_id'       => $u3,
     734                'component'     => 'groups',
     735                'item_id'       => 324,
     736                'type'          => 'activity_update',
     737                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     738            )
     739        );
     740
     741        global $activities_template;
     742
     743        bp_has_activities(
     744            array(
     745                'filter_query' => array(
     746                    'relation' => 'OR',
    661747                    array(
    662                         'column' => 'type',
    663                         'value'  => 'activity_update',
     748                        'column' => 'component',
     749                        'value'  => 'blogs',
    664750                    ),
    665751                    array(
    666                         'column' => 'user_id',
    667                         'value'  => $u2,
     752                        'relation' => 'AND',
     753                        array(
     754                            'column' => 'type',
     755                            'value'  => 'activity_update',
     756                        ),
     757                        array(
     758                            'column' => 'user_id',
     759                            'value'  => $u2,
     760                        ),
    668761                    ),
    669762                ),
    670763            )
    671         ) );
     764        );
    672765
    673766        // assert!
     
    690783
    691784        // misc activity items
    692         $a1 = self::factory()->activity->create( array(
    693             'user_id'   => $u3,
    694             'component' => 'blogs',
    695             'item_id'   => 1,
    696             'type'      => 'new_blog_post',
    697             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    698         ) );
    699         $a2 = self::factory()->activity->create( array(
    700             'user_id'   => $u2,
    701             'component' => 'activity',
    702             'type'      => 'activity_update',
    703             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    704         ) );
    705         $a3 = self::factory()->activity->create( array(
    706             'user_id'   => $u3,
    707             'component' => 'activity',
    708             'type'      => 'activity_update',
    709             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    710         ) );
    711         $a4 = self::factory()->activity->create( array(
    712             'user_id'   => $u3,
    713             'component' => 'groups',
    714             'item_id'   => 324,
    715             'type'      => 'activity_update',
    716             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    717         ) );
    718 
    719         global $activities_template;
    720 
    721         bp_has_activities( array(
    722             'filter_query' => array(
    723                 array(
    724                     'column'  => 'id',
    725                     'compare' => 'NOT IN',
    726                     'value'   => array( $a1, $a4 ),
     785        $a1 = self::factory()->activity->create(
     786            array(
     787                'user_id'       => $u3,
     788                'component'     => 'blogs',
     789                'item_id'       => 1,
     790                'type'          => 'new_blog_post',
     791                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     792            )
     793        );
     794        $a2 = self::factory()->activity->create(
     795            array(
     796                'user_id'       => $u2,
     797                'component'     => 'activity',
     798                'type'          => 'activity_update',
     799                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     800            )
     801        );
     802        $a3 = self::factory()->activity->create(
     803            array(
     804                'user_id'       => $u3,
     805                'component'     => 'activity',
     806                'type'          => 'activity_update',
     807                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     808            )
     809        );
     810        $a4 = self::factory()->activity->create(
     811            array(
     812                'user_id'       => $u3,
     813                'component'     => 'groups',
     814                'item_id'       => 324,
     815                'type'          => 'activity_update',
     816                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     817            )
     818        );
     819
     820        global $activities_template;
     821
     822        bp_has_activities(
     823            array(
     824                'filter_query' => array(
     825                    array(
     826                        'column'  => 'id',
     827                        'compare' => 'NOT IN',
     828                        'value'   => array( $a1, $a4 ),
     829                    ),
    727830                ),
    728831            )
    729         ) );
     832        );
    730833
    731834        // assert!
     
    746849
    747850        // misc activity items
    748         $a1 = self::factory()->activity->create( array(
    749             'user_id'   => $u1,
    750             'component' => 'blogs',
    751             'item_id'   => 1,
    752             'type'      => 'new_blog_post',
    753             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    754         ) );
    755         $a2 = self::factory()->activity->create( array(
    756             'user_id'   => $u1,
    757             'component' => 'activity',
    758             'type'      => 'activity_update',
    759             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    760         ) );
    761         $a3 = self::factory()->activity->create( array(
    762             'user_id'   => $u1,
    763             'component' => 'activity',
    764             'type'      => 'activity_update',
    765             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    766         ) );
    767         $a4 = self::factory()->activity->create( array(
    768             'user_id'   => $u1,
    769             'component' => 'groups',
    770             'item_id'   => 324,
    771             'type'      => 'activity_update',
    772             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    773         ) );
    774 
    775         global $activities_template;
    776 
    777         bp_has_activities( array(
    778             'filter_query' => array(
    779                 array(
    780                     'column'  => 'id',
    781                     'compare' => 'BETWEEN',
    782                     'value'   => array( $a3, $a4 ),
     851        $a1 = self::factory()->activity->create(
     852            array(
     853                'user_id'       => $u1,
     854                'component'     => 'blogs',
     855                'item_id'       => 1,
     856                'type'          => 'new_blog_post',
     857                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     858            )
     859        );
     860        $a2 = self::factory()->activity->create(
     861            array(
     862                'user_id'       => $u1,
     863                'component'     => 'activity',
     864                'type'          => 'activity_update',
     865                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     866            )
     867        );
     868        $a3 = self::factory()->activity->create(
     869            array(
     870                'user_id'       => $u1,
     871                'component'     => 'activity',
     872                'type'          => 'activity_update',
     873                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     874            )
     875        );
     876        $a4 = self::factory()->activity->create(
     877            array(
     878                'user_id'       => $u1,
     879                'component'     => 'groups',
     880                'item_id'       => 324,
     881                'type'          => 'activity_update',
     882                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     883            )
     884        );
     885
     886        global $activities_template;
     887
     888        bp_has_activities(
     889            array(
     890                'filter_query' => array(
     891                    array(
     892                        'column'  => 'id',
     893                        'compare' => 'BETWEEN',
     894                        'value'   => array( $a3, $a4 ),
     895                    ),
    783896                ),
    784897            )
    785         ) );
     898        );
    786899
    787900        // assert!
     
    802915
    803916        // misc activity items
    804         $a1 = self::factory()->activity->create( array(
    805             'user_id'   => $u1,
    806             'component' => 'activity',
    807             'item_id'   => 1,
    808             'type'      => 'activity_update',
    809             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    810         ) );
    811         $a2 = self::factory()->activity->create( array(
    812             'user_id'   => $u1,
    813             'component' => 'activity',
    814             'item_id'   => 10,
    815             'type'      => 'activity_update',
    816             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    817         ) );
    818         $a3 = self::factory()->activity->create( array(
    819             'user_id'   => $u1,
    820             'component' => 'activity',
    821             'item_id'   => 25,
    822             'type'      => 'activity_update',
    823             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    824         ) );
    825         $a4 = self::factory()->activity->create( array(
    826             'user_id'   => $u1,
    827             'component' => 'activity',
    828             'item_id'   => 100,
    829             'type'      => 'activity_update',
    830             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    831         ) );
     917        $a1 = self::factory()->activity->create(
     918            array(
     919                'user_id'       => $u1,
     920                'component'     => 'activity',
     921                'item_id'       => 1,
     922                'type'          => 'activity_update',
     923                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     924            )
     925        );
     926        $a2 = self::factory()->activity->create(
     927            array(
     928                'user_id'       => $u1,
     929                'component'     => 'activity',
     930                'item_id'       => 10,
     931                'type'          => 'activity_update',
     932                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     933            )
     934        );
     935        $a3 = self::factory()->activity->create(
     936            array(
     937                'user_id'       => $u1,
     938                'component'     => 'activity',
     939                'item_id'       => 25,
     940                'type'          => 'activity_update',
     941                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     942            )
     943        );
     944        $a4 = self::factory()->activity->create(
     945            array(
     946                'user_id'       => $u1,
     947                'component'     => 'activity',
     948                'item_id'       => 100,
     949                'type'          => 'activity_update',
     950                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     951            )
     952        );
    832953
    833954        global $activities_template;
    834955
    835956        // greater than
    836         bp_has_activities( array(
    837             'filter_query' => array(
    838                 array(
    839                     'column'  => 'item_id',
    840                     'compare' => '>',
    841                     'value'   => 10,
     957        bp_has_activities(
     958            array(
     959                'filter_query' => array(
     960                    array(
     961                        'column'  => 'item_id',
     962                        'compare' => '>',
     963                        'value'   => 10,
     964                    ),
    842965                ),
    843966            )
    844         ) );
     967        );
    845968
    846969        // assert!
     
    848971
    849972        // greater or equal than
    850         bp_has_activities( array(
    851             'filter_query' => array(
    852                 array(
    853                     'column'  => 'item_id',
    854                     'compare' => '>=',
    855                     'value'   => 10,
     973        bp_has_activities(
     974            array(
     975                'filter_query' => array(
     976                    array(
     977                        'column'  => 'item_id',
     978                        'compare' => '>=',
     979                        'value'   => 10,
     980                    ),
    856981                ),
    857982            )
    858         ) );
     983        );
    859984
    860985        // assert!
     
    862987
    863988        // less than
    864         bp_has_activities( array(
    865             'filter_query' => array(
    866                 array(
    867                     'column'  => 'item_id',
    868                     'compare' => '<',
    869                     'value'   => 10,
     989        bp_has_activities(
     990            array(
     991                'filter_query' => array(
     992                    array(
     993                        'column'  => 'item_id',
     994                        'compare' => '<',
     995                        'value'   => 10,
     996                    ),
    870997                ),
    871998            )
    872         ) );
     999        );
    8731000
    8741001        // assert!
     
    8761003
    8771004        // less or equal than
    878         bp_has_activities( array(
    879             'filter_query' => array(
    880                 array(
    881                     'column'  => 'item_id',
    882                     'compare' => '<=',
    883                     'value'   => 10,
     1005        bp_has_activities(
     1006            array(
     1007                'filter_query' => array(
     1008                    array(
     1009                        'column'  => 'item_id',
     1010                        'compare' => '<=',
     1011                        'value'   => 10,
     1012                    ),
    8841013                ),
    8851014            )
    886         ) );
     1015        );
    8871016
    8881017        // assert!
     
    8901019
    8911020        // not equal to
    892         bp_has_activities( array(
    893             'filter_query' => array(
    894                 array(
    895                     'column'  => 'item_id',
    896                     'compare' => '!=',
    897                     'value'   => 10,
     1021        bp_has_activities(
     1022            array(
     1023                'filter_query' => array(
     1024                    array(
     1025                        'column'  => 'item_id',
     1026                        'compare' => '!=',
     1027                        'value'   => 10,
     1028                    ),
    8981029                ),
    8991030            )
    900         ) );
     1031        );
    9011032
    9021033        // assert!
     
    9181049
    9191050        // misc activity items
    920         $a1 = self::factory()->activity->create( array(
    921             'user_id'   => $u1,
    922             'component' => 'blogs',
    923             'item_id'   => 1,
    924             'type'      => 'new_blog_post',
    925             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    926         ) );
    927         $a2 = self::factory()->activity->create( array(
    928             'user_id'   => $u1,
    929             'component' => 'blogs',
    930             'type'      => 'new_blog_comment',
    931             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    932         ) );
    933         $a3 = self::factory()->activity->create( array(
    934             'user_id'   => $u1,
    935             'component' => 'activity',
    936             'type'      => 'activity_update',
    937             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    938         ) );
    939         $a4 = self::factory()->activity->create( array(
    940             'user_id'   => $u1,
    941             'component' => 'groups',
    942             'item_id'   => 324,
    943             'type'      => 'activity_update',
    944             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    945         ) );
     1051        $a1 = self::factory()->activity->create(
     1052            array(
     1053                'user_id'       => $u1,
     1054                'component'     => 'blogs',
     1055                'item_id'       => 1,
     1056                'type'          => 'new_blog_post',
     1057                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1058            )
     1059        );
     1060        $a2 = self::factory()->activity->create(
     1061            array(
     1062                'user_id'       => $u1,
     1063                'component'     => 'blogs',
     1064                'type'          => 'new_blog_comment',
     1065                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1066            )
     1067        );
     1068        $a3 = self::factory()->activity->create(
     1069            array(
     1070                'user_id'       => $u1,
     1071                'component'     => 'activity',
     1072                'type'          => 'activity_update',
     1073                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1074            )
     1075        );
     1076        $a4 = self::factory()->activity->create(
     1077            array(
     1078                'user_id'       => $u1,
     1079                'component'     => 'groups',
     1080                'item_id'       => 324,
     1081                'type'          => 'activity_update',
     1082                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1083            )
     1084        );
    9461085
    9471086        global $activities_template;
    9481087
    9491088        // REGEXP
    950         bp_has_activities( array(
    951             'filter_query' => array(
    952                 array(
    953                     'column'  => 'type',
    954                     'compare' => 'REGEXP',
    955                     'value'   => '^new_blog_',
     1089        bp_has_activities(
     1090            array(
     1091                'filter_query' => array(
     1092                    array(
     1093                        'column'  => 'type',
     1094                        'compare' => 'REGEXP',
     1095                        'value'   => '^new_blog_',
     1096                    ),
    9561097                ),
    9571098            )
    958         ) );
     1099        );
    9591100
    9601101        // assert!
     
    9621103
    9631104        // RLIKE is a synonym for REGEXP
    964         bp_has_activities( array(
    965             'filter_query' => array(
    966                 array(
    967                     'column'  => 'type',
    968                     'compare' => 'RLIKE',
    969                     'value'   => '^new_blog_',
     1105        bp_has_activities(
     1106            array(
     1107                'filter_query' => array(
     1108                    array(
     1109                        'column'  => 'type',
     1110                        'compare' => 'RLIKE',
     1111                        'value'   => '^new_blog_',
     1112                    ),
    9701113                ),
    9711114            )
    972         ) );
     1115        );
    9731116
    9741117        // assert!
     
    9761119
    9771120        // NOT REGEXP
    978         bp_has_activities( array(
    979             'filter_query' => array(
    980                 array(
    981                     'column'  => 'type',
    982                     'compare' => 'NOT REGEXP',
    983                     'value'   => '^new_blog_',
     1121        bp_has_activities(
     1122            array(
     1123                'filter_query' => array(
     1124                    array(
     1125                        'column'  => 'type',
     1126                        'compare' => 'NOT REGEXP',
     1127                        'value'   => '^new_blog_',
     1128                    ),
    9841129                ),
    9851130            )
    986         ) );
     1131        );
    9871132
    9881133        // assert!
     
    9991144    public function test_bp_has_activities_private_group_home_scope() {
    10001145        global $activities_template;
    1001         $bp = buddypress();
    1002         $reset_current_group = $bp->groups->current_group;
     1146        $bp                   = buddypress();
     1147        $reset_current_group  = $bp->groups->current_group;
    10031148        $reset_current_action = $bp->current_action;
    10041149
     
    10091154        self::set_current_user( $u1 );
    10101155
    1011         $g = self::factory()->group->create( array(
    1012             'status' => 'private',
    1013         ) );
     1156        $g = self::factory()->group->create(
     1157            array(
     1158                'status' => 'private',
     1159            )
     1160        );
    10141161
    10151162        groups_join_group( $g, $u2 );
    10161163        groups_join_group( $g, $u3 );
    10171164
    1018         $a1 = self::factory()->activity->create( array(
    1019             'component' => $bp->groups->id,
    1020             'item_id'   => $g,
    1021             'type'      => 'activity_update',
    1022             'user_id'   => $u2,
    1023             'content'   => 'foo bar',
    1024         ) );
    1025 
    1026         $a2 = self::factory()->activity->create( array(
    1027             'component' => $bp->groups->id,
    1028             'item_id'   => $g,
    1029             'type'      => 'activity_update',
    1030             'user_id'   => $u3,
    1031             'content'   => 'bar foo',
    1032         ) );
     1165        $a1 = self::factory()->activity->create(
     1166            array(
     1167                'component' => $bp->groups->id,
     1168                'item_id'   => $g,
     1169                'type'      => 'activity_update',
     1170                'user_id'   => $u2,
     1171                'content'   => 'foo bar',
     1172            )
     1173        );
     1174
     1175        $a2 = self::factory()->activity->create(
     1176            array(
     1177                'component' => $bp->groups->id,
     1178                'item_id'   => $g,
     1179                'type'      => 'activity_update',
     1180                'user_id'   => $u3,
     1181                'content'   => 'bar foo',
     1182            )
     1183        );
    10331184
    10341185        $bp->groups->current_group = groups_get_group( $g );
     
    10421193
    10431194        // clean up!
    1044         $activities_template = null;
     1195        $activities_template       = null;
    10451196        $bp->groups->current_group = $reset_current_group;
    1046         $bp->current_action = $reset_current_action;
     1197        $bp->current_action        = $reset_current_action;
    10471198    }
    10481199
     
    10531204    public function test_bp_has_activities_hidden_group_home_scope() {
    10541205        global $activities_template;
    1055         $bp = buddypress();
    1056         $reset_current_group = $bp->groups->current_group;
     1206        $bp                   = buddypress();
     1207        $reset_current_group  = $bp->groups->current_group;
    10571208        $reset_current_action = $bp->current_action;
    10581209
     
    10631214        self::set_current_user( $u1 );
    10641215
    1065         $g = self::factory()->group->create( array(
    1066             'status' => 'hidden',
    1067         ) );
     1216        $g = self::factory()->group->create(
     1217            array(
     1218                'status' => 'hidden',
     1219            )
     1220        );
    10681221
    10691222        groups_join_group( $g, $u2 );
    10701223        groups_join_group( $g, $u3 );
    10711224
    1072         $a1 = self::factory()->activity->create( array(
    1073             'component' => $bp->groups->id,
    1074             'item_id'   => $g,
    1075             'type'      => 'activity_update',
    1076             'user_id'   => $u2,
    1077             'content'   => 'foo bar',
    1078         ) );
    1079 
    1080         $a2 = self::factory()->activity->create( array(
    1081             'component' => $bp->groups->id,
    1082             'item_id'   => $g,
    1083             'type'      => 'activity_update',
    1084             'user_id'   => $u3,
    1085             'content'   => 'bar foo',
    1086         ) );
     1225        $a1 = self::factory()->activity->create(
     1226            array(
     1227                'component' => $bp->groups->id,
     1228                'item_id'   => $g,
     1229                'type'      => 'activity_update',
     1230                'user_id'   => $u2,
     1231                'content'   => 'foo bar',
     1232            )
     1233        );
     1234
     1235        $a2 = self::factory()->activity->create(
     1236            array(
     1237                'component' => $bp->groups->id,
     1238                'item_id'   => $g,
     1239                'type'      => 'activity_update',
     1240                'user_id'   => $u3,
     1241                'content'   => 'bar foo',
     1242            )
     1243        );
    10871244
    10881245        $bp->groups->current_group = groups_get_group( $g );
     
    10961253
    10971254        // clean up!
    1098         $activities_template = null;
     1255        $activities_template       = null;
    10991256        $bp->groups->current_group = $reset_current_group;
    1100         $bp->current_action = $reset_current_action;
     1257        $bp->current_action        = $reset_current_action;
    11011258    }
    11021259
     
    11101267
    11111268        global $activities_template;
    1112         bp_has_activities( array(
    1113             'meta_query' => array(
    1114                 array(
    1115                     'key' => 'foo',
    1116                     'value' => 'bar',
     1269        bp_has_activities(
     1270            array(
     1271                'meta_query' => array(
     1272                    array(
     1273                        'key'   => 'foo',
     1274                        'value' => 'bar',
     1275                    ),
    11171276                ),
    1118             ),
    1119         ) );
     1277            )
     1278        );
    11201279
    11211280        $ids = wp_list_pluck( $activities_template->activities, 'id' );
     
    11291288    public function test_bp_has_activities_with_display_comments_false() {
    11301289        $now = time();
    1131         $a1 = self::factory()->activity->create( array(
    1132             'content' => 'Life Rules',
    1133             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1134         ) );
    1135         $a2 = self::factory()->activity->create( array(
    1136             'content' => 'Life Drools',
    1137             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1138         ) );
    1139         $a3 = bp_activity_new_comment( array(
    1140             'activity_id' => $a1,
    1141             'content' => 'Candy is good',
    1142             'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
    1143         ) );
    1144 
    1145         global $activities_template;
    1146         bp_has_activities( array(
    1147             'display_comments' => false,
    1148         ) );
     1290        $a1  = self::factory()->activity->create(
     1291            array(
     1292                'content'       => 'Life Rules',
     1293                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1294            )
     1295        );
     1296        $a2  = self::factory()->activity->create(
     1297            array(
     1298                'content'       => 'Life Drools',
     1299                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1300            )
     1301        );
     1302        $a3  = bp_activity_new_comment(
     1303            array(
     1304                'activity_id'   => $a1,
     1305                'content'       => 'Candy is good',
     1306                'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     1307            )
     1308        );
     1309
     1310        global $activities_template;
     1311        bp_has_activities(
     1312            array(
     1313                'display_comments' => false,
     1314            )
     1315        );
    11491316        $ids = wp_list_pluck( $activities_template->activities, 'id' );
    11501317
    11511318        $this->assertEquals( array( $a1, $a2 ), wp_parse_id_list( $ids ) );
    1152 
    11531319    }
    11541320
     
    11591325    public function test_bp_has_activities_with_display_comments_0() {
    11601326        $now = time();
    1161         $a1 = self::factory()->activity->create( array(
    1162             'content' => 'Life Rules',
    1163             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1164         ) );
    1165         $a2 = self::factory()->activity->create( array(
    1166             'content' => 'Life Drools',
    1167             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1168         ) );
    1169         $a3 = bp_activity_new_comment( array(
    1170             'activity_id' => $a1,
    1171             'content' => 'Candy is good',
    1172             'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
    1173         ) );
    1174 
    1175         global $activities_template;
    1176         bp_has_activities( array(
    1177             'display_comments' => 0,
    1178         ) );
     1327        $a1  = self::factory()->activity->create(
     1328            array(
     1329                'content'       => 'Life Rules',
     1330                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1331            )
     1332        );
     1333        $a2  = self::factory()->activity->create(
     1334            array(
     1335                'content'       => 'Life Drools',
     1336                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1337            )
     1338        );
     1339        $a3  = bp_activity_new_comment(
     1340            array(
     1341                'activity_id'   => $a1,
     1342                'content'       => 'Candy is good',
     1343                'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     1344            )
     1345        );
     1346
     1347        global $activities_template;
     1348        bp_has_activities(
     1349            array(
     1350                'display_comments' => 0,
     1351            )
     1352        );
    11791353        $ids = wp_list_pluck( $activities_template->activities, 'id' );
    11801354
    11811355        $this->assertEquals( array( $a1, $a2 ), wp_parse_id_list( $ids ) );
    1182 
    11831356    }
    11841357
     
    11891362    public function test_bp_has_activities_with_display_comments_0_querystring() {
    11901363        $now = time();
    1191         $a1 = self::factory()->activity->create( array(
    1192             'content' => 'Life Rules',
    1193             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1194         ) );
    1195         $a2 = self::factory()->activity->create( array(
    1196             'content' => 'Life Drools',
    1197             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1198         ) );
    1199         $a3 = bp_activity_new_comment( array(
    1200             'activity_id' => $a1,
    1201             'content' => 'Candy is good',
    1202             'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
    1203         ) );
     1364        $a1  = self::factory()->activity->create(
     1365            array(
     1366                'content'       => 'Life Rules',
     1367                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1368            )
     1369        );
     1370        $a2  = self::factory()->activity->create(
     1371            array(
     1372                'content'       => 'Life Drools',
     1373                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1374            )
     1375        );
     1376        $a3  = bp_activity_new_comment(
     1377            array(
     1378                'activity_id'   => $a1,
     1379                'content'       => 'Candy is good',
     1380                'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     1381            )
     1382        );
    12041383
    12051384        global $activities_template;
     
    12081387
    12091388        $this->assertEquals( array( $a1, $a2 ), $ids );
    1210 
    12111389    }
    12121390
     
    12171395    public function test_bp_has_activities_with_display_comments_none_querystring() {
    12181396        $now = time();
    1219         $a1 = self::factory()->activity->create( array(
    1220             'content' => 'Life Rules',
    1221             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1222         ) );
    1223         $a2 = self::factory()->activity->create( array(
    1224             'content' => 'Life Drools',
    1225             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1226         ) );
    1227         $a3 = bp_activity_new_comment( array(
    1228             'activity_id' => $a1,
    1229             'content' => 'Candy is good',
    1230             'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
    1231         ) );
     1397        $a1  = self::factory()->activity->create(
     1398            array(
     1399                'content'       => 'Life Rules',
     1400                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1401            )
     1402        );
     1403        $a2  = self::factory()->activity->create(
     1404            array(
     1405                'content'       => 'Life Drools',
     1406                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1407            )
     1408        );
     1409        $a3  = bp_activity_new_comment(
     1410            array(
     1411                'activity_id'   => $a1,
     1412                'content'       => 'Candy is good',
     1413                'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     1414            )
     1415        );
    12321416
    12331417        global $activities_template;
     
    12361420
    12371421        $this->assertEquals( array( $a1, $a2 ), $ids );
    1238 
    12391422    }
    12401423
     
    12451428    public function test_bp_has_activities_with_update_meta_cache_false() {
    12461429        $now = time();
    1247         $a1 = self::factory()->activity->create( array(
    1248             'content' => 'Life Rules',
    1249             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1250         ) );
    1251         $a2 = self::factory()->activity->create( array(
    1252             'content' => 'Life Drools',
    1253             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1254         ) );
     1430        $a1  = self::factory()->activity->create(
     1431            array(
     1432                'content'       => 'Life Rules',
     1433                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1434            )
     1435        );
     1436        $a2  = self::factory()->activity->create(
     1437            array(
     1438                'content'       => 'Life Drools',
     1439                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1440            )
     1441        );
    12551442
    12561443        bp_activity_add_meta( $a1, 'foo', 'bar' );
     
    12581445
    12591446        // prime
    1260         bp_has_activities( array(
    1261             'update_meta_cache' => false,
    1262         ) );
     1447        bp_has_activities(
     1448            array(
     1449                'update_meta_cache' => false,
     1450            )
     1451        );
    12631452
    12641453        $this->assertFalse( wp_cache_get( $a1, 'activity_meta' ) );
     
    12721461    public function test_bp_has_activities_with_update_meta_cache_true() {
    12731462        $now = time();
    1274         $a1 = self::factory()->activity->create( array(
    1275             'content' => 'Life Rules',
    1276             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1277         ) );
    1278         $a2 = self::factory()->activity->create( array(
    1279             'content' => 'Life Drools',
    1280             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1281         ) );
     1463        $a1  = self::factory()->activity->create(
     1464            array(
     1465                'content'       => 'Life Rules',
     1466                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1467            )
     1468        );
     1469        $a2  = self::factory()->activity->create(
     1470            array(
     1471                'content'       => 'Life Drools',
     1472                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1473            )
     1474        );
    12821475
    12831476        bp_activity_add_meta( $a1, 'foo', 'bar' );
     
    12851478
    12861479        // prime
    1287         bp_has_activities( array(
    1288             'update_meta_cache' => true,
    1289         ) );
     1480        bp_has_activities(
     1481            array(
     1482                'update_meta_cache' => true,
     1483            )
     1484        );
    12901485
    12911486        $this->assertNotEmpty( wp_cache_get( $a1, 'activity_meta' ) );
     
    13031498
    13041499        $now = time();
    1305         $a1 = self::factory()->activity->create( array(
    1306             'content' => 'Life Rules',
    1307             'component' => 'blogs',
    1308             'type' => 'new_blog_post',
    1309             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1310             'user_id' => $u,
    1311         ) );
    1312         $a2 = self::factory()->activity->create( array(
    1313             'content' => 'Life Drools',
    1314             'component' => 'blogs',
    1315             'type' => 'new_blog_comment',
    1316             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1317             'user_id' => $u,
    1318         ) );
     1500        $a1  = self::factory()->activity->create(
     1501            array(
     1502                'content'       => 'Life Rules',
     1503                'component'     => 'blogs',
     1504                'type'          => 'new_blog_post',
     1505                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1506                'user_id'       => $u,
     1507            )
     1508        );
     1509        $a2  = self::factory()->activity->create(
     1510            array(
     1511                'content'       => 'Life Drools',
     1512                'component'     => 'blogs',
     1513                'type'          => 'new_blog_comment',
     1514                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1515                'user_id'       => $u,
     1516            )
     1517        );
    13191518
    13201519        // This one will show up in the stream because it's a comment
    13211520        // on a blog post
    1322         $a3 = bp_activity_new_comment( array(
    1323             'activity_id' => $a1,
    1324             'content' => 'Candy is good',
    1325             'recorded_time' => date( 'Y-m-d H:i:s', $now - 200 ),
    1326             'user_id' => $u,
    1327         ) );
    1328 
    1329         $a4 = self::factory()->activity->create( array(
    1330             'content' => 'Life Rulez',
    1331             'component' => 'activity',
    1332             'type' => 'activity_update',
    1333             'recorded_time' => date( 'Y-m-d H:i:s', $now - 300 ),
    1334             'user_id' => $u,
    1335         ) );
     1521        $a3 = bp_activity_new_comment(
     1522            array(
     1523                'activity_id'   => $a1,
     1524                'content'       => 'Candy is good',
     1525                'recorded_time' => date( 'Y-m-d H:i:s', $now - 200 ),
     1526                'user_id'       => $u,
     1527            )
     1528        );
     1529
     1530        $a4 = self::factory()->activity->create(
     1531            array(
     1532                'content'       => 'Life Rulez',
     1533                'component'     => 'activity',
     1534                'type'          => 'activity_update',
     1535                'recorded_time' => date( 'Y-m-d H:i:s', $now - 300 ),
     1536                'user_id'       => $u,
     1537            )
     1538        );
    13361539
    13371540        // This one should not show up in the stream because it's a
    13381541        // comment on an activity item
    1339         $a5 = bp_activity_new_comment( array(
    1340             'activity_id' => $a4,
    1341             'content' => 'Candy is great',
    1342             'recorded_time' => date( 'Y-m-d H:i:s', $now - 400 ),
    1343             'user_id' => $u,
    1344         ) );
     1542        $a5 = bp_activity_new_comment(
     1543            array(
     1544                'activity_id'   => $a4,
     1545                'content'       => 'Candy is great',
     1546                'recorded_time' => date( 'Y-m-d H:i:s', $now - 400 ),
     1547                'user_id'       => $u,
     1548            )
     1549        );
    13451550        global $activities_template;
    13461551
    13471552        // prime
    1348         bp_has_activities( array(
    1349             'component' => 'blogs',
    1350             'action' => 'new_blog_comment',
    1351         ) );
     1553        bp_has_activities(
     1554            array(
     1555                'component' => 'blogs',
     1556                'action'    => 'new_blog_comment',
     1557            )
     1558        );
    13521559
    13531560        $this->assertEquals( array( $a3, $a2 ), wp_parse_id_list( wp_list_pluck( $activities_template->activities, 'id' ) ) );
     
    13701577        // Fake the global
    13711578        global $activities_template;
    1372         $activities_template = new stdClass;
    1373         $activities_template->activity = new stdClass;
    1374         $activities_template->activity->current_comment = new stdClass;
    1375 
    1376         $comment = new stdClass;
     1579        $activities_template                            = new stdClass();
     1580        $activities_template->activity                  = new stdClass();
     1581        $activities_template->activity->current_comment = new stdClass();
     1582
     1583        $comment          = new stdClass();
    13771584        $comment->item_id = 4;
    13781585
     
    14071614        // Fake the global
    14081615        global $activities_template;
    1409         $activities_template = new stdClass;
    1410         $activities_template->activity = new stdClass;
    1411         $activities_template->activity->current_comment = new stdClass;
    1412 
    1413         $comment = new stdClass;
     1616        $activities_template                            = new stdClass();
     1617        $activities_template->activity                  = new stdClass();
     1618        $activities_template->activity->current_comment = new stdClass();
     1619
     1620        $comment          = new stdClass();
    14141621        $comment->item_id = 4;
    14151622
     
    14331640        $reset_activities_template = $activities_template;
    14341641
    1435         $activities_template = new stdClass;
     1642        $activities_template                            = new stdClass();
    14361643        $activities_template->disable_blogforum_replies = true;
    1437         $activities_template->activity = (object) array( 'type' => 'activity_comment' );
     1644        $activities_template->activity                  = (object) array( 'type' => 'activity_comment' );
    14381645
    14391646        $this->assertFalse( bp_activity_can_comment(), 'bp_activity_can_comment() should return false if the activity type is activity_comment' );
     
    14431650            'new_blog_comment',
    14441651            'new_forum_topic',
    1445             'new_forum_post'
     1652            'new_forum_post',
    14461653        );
    14471654
     
    14731680
    14741681        $reset_activities_template = $activities_template;
    1475         $reset_activity_track = $bp->activity->track;
    1476 
    1477         $activities_template = new stdClass;
     1682        $reset_activity_track      = $bp->activity->track;
     1683
     1684        $activities_template                            = new stdClass();
    14781685        $activities_template->disable_blogforum_replies = true;
    14791686
    1480         register_post_type( 'foo', array(
    1481             'label'   => 'foo',
    1482             'public'   => true,
    1483             'supports' => array( 'buddypress-activity' ),
    1484         ) );
     1687        register_post_type(
     1688            'foo',
     1689            array(
     1690                'label'    => 'foo',
     1691                'public'   => true,
     1692                'supports' => array( 'buddypress-activity' ),
     1693            )
     1694        );
    14851695
    14861696        $bp->activity->track = bp_activity_get_post_types_tracking_args();
     
    14961706        $this->assertFalse( bp_activity_can_comment(), 'If post type support comments, a post type activity cannot be commented' );
    14971707
    1498         $bp_activity_support = (array) $bp->activity->track['new_foo'];
     1708        $bp_activity_support                     = (array) $bp->activity->track['new_foo'];
    14991709        $bp_activity_support['activity_comment'] = true;
    15001710
     
    15381748        $args = array(
    15391749            'count_total' => false,
    1540             'per_page' => 2,
     1750            'per_page'    => 2,
    15411751        );
    15421752
     
    15791789        $args = array(
    15801790            'count_total' => 'count_query',
    1581             'per_page' => 2,
     1791            'per_page'    => 2,
    15821792        );
    15831793
     
    16011811
    16021812        $a1 = self::factory()->activity->create();
    1603         $a2 = self::factory()->activity->create( array(
    1604             'recorded_time' => '2001-01-01 12:00'
    1605         ) );
    1606         $a3 = self::factory()->activity->create( array(
    1607             'recorded_time' => '2005-01-01 12:00'
    1608         ) );
    1609 
    1610         global $activities_template;
    1611         bp_has_activities( array(
    1612             'date_query' => array( array(
    1613                 'after' => '1 day ago'
    1614             ) )
    1615         ) );
     1813        $a2 = self::factory()->activity->create(
     1814            array(
     1815                'recorded_time' => '2001-01-01 12:00',
     1816            )
     1817        );
     1818        $a3 = self::factory()->activity->create(
     1819            array(
     1820                'recorded_time' => '2005-01-01 12:00',
     1821            )
     1822        );
     1823
     1824        global $activities_template;
     1825        bp_has_activities(
     1826            array(
     1827                'date_query' => array(
     1828                    array(
     1829                        'after' => '1 day ago',
     1830                    ),
     1831                ),
     1832            )
     1833        );
    16161834
    16171835        $ids = wp_list_pluck( $activities_template->activities, 'id' );
     
    16241842     */
    16251843    public function test_bp_activity_template_should_give_precedence_to_acpage_URL_param() {
    1626         $request = $_REQUEST;
     1844        $request            = $_REQUEST;
    16271845        $_REQUEST['acpage'] = '5';
    16281846
    1629         $at = new BP_Activity_Template( array(
    1630             'page' => 8,
    1631         ) );
     1847        $at = new BP_Activity_Template(
     1848            array(
     1849                'page' => 8,
     1850            )
     1851        );
    16321852
    16331853        $this->assertEquals( 5, $at->pag_page );
     
    16411861     */
    16421862    public function test_bp_activity_template_should_reset_0_pag_page_URL_param_to_default_pag_page_value() {
    1643         $request = $_REQUEST;
     1863        $request            = $_REQUEST;
    16441864        $_REQUEST['acpage'] = '0';
    16451865
    1646         $at = new BP_Activity_Template( array(
    1647             'page' => 8,
    1648         ) );
     1866        $at = new BP_Activity_Template(
     1867            array(
     1868                'page' => 8,
     1869            )
     1870        );
    16491871
    16501872        $this->assertEquals( 8, $at->pag_page );
     
    16581880     */
    16591881    public function test_bp_activity_template_should_give_precedence_to_num_URL_param() {
    1660         $request = $_REQUEST;
     1882        $request         = $_REQUEST;
    16611883        $_REQUEST['num'] = '14';
    16621884
    1663         $at = new BP_Activity_Template( array(
    1664             'per_page' => 13,
    1665         ) );
     1885        $at = new BP_Activity_Template(
     1886            array(
     1887                'per_page' => 13,
     1888            )
     1889        );
    16661890
    16671891        $this->assertEquals( 14, $at->pag_num );
     
    16751899     */
    16761900    public function test_bp_activity_template_should_reset_0_pag_num_URL_param_to_default_pag_num_value() {
    1677         $request = $_REQUEST;
     1901        $request         = $_REQUEST;
    16781902        $_REQUEST['num'] = '0';
    16791903
    1680         $at = new BP_Activity_Template( array(
    1681             'per_page' => 13,
    1682         ) );
     1904        $at = new BP_Activity_Template(
     1905            array(
     1906                'per_page' => 13,
     1907            )
     1908        );
    16831909
    16841910        $this->assertEquals( 13, $at->pag_num );
  • trunk/tests/phpunit/testcases/blogs/template.php

    r13184 r14026  
    1919        $this->assertEquals( bp_core_get_last_activity( $time, __( 'Active %s', 'buddypress' ) ), bp_get_blog_last_active() );
    2020
    21         $blogs_template->blog = null;
     21        $blogs_template = null;
    2222    }
    2323
     
    3636        $this->assertEquals( bp_core_get_last_activity( $time, __( 'Active %s', 'buddypress' ) ), bp_get_blog_last_active( array( 'active_format' => true, ) ) );
    3737
    38         $blogs_template->blog = null;
     38        $blogs_template = null;
    3939    }
    4040
     
    5353        $this->assertEquals( bp_core_time_since( $time ), bp_get_blog_last_active( array( 'active_format' => false, ) ) );
    5454
    55         $blogs_template->blog = null;
     55        $blogs_template = null;
    5656    }
    5757
     
    7878        $this->assertSame( sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="foo">bar</a>' ), bp_get_blog_latest_post() );
    7979
    80         $blogs_template->blog = null;
     80        $blogs_template = null;
    8181    }
    8282
     
    9696        $this->assertSame( sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="foo">bar</a>' ), bp_get_blog_latest_post( array( 'latest_format' => true, ) ) );
    9797
    98         $blogs_template->blog = null;
     98        $blogs_template = null;
    9999    }
    100100
     
    114114        $this->assertSame( '<a href="foo">bar</a>', bp_get_blog_latest_post( array( 'latest_format' => false, ) ) );
    115115
    116         $blogs_template->blog = null;
     116        $blogs_template = null;
    117117    }
    118118
  • trunk/tests/phpunit/testcases/core/class-bp-component.php

    r13422 r14026  
    11<?php
    22
    3 include_once BP_TESTS_DIR . '/assets/bp-rest-api-controllers.php';
    43include_once BP_TESTS_DIR . '/assets/class-bptest-component.php';
    54
     
    98 */
    109class BP_Tests_BP_Component_TestCases extends BP_UnitTestCase {
    11     public function set_up() {
    12         parent::set_up();
    13 
    14         $bp = buddypress();
    15         $bp->unit_test_rest = new stdClass;
    16         $bp->unit_test_rest->controllers = array();
    17     }
    18 
    19     public function remove_controller( $controllers ) {
    20         return array_diff( $controllers, array( 'BP_REST_Members_Endpoint' ) );
    21     }
    22 
    23     public function add_controller( $controllers ) {
    24         return array_merge( $controllers, array( 'Foo_Bar' ) );
    25     }
    26 
    27     public function test_rest_api_init_for_members_component() {
    28         $bp_members = new BP_Members_Component();
    29         $bp         = buddypress();
    30 
    31         $bp_members->rest_api_init();
    32 
    33         $this->assertSame( $bp->unit_test_rest->controllers, array(
    34             'BP_REST_Members_Endpoint',
    35             'BP_REST_Attachments_Member_Avatar_Endpoint',
    36             'BP_REST_Attachments_Member_Cover_Endpoint',
    37         ) );
    38     }
    39 
    40     public function test_rest_api_init_for_members_component_can_remove_controller() {
    41         $bp_members = new BP_Members_Component();
    42         $bp         = buddypress();
    43 
    44         add_filter( 'bp_members_rest_api_controllers', array( $this, 'remove_controller' ) );
    45 
    46         $bp_members->rest_api_init();
    47 
    48         remove_filter( 'bp_members_rest_api_controllers', array( $this, 'remove_controller' ) );
    49 
    50         $this->assertSame( $bp->unit_test_rest->controllers, array(
    51             'BP_REST_Attachments_Member_Avatar_Endpoint',
    52             'BP_REST_Attachments_Member_Cover_Endpoint',
    53         ) );
    54     }
    55 
    56     public function test_rest_api_init_for_members_component_cannot_add_controller() {
    57         $bp_members = new BP_Members_Component();
    58         $bp         = buddypress();
    59 
    60         add_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
    61 
    62         $bp_members->rest_api_init();
    63 
    64         remove_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
    65 
    66         $this->assertSame( $bp->unit_test_rest->controllers, array(
    67             'BP_REST_Members_Endpoint',
    68             'BP_REST_Attachments_Member_Avatar_Endpoint',
    69             'BP_REST_Attachments_Member_Cover_Endpoint',
    70         ) );
    71     }
    7210
    7311    /**
  • trunk/tests/phpunit/testcases/core/invitations.php

    r13990 r14026  
    11<?php
    22
    3 include_once BP_TESTS_DIR . 'assets/invitations-extensions.php';
     3require_once BP_TESTS_DIR . 'assets/invitations-extensions.php';
    44
    55/**
     
    77 * @group invitations
    88 */
    9  class BP_Tests_Invitations extends BP_UnitTestCase {
    10 
    11      /**
    12       * @ticket BP8552
    13       * @group cache
    14       */
    15      public function test_invitation_query_with_ids_cache_results() {
    16          global $wpdb;
    17 
    18          $u1 = self::factory()->user->create();
    19          $u2 = self::factory()->user->create();
    20          $u3 = self::factory()->user->create();
    21 
    22          $invites_class = new BPTest_Invitation_Manager_Extension();
    23 
    24          // Create a couple of invitations.
    25          $invite_args = array(
    26              'user_id'           => $u3,
    27              'inviter_id'       => $u1,
    28              'item_id'           => 1,
    29              'send_invite'      => 'sent',
    30          );
    31 
    32          $invites_class->add_invitation( $invite_args );
    33 
    34          $invite_args['inviter_id'] = $u2;
    35 
    36          $invites_class->add_invitation( $invite_args );
    37 
    38          $wpdb->num_queries = 0;
    39 
    40          $first_query = BP_Invitation::get(
    41              array(
    42                  'cache_results' => true,
    43                  'fields'        => 'ids',
    44              )
    45          );
    46 
    47          $queries_before = get_num_queries();
    48 
    49          $second_query = BP_Invitation::get(
    50              array(
    51                  'cache_results' => false,
    52                  'fields'        => 'ids',
    53              )
    54          );
    55 
    56          $queries_after = get_num_queries();
    57 
    58          $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
    59          $this->assertSame( 2, $queries_after, 'Assert that the uncached query was run' );
    60          $this->assertSameSets( $first_query, $second_query, 'Results of the query are expected to match.' );
    61      }
    62 
    63      /**
    64       * @ticket BP8552
    65       * @group cache
    66       */
    67      public function test_invitation_query_with_all_cache_results() {
    68          global $wpdb;
    69 
    70          $u1 = self::factory()->user->create();
    71          $u2 = self::factory()->user->create();
    72          $u3 = self::factory()->user->create();
    73 
    74          $invites_class = new BPTest_Invitation_Manager_Extension();
    75 
    76          // Create a couple of invitations.
    77          $invite_args = array(
    78              'user_id'     => $u3,
    79              'inviter_id'  => $u1,
    80              'item_id'     => 1,
    81              'send_invite' => 'sent',
    82          );
    83 
    84          $invites_class->add_invitation( $invite_args );
    85 
    86          $invite_args['inviter_id'] = $u2;
    87 
    88          $invites_class->add_invitation( $invite_args );
    89 
    90          $wpdb->num_queries = 0;
    91 
    92          $first_query = BP_Invitation::get(
    93              array( 'cache_results' => true )
    94          );
    95 
    96          $queries_before = get_num_queries();
    97 
    98          $second_query = BP_Invitation::get(
    99              array( 'cache_results' => false )
    100          );
    101 
    102          $queries_after = get_num_queries();
    103 
    104          $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
    105          $this->assertSame( 3, $queries_after, 'Assert that the uncached query was run' );
    106          $this->assertEquals( $first_query, $second_query, 'Results of the query are expected to match.' );
    107      }
     9class BP_Tests_Invitations extends BP_UnitTestCase {
     10
     11    /**
     12     * @ticket BP8552
     13     * @group cache
     14     */
     15    public function test_invitation_query_with_ids_cache_results() {
     16        global $wpdb;
     17
     18        $u1 = self::factory()->user->create();
     19        $u2 = self::factory()->user->create();
     20        $u3 = self::factory()->user->create();
     21
     22        $invites_class = new BPTest_Invitation_Manager_Extension();
     23
     24        // Create a couple of invitations.
     25        $invite_args = array(
     26            'user_id'     => $u3,
     27            'inviter_id'  => $u1,
     28            'item_id'     => 1,
     29            'send_invite' => 'sent',
     30        );
     31
     32        $invites_class->add_invitation( $invite_args );
     33
     34        $invite_args['inviter_id'] = $u2;
     35
     36        $invites_class->add_invitation( $invite_args );
     37
     38        $wpdb->num_queries = 0;
     39
     40        $first_query = BP_Invitation::get(
     41            array(
     42                'cache_results' => true,
     43                'fields'        => 'ids',
     44            )
     45        );
     46
     47        $queries_before = get_num_queries();
     48
     49        $second_query = BP_Invitation::get(
     50            array(
     51                'cache_results' => false,
     52                'fields'        => 'ids',
     53            )
     54        );
     55
     56        $queries_after = get_num_queries();
     57
     58        $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
     59        $this->assertSame( 2, $queries_after, 'Assert that the uncached query was run' );
     60        $this->assertSameSets( $first_query, $second_query, 'Results of the query are expected to match.' );
     61    }
     62
     63    /**
     64     * @ticket BP8552
     65     * @group cache
     66     */
     67    public function test_invitation_query_with_all_cache_results() {
     68        global $wpdb;
     69
     70        $u1 = self::factory()->user->create();
     71        $u2 = self::factory()->user->create();
     72        $u3 = self::factory()->user->create();
     73
     74        $invites_class = new BPTest_Invitation_Manager_Extension();
     75
     76        // Create a couple of invitations.
     77        $invite_args = array(
     78            'user_id'     => $u3,
     79            'inviter_id'  => $u1,
     80            'item_id'     => 1,
     81            'send_invite' => 'sent',
     82        );
     83
     84        $invites_class->add_invitation( $invite_args );
     85
     86        $invite_args['inviter_id'] = $u2;
     87
     88        $invites_class->add_invitation( $invite_args );
     89
     90        $wpdb->num_queries = 0;
     91
     92        $first_query = BP_Invitation::get(
     93            array( 'cache_results' => true )
     94        );
     95
     96        $queries_before = get_num_queries();
     97
     98        $second_query = BP_Invitation::get(
     99            array( 'cache_results' => false )
     100        );
     101
     102        $queries_after = get_num_queries();
     103
     104        $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
     105        $this->assertSame( 3, $queries_after, 'Assert that the uncached query was run' );
     106        $this->assertEquals( $first_query, $second_query, 'Results of the query are expected to match.' );
     107    }
    108108
    109109    public function test_bp_invitations_add_invitation_vanilla() {
     
    118118
    119119        // Create a couple of invitations.
    120         $invite_args = array(
    121             'user_id'           => $u3,
    122             'inviter_id'        => $u1,
    123             'item_id'           => 1,
    124             'send_invite'       => 'sent',
    125         );
    126         $i1 = $invites_class->add_invitation( $invite_args );
     120        $invite_args               = array(
     121            'user_id'     => $u3,
     122            'inviter_id'  => $u1,
     123            'item_id'     => 1,
     124            'send_invite' => 'sent',
     125        );
     126        $i1                        = $invites_class->add_invitation( $invite_args );
    127127        $invite_args['inviter_id'] = $u2;
    128         $i2 = $invites_class->add_invitation( $invite_args );
    129 
    130         $get_invites = array(
    131             'user_id'        => $u3,
    132             'fields'         => 'ids',
    133         );
    134         $invites = $invites_class->get_invitations( $get_invites );
     128        $i2                        = $invites_class->add_invitation( $invite_args );
     129
     130        $get_invites = array(
     131            'user_id' => $u3,
     132            'fields'  => 'ids',
     133        );
     134        $invites     = $invites_class->get_invitations( $get_invites );
    135135        $this->assertEqualSets( array( $i1, $i2 ), $invites );
    136136
     
    149149        // Create an invitation.
    150150        $invite_args = array(
    151             'user_id'           => $u2,
    152             'inviter_id'        => $u1,
    153             'item_id'           => 1,
    154             'send_invite'       => 'sent',
    155         );
    156         $i1 = $invites_class->add_invitation( $invite_args );
     151            'user_id'     => $u2,
     152            'inviter_id'  => $u1,
     153            'item_id'     => 1,
     154            'send_invite' => 'sent',
     155        );
     156        $i1          = $invites_class->add_invitation( $invite_args );
    157157        // Attempt to create a duplicate. Should return existing invite.
    158158        $i2 = $invites_class->add_invitation( $invite_args );
     
    168168        $u2 = self::factory()->user->create();
    169169        $u3 = self::factory()->user->create();
    170         self::set_current_user( $u1 );
    171 
    172         $invites_class = new BPTest_Invitation_Manager_Extension();
    173 
    174         // Create an invitation.
    175         $invite_args = array(
    176             'user_id'           => $u3,
    177             'inviter_id'        => $u1,
    178             'item_id'           => 1,
    179             'send_invite'       => 'sent',
    180         );
    181         $i1 = $invites_class->add_invitation( $invite_args );
     170
     171        self::set_current_user( $u1 );
     172
     173        $invites_class = new BPTest_Invitation_Manager_Extension();
     174
     175        // Create an invitation.
     176        $i1 = $invites_class->add_invitation(
     177            array(
     178                'user_id'     => $u3,
     179                'inviter_id'  => $u1,
     180                'item_id'     => 1,
     181                'send_invite' => 'sent',
     182            )
     183        );
     184
     185        $this->assertIsInt( $i1, 'Invitation ID is not an integer.' );
     186
     187        // Create a request.
     188        $invites_class->add_request(
     189            array(
     190                'user_id' => $u3,
     191                'item_id' => 1,
     192            )
     193        );
     194
     195        $get_invites = array(
     196            'user_id'  => $u3,
     197            'accepted' => 'accepted',
     198        );
     199
     200        $invites    = $invites_class->get_invitations( $get_invites );
     201        $invite_ids = wp_list_pluck( $invites, 'id' );
     202
     203        $this->assertNotEmpty( $invite_ids );
     204        $this->assertEqualSets( array( $i1 ), $invite_ids );
     205
     206        self::set_current_user( $old_current_user );
     207    }
     208
     209    public function test_bp_invitations_add_invitation_unsent_invite_plus_request_should_not_accept() {
     210        $old_current_user = get_current_user_id();
     211
     212        $u1 = self::factory()->user->create();
     213        $u2 = self::factory()->user->create();
     214        $u3 = self::factory()->user->create();
     215        self::set_current_user( $u1 );
     216
     217        $invites_class = new BPTest_Invitation_Manager_Extension();
     218
     219        // Create an invitation.
     220        $invite_args = array(
     221            'user_id'     => $u3,
     222            'inviter_id'  => $u1,
     223            'item_id'     => 1,
     224            'send_invite' => 0,
     225        );
     226        $i1          = $invites_class->add_invitation( $invite_args );
    182227
    183228        // Create a request.
    184229        $request_args = array(
    185             'user_id'           => $u3,
    186             'item_id'           => 1,
    187         );
    188         $r1 = $invites_class->add_request( $request_args );
    189 
    190         $get_invites = array(
    191             'user_id'          => $u3,
    192             'accepted'         => 'accepted'
    193         );
    194         $invites = $invites_class->get_invitations( $get_invites );
    195         $this->assertEqualSets( array( $i1 ), wp_list_pluck( $invites, 'id' ) );
    196 
    197         self::set_current_user( $old_current_user );
    198     }
    199 
    200     public function test_bp_invitations_add_invitation_unsent_invite_plus_request_should_not_accept() {
    201         $old_current_user = get_current_user_id();
    202 
    203         $u1 = self::factory()->user->create();
    204         $u2 = self::factory()->user->create();
    205         $u3 = self::factory()->user->create();
    206         self::set_current_user( $u1 );
    207 
    208         $invites_class = new BPTest_Invitation_Manager_Extension();
    209 
    210         // Create an invitation.
    211         $invite_args = array(
    212             'user_id'           => $u3,
    213             'inviter_id'        => $u1,
    214             'item_id'           => 1,
    215             'send_invite'       => 0,
    216         );
    217         $i1 = $invites_class->add_invitation( $invite_args );
     230            'user_id' => $u3,
     231            'item_id' => 1,
     232        );
     233        $r1           = $invites_class->add_request( $request_args );
     234
     235        $get_invites = array(
     236            'user_id'  => $u3,
     237            'accepted' => 'accepted',
     238        );
     239        $invites     = $invites_class->get_invitations( $get_invites );
     240        $this->assertEqualSets( array(), wp_list_pluck( $invites, 'id' ) );
     241
     242        self::set_current_user( $old_current_user );
     243    }
     244
     245    public function test_bp_invitations_add_invitation_unsent_invite_plus_request_then_send_invite_should_accept() {
     246        $old_current_user = get_current_user_id();
     247
     248        $u1 = self::factory()->user->create();
     249        $u2 = self::factory()->user->create();
     250        $u3 = self::factory()->user->create();
     251        self::set_current_user( $u1 );
     252
     253        $invites_class = new BPTest_Invitation_Manager_Extension();
     254
     255        // Create an invitation.
     256        $invite_args = array(
     257            'user_id'     => $u3,
     258            'inviter_id'  => $u1,
     259            'item_id'     => 1,
     260            'send_invite' => 0,
     261        );
     262        $i1          = $invites_class->add_invitation( $invite_args );
    218263
    219264        // Create a request.
    220265        $request_args = array(
    221             'user_id'           => $u3,
    222             'item_id'           => 1,
    223         );
    224         $r1 = $invites_class->add_request( $request_args );
    225 
    226         $get_invites = array(
    227             'user_id'          => $u3,
    228             'accepted'         => 'accepted'
    229         );
    230         $invites = $invites_class->get_invitations( $get_invites );
    231         $this->assertEqualSets( array(), wp_list_pluck( $invites, 'id' ) );
    232 
    233         self::set_current_user( $old_current_user );
    234     }
    235 
    236     public function test_bp_invitations_add_invitation_unsent_invite_plus_request_then_send_invite_should_accept() {
    237         $old_current_user = get_current_user_id();
    238 
    239         $u1 = self::factory()->user->create();
    240         $u2 = self::factory()->user->create();
    241         $u3 = self::factory()->user->create();
    242         self::set_current_user( $u1 );
    243 
    244         $invites_class = new BPTest_Invitation_Manager_Extension();
    245 
    246         // Create an invitation.
    247         $invite_args = array(
    248             'user_id'           => $u3,
    249             'inviter_id'        => $u1,
    250             'item_id'           => 1,
    251             'send_invite'       => 0,
    252         );
    253         $i1 = $invites_class->add_invitation( $invite_args );
     266            'user_id' => $u3,
     267            'item_id' => 1,
     268        );
     269        $r1           = $invites_class->add_request( $request_args );
     270
     271        $invites_class->send_invitation_by_id( $i1 );
     272
     273        // Check that both the request and invitation are marked 'accepted'.
     274        $get_invites = array(
     275            'user_id'  => $u3,
     276            'type'     => 'all',
     277            'accepted' => 'accepted',
     278            'fields'   => 'ids',
     279        );
     280        $invites     = $invites_class->get_invitations( $get_invites );
     281        $this->assertEqualSets( array( $i1, $r1 ), $invites );
     282
     283        self::set_current_user( $old_current_user );
     284    }
     285
     286    public function test_bp_invitations_add_request_vanilla() {
     287        $old_current_user = get_current_user_id();
     288
     289        $u1 = self::factory()->user->create();
     290        self::set_current_user( $u1 );
     291
     292        $invites_class = new BPTest_Invitation_Manager_Extension();
     293
     294        // Create a couple of requests.
     295        $request_args            = array(
     296            'user_id' => $u1,
     297            'item_id' => 7,
     298        );
     299        $r1                      = $invites_class->add_request( $request_args );
     300        $request_args['item_id'] = 4;
     301        $r2                      = $invites_class->add_request( $request_args );
     302
     303        $get_requests = array(
     304            'user_id' => $u1,
     305            'fields'  => 'ids',
     306        );
     307        $requests     = $invites_class->get_requests( $get_requests );
     308        $this->assertEqualSets( array( $r1, $r2 ), $requests );
     309
     310        self::set_current_user( $old_current_user );
     311    }
     312
     313    public function test_bp_invitations_add_request_avoid_duplicates() {
     314        $old_current_user = get_current_user_id();
     315
     316        $invites_class = new BPTest_Invitation_Manager_Extension();
     317
     318        $u1 = self::factory()->user->create();
     319        self::set_current_user( $u1 );
     320
     321        // Create a couple of requests.
     322        $request_args = array(
     323            'user_id' => $u1,
     324            'item_id' => 7,
     325        );
     326        $r1           = $invites_class->add_request( $request_args );
     327        // Attempt to create a duplicate.
     328        $this->assertFalse( $invites_class->add_request( $request_args ) );
     329
     330        self::set_current_user( $old_current_user );
     331    }
     332
     333    public function test_bp_invitations_add_request_request_plus_sent_invite_should_accept() {
     334        $old_current_user = get_current_user_id();
     335
     336        $u1 = self::factory()->user->create();
     337        $u2 = self::factory()->user->create();
     338        self::set_current_user( $u1 );
     339
     340        $invites_class = new BPTest_Invitation_Manager_Extension();
    254341
    255342        // Create a request.
    256343        $request_args = array(
    257             'user_id'           => $u3,
    258             'item_id'           => 1,
    259         );
    260         $r1 = $invites_class->add_request( $request_args );
    261 
    262         $invites_class->send_invitation_by_id( $i1 );
     344            'user_id' => $u2,
     345            'item_id' => 1,
     346        );
     347        $r1           = $invites_class->add_request( $request_args );
     348
     349        // Create an invitation.
     350        $invite_args = array(
     351            'user_id'     => $u2,
     352            'inviter_id'  => $u1,
     353            'item_id'     => 1,
     354            'send_invite' => 1,
     355        );
     356        $i1          = $invites_class->add_invitation( $invite_args );
    263357
    264358        // Check that both the request and invitation are marked 'accepted'.
    265359        $get_invites = array(
    266             'user_id'          => $u3,
    267             'type'             => 'all',
    268             'accepted'         => 'accepted',
    269             'fields'           => 'ids'
    270         );
    271         $invites = $invites_class->get_invitations( $get_invites );
    272         $this->assertEqualSets( array( $i1, $r1 ), $invites );
    273 
    274         self::set_current_user( $old_current_user );
    275     }
    276 
    277     public function test_bp_invitations_add_request_vanilla() {
    278         $old_current_user = get_current_user_id();
    279 
    280         $u1 = self::factory()->user->create();
    281         self::set_current_user( $u1 );
    282 
    283         $invites_class = new BPTest_Invitation_Manager_Extension();
    284 
    285         // Create a couple of requests.
    286         $request_args = array(
    287             'user_id'           => $u1,
    288             'item_id'           => 7,
    289         );
    290         $r1 = $invites_class->add_request( $request_args );
    291         $request_args['item_id'] = 4;
    292         $r2 = $invites_class->add_request( $request_args );
    293 
    294         $get_requests = array(
    295             'user_id'           => $u1,
    296             'fields'            => 'ids'
    297         );
    298         $requests = $invites_class->get_requests( $get_requests );
    299         $this->assertEqualSets( array( $r1, $r2 ), $requests );
    300 
    301         self::set_current_user( $old_current_user );
    302     }
    303 
    304     public function test_bp_invitations_add_request_avoid_duplicates() {
    305         $old_current_user = get_current_user_id();
    306 
    307         $invites_class = new BPTest_Invitation_Manager_Extension();
    308 
    309         $u1 = self::factory()->user->create();
    310         self::set_current_user( $u1 );
    311 
    312         // Create a couple of requests.
    313         $request_args = array(
    314             'user_id'           => $u1,
    315             'item_id'           => 7,
    316         );
    317         $r1 = $invites_class->add_request( $request_args );
    318         // Attempt to create a duplicate.
    319         $this->assertFalse( $invites_class->add_request( $request_args ) );
    320 
    321         self::set_current_user( $old_current_user );
    322     }
    323 
    324     public function test_bp_invitations_add_request_request_plus_sent_invite_should_accept() {
    325         $old_current_user = get_current_user_id();
    326 
    327         $u1 = self::factory()->user->create();
    328         $u2 = self::factory()->user->create();
    329         self::set_current_user( $u1 );
    330 
    331         $invites_class = new BPTest_Invitation_Manager_Extension();
    332 
    333         // Create a request.
    334         $request_args = array(
    335             'user_id'           => $u2,
    336             'item_id'           => 1,
    337         );
    338         $r1 = $invites_class->add_request( $request_args );
    339 
    340         // Create an invitation.
    341         $invite_args = array(
    342             'user_id'           => $u2,
    343             'inviter_id'        => $u1,
    344             'item_id'           => 1,
    345             'send_invite'       => 1,
    346         );
    347         $i1 = $invites_class->add_invitation( $invite_args );
    348 
    349         // Check that both the request and invitation are marked 'accepted'.
    350         $get_invites = array(
    351             'user_id'          => $u2,
    352             'type'             => 'all',
    353             'accepted'         => 'accepted',
    354             'fields'           => 'ids'
    355         );
    356         $invites = $invites_class->get_invitations( $get_invites );
     360            'user_id'  => $u2,
     361            'type'     => 'all',
     362            'accepted' => 'accepted',
     363            'fields'   => 'ids',
     364        );
     365        $invites     = $invites_class->get_invitations( $get_invites );
    357366        $this->assertEqualSets( array( $r1, $i1 ), $invites );
    358367
     
    371380        // Create an invitation.
    372381        $invite_args = array(
    373             'user_id'           => $u2,
    374             'inviter_id'        => $u1,
    375             'item_id'           => 1,
    376         );
    377         $i1 = $invites_class->add_invitation( $invite_args );
     382            'user_id'    => $u2,
     383            'inviter_id' => $u1,
     384            'item_id'    => 1,
     385        );
     386        $i1          = $invites_class->add_invitation( $invite_args );
    378387
    379388        $invite = new BP_Invitation( $i1 );
     
    404413            'content'    => 'Sometimes, the mystery is enough.',
    405414        );
    406         $i1 = $invites_class->add_invitation( $i1_args );
     415        $i1      = $invites_class->add_invitation( $i1_args );
    407416        $invites_class->send_invitation_by_id( $i1 );
    408417
     
    413422            'item_id'       => 1,
    414423        );
    415         $i2 = $invites_class->add_invitation( $i2_args );
     424        $i2      = $invites_class->add_invitation( $i2_args );
    416425        $invites_class->send_invitation_by_id( $i2 );
    417426
     
    420429            'fields'       => 'ids',
    421430        );
    422         $invites = $invites_class->get_invitations( $get_invites );
     431        $invites     = $invites_class->get_invitations( $get_invites );
    423432        $this->assertEqualSets( array( $i1 ), $invites );
    424433
     
    427436            'fields'       => 'ids',
    428437        );
    429         $invites = $invites_class->get_invitations( $get_invites );
     438        $invites     = $invites_class->get_invitations( $get_invites );
    430439        $this->assertEqualSets( array( $i2 ), $invites );
    431440
     
    443452        $time = gmdate( 'Y-m-d H:i:s', time() - 100 );
    444453        $args = array(
    445             'user_id'           => $u1,
    446             'item_id'           => 7,
    447             'date_modified'     => $time,
    448         );
    449         $r1 = $invites_class->add_request( $args );
     454            'user_id'       => $u1,
     455            'item_id'       => 7,
     456            'date_modified' => $time,
     457        );
     458        $r1   = $invites_class->add_request( $args );
    450459
    451460        $req = new BP_Invitation( $r1 );
     
    463472
    464473        $invites_class = new BPTest_Invitation_Manager_Extension();
    465         $time = gmdate( 'Y-m-d H:i:s', time() - 100 );
    466 
    467         // Create an invitation.
    468         $invite_args = array(
    469             'user_id'           => $u2,
    470             'inviter_id'        => $u1,
    471             'item_id'           => 1,
    472             'send_invite'       => 1,
    473             'date_modified'     => $time,
    474         );
    475         $i1 = $invites_class->add_invitation( $invite_args );
     474        $time          = gmdate( 'Y-m-d H:i:s', time() - 100 );
     475
     476        // Create an invitation.
     477        $invite_args = array(
     478            'user_id'       => $u2,
     479            'inviter_id'    => $u1,
     480            'item_id'       => 1,
     481            'send_invite'   => 1,
     482            'date_modified' => $time,
     483        );
     484        $i1          = $invites_class->add_invitation( $invite_args );
    476485
    477486        $inv = new BP_Invitation( $i1 );
     
    497506            'item_id'    => 6,
    498507        );
    499         $i1 = $invites_class->add_invitation( $i1_args );
     508        $i1      = $invites_class->add_invitation( $i1_args );
    500509        $invites_class->send_invitation_by_id( $i1 );
    501510
     
    505514            'item_id'    => 4,
    506515        );
    507         $i2 = $invites_class->add_invitation( $i2_args );
     516        $i2      = $invites_class->add_invitation( $i2_args );
    508517        $invites_class->send_invitation_by_id( $i2 );
    509518
     
    513522            'item_id'    => 8,
    514523        );
    515         $i3 = $invites_class->add_invitation( $i3_args );
     524        $i3      = $invites_class->add_invitation( $i3_args );
    516525        $invites_class->send_invitation_by_id( $i3 );
    517526
     
    521530            'fields'     => 'ids',
    522531        );
    523         $invites = $invites_class->get_invitations( $get_invites );
     532        $invites     = $invites_class->get_invitations( $get_invites );
    524533        $this->assertEquals( array( $i2, $i1, $i3 ), $invites );
    525534
    526535        $get_invites['sort_order'] = 'DESC';
    527         $invites = $invites_class->get_invitations( $get_invites );
     536        $invites                   = $invites_class->get_invitations( $get_invites );
    528537        $this->assertEquals( array( $i3, $i1, $i2 ), $invites );
    529538
  • trunk/tests/phpunit/testcases/groups/activity.php

    r13980 r14026  
    1515        $u = self::factory()->user->create();
    1616        $g = self::factory()->group->create();
    17         $a = self::factory()->activity->create( array(
    18             'component' => buddypress()->groups->id,
    19             'type' => 'created_group',
    20             'user_id' => $u,
    21             'item_id' => $g,
    22         ) );
     17        $a = self::factory()->activity->create(
     18            array(
     19                'component' => buddypress()->groups->id,
     20                'type'      => 'created_group',
     21                'user_id'   => $u,
     22                'item_id'   => $g,
     23            )
     24        );
    2325
    2426        $a_obj = new BP_Activity_Activity( $a );
    2527        $g_obj = groups_get_group( $g );
    2628
    27         $expected = sprintf( __( '%s created the group %s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' );
     29        $expected = sprintf( __( '%1$s created the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' );
    2830
    2931        $this->assertSame( $expected, $a_obj->action );
     
    3739        $u = self::factory()->user->create();
    3840        $g = self::factory()->group->create();
    39         $a = self::factory()->activity->create( array(
    40             'component' => buddypress()->groups->id,
    41             'type' => 'joined_group',
    42             'user_id' => $u,
    43             'item_id' => $g,
    44         ) );
     41        $a = self::factory()->activity->create(
     42            array(
     43                'component' => buddypress()->groups->id,
     44                'type'      => 'joined_group',
     45                'user_id'   => $u,
     46                'item_id'   => $g,
     47            )
     48        );
    4549
    4650        $a_obj = new BP_Activity_Activity( $a );
    4751        $g_obj = groups_get_group( $g );
    4852
    49         $expected = sprintf( __( '%s joined the group %s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' );
     53        $expected = sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' );
    5054
    5155        $this->assertSame( $expected, $a_obj->action );
     
    5862    public function test_bp_groups_format_activity_action_group_details_updated_with_no_change() {
    5963        $group = self::factory()->group->create_and_get();
    60         groups_edit_base_group_details( array(
     64        groups_edit_base_group_details(
     65            array(
    6166                'group_id'       => $group->id,
    6267                'name'           => $group->name,
     
    6469                'description'    => $group->description,
    6570                'notify_members' => true,
    66         ) );
    67 
    68         $a = bp_activity_get( array(
    69             'component' => buddypress()->groups->id,
    70             'action' => 'group_details_updated',
    71             'item_id' => $group->id,
    72         ) );
     71            )
     72        );
     73
     74        $a = bp_activity_get(
     75            array(
     76                'component' => buddypress()->groups->id,
     77                'action'    => 'group_details_updated',
     78                'item_id'   => $group->id,
     79            )
     80        );
    7381
    7482        $this->assertTrue( empty( $a['activities'] ) );
     
    8189    public function test_bp_groups_format_activity_action_group_details_updated_with_notify_members_false() {
    8290        $group = self::factory()->group->create_and_get();
    83         groups_edit_base_group_details( array(
    84             'group_id'       => $group->id,
    85             'name'           => 'Foo',
    86             'slug'           => $group->slug,
    87             'description'    => $group->description,
    88             'notify_members' => false,
    89         ) );
    90 
    91         $a = bp_activity_get( array(
    92             'component' => buddypress()->groups->id,
    93             'action' => 'group_details_updated',
    94             'item_id' => $group->id,
    95         ) );
     91        groups_edit_base_group_details(
     92            array(
     93                'group_id'       => $group->id,
     94                'name'           => 'Foo',
     95                'slug'           => $group->slug,
     96                'description'    => $group->description,
     97                'notify_members' => false,
     98            )
     99        );
     100
     101        $a = bp_activity_get(
     102            array(
     103                'component' => buddypress()->groups->id,
     104                'action'    => 'group_details_updated',
     105                'item_id'   => $group->id,
     106            )
     107        );
    96108
    97109        $this->assertTrue( empty( $a['activities'] ) );
     
    104116    public function test_bp_groups_format_activity_action_group_details_updated_with_updated_name() {
    105117        $old_user = get_current_user_id();
    106         $u = self::factory()->user->create();
     118        $u        = self::factory()->user->create();
    107119        self::set_current_user( $u );
    108120
    109121        $group = self::factory()->group->create_and_get();
    110         groups_edit_base_group_details( array(
    111             'group_id'       => $group->id,
    112             'name'           => 'Foo',
    113             'slug'           => $group->slug,
    114             'description'    => $group->description,
    115             'notify_members' => true,
    116         ) );
    117 
    118         $a = bp_activity_get( array(
    119             'component' => buddypress()->groups->id,
    120             'action' => 'group_details_updated',
    121             'item_id' => $group->id,
    122         ) );
     122        groups_edit_base_group_details(
     123            array(
     124                'group_id'       => $group->id,
     125                'name'           => 'Foo',
     126                'slug'           => $group->slug,
     127                'description'    => $group->description,
     128                'notify_members' => true,
     129            )
     130        );
     131
     132        $a = bp_activity_get(
     133            array(
     134                'component' => buddypress()->groups->id,
     135                'action'    => 'group_details_updated',
     136                'item_id'   => $group->id,
     137            )
     138        );
    123139
    124140        $this->assertNotEmpty( $a['activities'] );
    125141
    126         $expected = sprintf( esc_html__( '%s changed the name of the group %s from "%s" to "%s"', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>', $group->name, 'Foo' );
     142        $expected = sprintf( esc_html__( '%1$s changed the name of the group %2$s from "%3$s" to "%4$s"', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>', $group->name, 'Foo' );
    127143        $this->assertSame( $expected, $a['activities'][0]->action );
    128144
     
    136152    public function test_bp_groups_format_activity_action_group_details_updated_with_updated_description() {
    137153        $old_user = get_current_user_id();
    138         $u = self::factory()->user->create();
     154        $u        = self::factory()->user->create();
    139155        self::set_current_user( $u );
    140156
    141157        $group = self::factory()->group->create_and_get();
    142         groups_edit_base_group_details( array(
    143             'group_id'       => $group->id,
    144             'name'           => $group->name,
    145             'slug'           => $group->slug,
    146             'description'    => 'Bar',
    147             'notify_members' => true,
    148         ) );
    149 
    150         $a = bp_activity_get( array(
    151             'component' => buddypress()->groups->id,
    152             'action' => 'group_details_updated',
    153             'item_id' => $group->id,
    154         ) );
     158        groups_edit_base_group_details(
     159            array(
     160                'group_id'       => $group->id,
     161                'name'           => $group->name,
     162                'slug'           => $group->slug,
     163                'description'    => 'Bar',
     164                'notify_members' => true,
     165            )
     166        );
     167
     168        $a = bp_activity_get(
     169            array(
     170                'component' => buddypress()->groups->id,
     171                'action'    => 'group_details_updated',
     172                'item_id'   => $group->id,
     173            )
     174        );
    155175
    156176        $this->assertNotEmpty( $a['activities'] );
    157177
    158         $expected = sprintf( esc_html__( '%s changed the description of the group %s from "%s" to "%s"', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">' . $group->name . '</a>', $group->description, 'Bar' );
     178        $expected = sprintf( esc_html__( '%1$s changed the description of the group %2$s from "%3$s" to "%4$s"', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">' . $group->name . '</a>', $group->description, 'Bar' );
    159179        $this->assertSame( $expected, $a['activities'][0]->action );
    160180
     
    168188    public function test_bp_groups_format_activity_action_group_details_updated_with_updated_slug() {
    169189        $old_user = get_current_user_id();
    170         $u = self::factory()->user->create();
     190        $u        = self::factory()->user->create();
    171191        self::set_current_user( $u );
    172192
    173193        $group = self::factory()->group->create_and_get();
    174         groups_edit_base_group_details( array(
    175             'group_id'       => $group->id,
    176             'name'           => $group->name,
    177             'slug'           => 'flaxen',
    178             'description'    => $group->description,
    179             'notify_members' => true,
    180         ) );
     194        groups_edit_base_group_details(
     195            array(
     196                'group_id'       => $group->id,
     197                'name'           => $group->name,
     198                'slug'           => 'flaxen',
     199                'description'    => $group->description,
     200                'notify_members' => true,
     201            )
     202        );
    181203        $new_group_details = groups_get_group( $group->id );
    182204
    183         $a = bp_activity_get( array(
    184             'component' => buddypress()->groups->id,
    185             'action' => 'group_details_updated',
    186             'item_id' => $group->id,
    187         ) );
     205        $a = bp_activity_get(
     206            array(
     207                'component' => buddypress()->groups->id,
     208                'action'    => 'group_details_updated',
     209                'item_id'   => $group->id,
     210            )
     211        );
    188212
    189213        $this->assertNotEmpty( $a['activities'] );
    190214
    191         $expected = sprintf( __( '%s changed the permalink of the group %s.', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $new_group_details ) ) . '">' . $group->name . '</a>' );
     215        $expected = sprintf( __( '%1$s changed the permalink of the group %2$s.', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $new_group_details ) ) . '">' . $group->name . '</a>' );
    192216        $this->assertSame( $expected, $a['activities'][0]->action );
    193217
     
    201225    public function test_bp_groups_format_activity_action_group_details_updated_with_updated_name_and_description() {
    202226        $old_user = get_current_user_id();
    203         $u = self::factory()->user->create();
     227        $u        = self::factory()->user->create();
    204228        self::set_current_user( $u );
    205229
    206230        $group = self::factory()->group->create_and_get();
    207         groups_edit_base_group_details( array(
    208             'group_id'       => $group->id,
    209             'name'           => 'Foo',
    210             'slug'           => $group->slug,
    211             'description'    => 'Bar',
    212             'notify_members' => true,
    213         ) );
    214 
    215         $a = bp_activity_get( array(
    216             'component' => buddypress()->groups->id,
    217             'action' => 'group_details_updated',
    218             'item_id' => $group->id,
    219         ) );
     231        groups_edit_base_group_details(
     232            array(
     233                'group_id'       => $group->id,
     234                'name'           => 'Foo',
     235                'slug'           => $group->slug,
     236                'description'    => 'Bar',
     237                'notify_members' => true,
     238            )
     239        );
     240
     241        $a = bp_activity_get(
     242            array(
     243                'component' => buddypress()->groups->id,
     244                'action'    => 'group_details_updated',
     245                'item_id'   => $group->id,
     246            )
     247        );
    220248
    221249        $this->assertNotEmpty( $a['activities'] );
    222250
    223         $expected = sprintf( __( '%s changed the name and description of the group %s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>' );
     251        $expected = sprintf( __( '%1$s changed the name and description of the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>' );
    224252        $this->assertSame( $expected, $a['activities'][0]->action );
    225253
     
    234262        $u = self::factory()->user->create();
    235263        $g = self::factory()->group->create();
    236         $a = self::factory()->activity->create( array(
    237             'component' => buddypress()->groups->id,
    238             'type' => 'activity_update',
    239             'user_id' => $u,
    240             'item_id' => $g,
    241         ) );
     264        $a = self::factory()->activity->create(
     265            array(
     266                'component' => buddypress()->groups->id,
     267                'type'      => 'activity_update',
     268                'user_id'   => $u,
     269                'item_id'   => $g,
     270            )
     271        );
    242272
    243273        $a_obj = new BP_Activity_Activity( $a );
    244274        $g_obj = groups_get_group( $g );
    245275
    246         $expected = sprintf( esc_html__( '%1$s posted an update in the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ),  '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . esc_html( $g_obj->name ) . '</a>' );
     276        $expected = sprintf( esc_html__( '%1$s posted an update in the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . esc_html( $g_obj->name ) . '</a>' );
    247277
    248278        $this->assertSame( $expected, $a_obj->action );
     
    296326        );
    297327
    298         $a = groups_post_update( $activity_args );
     328        $a     = groups_post_update( $activity_args );
    299329        $a_obj = new BP_Activity_Activity( $a );
    300330
     
    310340    public function test_groups_activity_can_comment() {
    311341        $old_user = get_current_user_id();
    312         $u1 = self::factory()->user->create();
    313         $u2 = self::factory()->user->create();
     342        $u1       = self::factory()->user->create();
     343        $u2       = self::factory()->user->create();
    314344
    315345        $g = self::factory()->group->create();
     
    318348        groups_join_group( $g, $u1 );
    319349
    320         $a = self::factory()->activity->create( array(
    321             'component' => buddypress()->groups->id,
    322             'type' => 'created_group',
    323             'user_id' => $u1,
    324             'item_id' => $g,
    325         ) );
     350        $a = self::factory()->activity->create(
     351            array(
     352                'component' => buddypress()->groups->id,
     353                'type'      => 'created_group',
     354                'user_id'   => $u1,
     355                'item_id'   => $g,
     356            )
     357        );
    326358
    327359        self::set_current_user( $u1 );
    328360        if ( bp_has_activities( array( 'in' => $a ) ) ) {
    329             while ( bp_activities() ) : bp_the_activity();
     361            while ( bp_activities() ) :
     362                bp_the_activity();
    330363                // User 1 should be able to comment.
    331364                $this->assertTrue( bp_activity_can_comment() );
     
    335368        self::set_current_user( $u2 );
    336369        if ( bp_has_activities( array( 'in' => $a ) ) ) {
    337             while ( bp_activities() ) : bp_the_activity();
     370            while ( bp_activities() ) :
     371                bp_the_activity();
    338372                // User 2 should not be able to comment.
    339373                $this->assertFalse( bp_activity_can_comment() );
     
    345379
    346380    public function groups_post_update_args( $args = array() ) {
    347         $this->groups_post_update_args = array_intersect_key( $args, array(
    348             'content'    => true,
    349             'user_id'    => true,
    350             'item_id'    => true,
    351             'error_type' => true,
    352         ) );
     381        $this->groups_post_update_args = array_intersect_key(
     382            $args,
     383            array(
     384                'content'    => true,
     385                'user_id'    => true,
     386                'item_id'    => true,
     387                'error_type' => true,
     388            )
     389        );
    353390
    354391        return $args;
     
    359396     */
    360397    public function test_user_can_delete_group_activity() {
    361         $u1             = self::factory()->user->create();
    362         $u2             = self::factory()->user->create();
     398        $u1            = self::factory()->user->create();
     399        $u2            = self::factory()->user->create();
    363400        $original_user = bp_loggedin_user_id();
    364401
     
    416453
    417454        // Misc user can't delete activity.
    418         $misc_user = self::factory()->user->create( array( 'role' => 'subscriber' ) );
     455        $misc_user = self::factory()->user->create();
    419456        self::set_current_user( $misc_user );
    420457        $this->assertFalse( bp_activity_user_can_delete( $activity ) );
    421458
    422459        // Misc group member can't delete activity.
    423         $misc_user_2 = self::factory()->user->create( array( 'role' => 'subscriber' ) );
     460        $misc_user_2 = self::factory()->user->create();
    424461        self::add_user_to_group( $misc_user_2, $g );
    425462        self::set_current_user( $misc_user_2 );
     
    427464
    428465        // Group mod can delete activity.
    429         $misc_user_3 = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    430         self::add_user_to_group( $misc_user_3, $g, [ 'is_mod' => true ] );
     466        $misc_user_3 = self::factory()->user->create();
     467        self::add_user_to_group( $misc_user_3, $g, array( 'is_mod' => true ) );
    431468        self::set_current_user( $misc_user_3 );
    432469        $this->assertTrue( bp_activity_user_can_delete( $activity ) );
    433470
    434471        // Group admin can delete activity.
    435         $misc_user_4 = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    436         self::add_user_to_group( $misc_user_4, $g, [ 'is_admin' => true ] );
     472        $misc_user_4 = self::factory()->user->create();
     473        self::add_user_to_group( $misc_user_4, $g, array( 'is_admin' => true ) );
    437474        self::set_current_user( $misc_user_4 );
    438475        $this->assertTrue( bp_activity_user_can_delete( $activity ) );
     
    455492        $a  = self::factory()->activity->create(
    456493            array(
    457                 'user_id'   => $u1,
    458                 'content'   => 'Random Activity content',
     494                'user_id' => $u1,
     495                'content' => 'Random Activity content',
    459496            )
    460497        );
     
    484521
    485522        // Add u2 as Admin of g2.
    486         self::add_user_to_group( $u2, $g, [ 'is_admin' => true ] );
     523        self::add_user_to_group( $u2, $g, array( 'is_admin' => true ) );
    487524
    488525        self::set_current_user( $u2 );
  • trunk/tests/phpunit/testcases/members/class-bp-signup.php

    r13989 r14026  
    44 * @group members
    55 * @group signups
     6 * @group signup
    67 * @group BP_Signup
    78 */
  • trunk/tests/phpunit/testcases/members/functions.php

    r13985 r14026  
    3434        // 1. Admin can delete user account
    3535        $this->set_current_user( $admin_user );
    36         $user1 = self::factory()->user->create( array( 'role' => 'subscriber' ) );
     36        $user1 = self::factory()->user->create();
    3737        bp_core_delete_account( $user1 );
    3838        $maybe_user = new WP_User( $user1 );
     
    5050
    5151        // User cannot delete other's account
    52         $user3 = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    53         $user4 = self::factory()->user->create( array( 'role' => 'subscriber' ) );
     52        $user3 = self::factory()->user->create();
     53        $user4 = self::factory()->user->create();
    5454        $this->set_current_user( $user3 );
    5555        bp_core_delete_account( $user4 );
     
    129129    public function test_bp_members_get_user_url_after_directory_page_update() {
    130130        // Generate user
    131         $user_id = self::factory()->user->create( array( 'role' => 'subscriber' ) );
     131        $user_id = self::factory()->user->create();
    132132        $this->set_permalink_structure( '/%postname%/' );
    133133
  • trunk/tests/phpunit/testcases/testsuite/factory.php

    r11737 r14026  
    33/**
    44 * @group testsuite
     5 * @group factory
    56 */
    6 class BPTests_Testsuite_Factory extends BP_UnitTestCase {
     7class BP_Tests_Testsuite_Factory extends BP_UnitTestCase {
    78    /**
    89     * @ticket BP7234
     
    4445        $u2 = self::factory()->user->create();
    4546
    46         $f = self::factory()->friendship->create_and_get( array(
    47             'initiator_user_id' => $u1,
    48             'friend_user_id' => $u2,
    49         ) );
     47        $f = self::factory()->friendship->create_and_get(
     48            array(
     49                'initiator_user_id' => $u1,
     50                'friend_user_id'    => $u2,
     51            )
     52        );
    5053
    5154        $this->assertSame( $u1, $f->initiator_user_id );
  • trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php

    r13980 r14026  
    1111    public function test_can_delete_save() {
    1212        $group = self::factory()->xprofile_group->create();
    13         $field = self::factory()->xprofile_field->create( array(
    14             'field_group_id' => $group,
    15         ) );
    16 
    17         $f = new BP_XProfile_Field( $field );
     13        $field = self::factory()->xprofile_field->create(
     14            array(
     15                'field_group_id' => $group,
     16            )
     17        );
     18
     19        $f             = new BP_XProfile_Field( $field );
    1820        $f->can_delete = 0;
    1921        $f->save();
     
    3234        $_POST['checkbox_option'] = array(
    3335            1 => 'BuddyPress',
    34             2 => 'WordPress'
     36            2 => 'WordPress',
    3537        );
    3638
    3739        // checkbox field
    38         $f1 = self::factory()->xprofile_field->create( array(
    39             'field_group_id' => $group,
    40             'type' => 'checkbox',
    41             'name' => 'Interests'
    42         ) );
     40        $f1 = self::factory()->xprofile_field->create(
     41            array(
     42                'field_group_id' => $group,
     43                'type'           => 'checkbox',
     44                'name'           => 'Interests',
     45            )
     46        );
    4347
    4448        // textbox field with the same name as our checkbox value
    45         $f2 = self::factory()->xprofile_field->create( array(
    46             'field_group_id' => $group,
    47             'type' => 'textbox',
    48             'name' => 'BuddyPress'
    49         ) );
     49        $f2 = self::factory()->xprofile_field->create(
     50            array(
     51                'field_group_id' => $group,
     52                'type'           => 'textbox',
     53                'name'           => 'BuddyPress',
     54            )
     55        );
    5056
    5157        $this->assertEquals( $f2, xprofile_get_field_id_from_name( 'BuddyPress' ) );
     
    105111            $_POST['required'],
    106112            $_POST['fieldtype'],
    107             $_POST['radio_option' ]
     113            $_POST['radio_option']
    108114        );
    109115    }
     
    113119     */
    114120    public function test_newly_created_field_should_have_field_id_property_set() {
    115         $field = new BP_XProfile_Field();
     121        $field           = new BP_XProfile_Field();
    116122        $field->group_id = 1;
    117         $field->name = 'Foo';
     123        $field->name     = 'Foo';
    118124
    119125        $new_field_id = $field->save();
     
    129135
    130136        $group = self::factory()->xprofile_group->create();
    131         $field = self::factory()->xprofile_field->create( array(
    132             'field_group_id' => $group,
    133         ) );
     137        $field = self::factory()->xprofile_field->create(
     138            array(
     139                'field_group_id' => $group,
     140            )
     141        );
    134142
    135143        bp_xprofile_update_meta( $field, 'field', 'default_visibility', 'loggedin' );
     
    137145        // Initial setup takes just one query.
    138146        $num_queries = $wpdb->num_queries;
    139         $field_obj = new BP_XProfile_Field( $field );
    140         $num_queries++;
     147        $field_obj   = new BP_XProfile_Field( $field );
     148        ++$num_queries;
    141149
    142150        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    144152        // Fetching the default_visibility should cause another query.
    145153        $this->assertSame( 'loggedin', $field_obj->default_visibility );
    146         $num_queries++;
     154        ++$num_queries;
    147155
    148156        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    156164
    157165        $group = self::factory()->xprofile_group->create();
    158         $field = self::factory()->xprofile_field->create( array(
    159             'field_group_id' => $group,
    160         ) );
     166        $field = self::factory()->xprofile_field->create(
     167            array(
     168                'field_group_id' => $group,
     169            )
     170        );
    161171
    162172        bp_xprofile_update_meta( $field, 'field', 'allow_custom_visibility', 'disabled' );
     
    164174        // Initial setup takes just one query.
    165175        $num_queries = $wpdb->num_queries;
    166         $field_obj = new BP_XProfile_Field( $field );
    167         $num_queries++;
     176        $field_obj   = new BP_XProfile_Field( $field );
     177        ++$num_queries;
    168178
    169179        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    171181        // Fetching the allow_custom_visibility should cause another query.
    172182        $this->assertSame( 'disabled', $field_obj->allow_custom_visibility );
    173         $num_queries++;
     183        ++$num_queries;
    174184
    175185        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    190200    public function test_update_position_should_invalidate_cache() {
    191201        $group = self::factory()->xprofile_group->create();
    192         $field = self::factory()->xprofile_field->create( array(
    193             'field_group_id' => $group,
    194         ) );
     202        $field = self::factory()->xprofile_field->create(
     203            array(
     204                'field_group_id' => $group,
     205            )
     206        );
    195207
    196208        // Prime cache.
    197         $fetched_field = xprofile_get_field( $field );
     209        $fetched_field   = xprofile_get_field( $field );
    198210        $new_field_order = 12345;
    199211
     
    210222     */
    211223    public function test_empty_datebox_fields_should_not_return_unix_epoch() {
    212         $user  = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    213         $group = self::factory()->xprofile_group->create();
    214         $field = self::factory()->xprofile_field->create( array(
    215             'field_group_id' => $group,
    216             'type' => 'datebox',
    217         ) );
     224        $user  = self::factory()->user->create();
     225        $group = self::factory()->xprofile_group->create();
     226        $field = self::factory()->xprofile_field->create(
     227            array(
     228                'field_group_id' => $group,
     229                'type'           => 'datebox',
     230            )
     231        );
    218232
    219233        $old_user = get_current_user_id();
    220234        self::set_current_user( $user );
    221235
    222         $value = bp_get_profile_field_data( array( 'user_id' => $user, 'field' => $field ) );
     236        $value = bp_get_profile_field_data(
     237            array(
     238                'user_id' => $user,
     239                'field'   => $field,
     240            )
     241        );
    223242        $this->assertEmpty( $value );
    224243
     
    231250    public function test_delete_field_should_delete_default_field_metadata() {
    232251        $group = self::factory()->xprofile_group->create();
    233         $field = self::factory()->xprofile_field->create( array(
    234             'field_group_id' => $group
    235         ) );
     252        $field = self::factory()->xprofile_field->create(
     253            array(
     254                'field_group_id' => $group,
     255            )
     256        );
    236257
    237258        $field_obj = new BP_XProfile_Field( $field );
     
    247268    public function test_delete_field_should_delete_custom_field_metadata() {
    248269        $group = self::factory()->xprofile_group->create();
    249         $field = self::factory()->xprofile_field->create( array(
    250             'field_group_id' => $group
    251         ) );
     270        $field = self::factory()->xprofile_field->create(
     271            array(
     272                'field_group_id' => $group,
     273            )
     274        );
    252275
    253276        bp_xprofile_update_meta( $field, 'field', 'custom', 'metadata' );
Note: See TracChangeset for help on using the changeset viewer.