Skip to:
Content

BuddyPress.org

Ticket #8151: 8151.2.patch

File 8151.2.patch, 6.2 KB (added by imath, 6 years ago)
  • src/bp-groups/classes/class-bp-groups-component.php

    diff --git src/bp-groups/classes/class-bp-groups-component.php src/bp-groups/classes/class-bp-groups-component.php
    index b53835ea0..609f9c657 100644
    class BP_Groups_Component extends BP_Component { 
    932932         *                           description.
    933933         */
    934934        public function rest_api_init( $controllers = array() ) {
    935                 parent::rest_api_init( array(
     935                $controllers = array(
    936936                        'BP_REST_Groups_Endpoint',
    937937                        'BP_REST_Group_Membership_Endpoint',
    938938                        'BP_REST_Group_Invites_Endpoint',
    939939                        'BP_REST_Group_Membership_Request_Endpoint',
    940                         'BP_REST_Attachments_Group_Avatar_Endpoint',
    941                 ) );
     940                );
     941
     942                // Only Load the Group's Avatar controller if Group Avatar uploads are allowed.
     943                if ( ! bp_disable_group_avatar_uploads() ) {
     944                        $controllers[] = 'BP_REST_Attachments_Group_Avatar_Endpoint';
     945                }
     946
     947                parent::rest_api_init( $controllers );
    942948        }
    943949}
  • src/bp-members/classes/class-bp-members-component.php

    diff --git src/bp-members/classes/class-bp-members-component.php src/bp-members/classes/class-bp-members-component.php
    index a83344feb..73b63348b 100644
    class BP_Members_Component extends BP_Component { 
    473473                         */
    474474                        'BP_REST_Components_Endpoint',
    475475                        'BP_REST_Members_Endpoint',
    476                         'BP_REST_Attachments_Member_Avatar_Endpoint',
    477476                ) );
    478477        }
    479478}
  • src/bp-xprofile/classes/class-bp-xprofile-component.php

    diff --git src/bp-xprofile/classes/class-bp-xprofile-component.php src/bp-xprofile/classes/class-bp-xprofile-component.php
    index b43879d34..e2133287d 100644
    class BP_XProfile_Component extends BP_Component { 
    499499         *                           description.
    500500         */
    501501        public function rest_api_init( $controllers = array() ) {
    502                 parent::rest_api_init( array(
     502                $controllers = array(
    503503                        'BP_REST_XProfile_Fields_Endpoint',
    504504                        'BP_REST_XProfile_Field_Groups_Endpoint',
    505505                        'BP_REST_XProfile_Data_Endpoint',
    506                 ) );
     506                );
     507
     508                // Only Load the Member's Avatar controller if Avatar uploads are allowed.
     509                if ( ! bp_disable_avatar_uploads() ) {
     510                        $controllers[] = 'BP_REST_Attachments_Member_Avatar_Endpoint';
     511                }
     512
     513                parent::rest_api_init( $controllers );
    507514        }
    508515}
  • tests/phpunit/assets/bp-rest-api-controllers.php

    diff --git tests/phpunit/assets/bp-rest-api-controllers.php tests/phpunit/assets/bp-rest-api-controllers.php
    index 66d685065..96760a6cd 100644
    class BP_REST_Mock_Class { 
    1717class BP_REST_Attachments_Member_Avatar_Endpoint extends BP_REST_Mock_Class {
    1818        public function __construct() {
    1919                $this->namespace = bp_rest_namespace() . '/' . bp_rest_version();
    20                 $this->rest_base = 'members';
     20                $this->rest_base = 'xprofile';
    2121        }
    2222
    2323        public function register_routes( $controller = '' ) {
    class BP_REST_Members_Endpoint extends BP_REST_Mock_Class { 
    5252                parent::register_routes( 'BP_REST_Members_Endpoint' );
    5353        }
    5454}
     55
     56/**
     57 * BP xProfiles Data REST Controller's mock.
     58 */
     59class BP_REST_XProfile_Data_Endpoint extends BP_REST_Mock_Class {
     60        public function __construct() {
     61                $this->namespace = bp_rest_namespace() . '/' . bp_rest_version();
     62                $this->rest_base = 'xprofile';
     63        }
     64
     65        public function register_routes( $controller = '' ) {
     66                parent::register_routes( 'BP_REST_XProfile_Data_Endpoint' );
     67        }
     68}
     69
     70/**
     71 * BP xProfiles Field Groups REST Controller's mock.
     72 */
     73class BP_REST_XProfile_Field_Groups_Endpoint extends BP_REST_Mock_Class {
     74        public function __construct() {
     75                $this->namespace = bp_rest_namespace() . '/' . bp_rest_version();
     76                $this->rest_base = 'xprofile/groups';
     77        }
     78
     79        public function register_routes( $controller = '' ) {
     80                parent::register_routes( 'BP_REST_XProfile_Field_Groups_Endpoint' );
     81        }
     82}
     83
     84/**
     85 * BP xProfiles Fields REST Controller's mock.
     86 */
     87class BP_REST_XProfile_Fields_Endpoint extends BP_REST_Mock_Class {
     88        public function __construct() {
     89                $this->namespace = bp_rest_namespace() . '/' . bp_rest_version();
     90                $this->rest_base = 'xprofile/fields';
     91        }
     92
     93        public function register_routes( $controller = '' ) {
     94                parent::register_routes( 'BP_REST_XProfile_Fields_Endpoint' );
     95        }
     96}
  • tests/phpunit/testcases/core/class-bp-component.php

    diff --git tests/phpunit/testcases/core/class-bp-component.php tests/phpunit/testcases/core/class-bp-component.php
    index bb8ad1b90..3b10613e4 100644
    class BP_Tests_BP_Component_TestCases extends BP_UnitTestCase { 
    3232                $this->assertSame( $bp->unit_test_rest->controllers, array(
    3333                        'BP_REST_Components_Endpoint',
    3434                        'BP_REST_Members_Endpoint',
    35                         'BP_REST_Attachments_Member_Avatar_Endpoint',
    3635                ) );
    3736        }
    3837
    class BP_Tests_BP_Component_TestCases extends BP_UnitTestCase { 
    4847
    4948                $this->assertSame( $bp->unit_test_rest->controllers, array(
    5049                        'BP_REST_Components_Endpoint',
    51                         'BP_REST_Attachments_Member_Avatar_Endpoint',
    5250                ) );
    5351        }
    5452
    class BP_Tests_BP_Component_TestCases extends BP_UnitTestCase { 
    6563                $this->assertSame( $bp->unit_test_rest->controllers, array(
    6664                        'BP_REST_Components_Endpoint',
    6765                        'BP_REST_Members_Endpoint',
     66                ) );
     67        }
     68
     69        public function test_rest_api_init_for_xprofile_component() {
     70                $bp_xprofile = new BP_XProfile_Component();
     71                $bp          = buddypress();
     72
     73                $bp_xprofile->rest_api_init();
     74
     75                $this->assertSame( $bp->unit_test_rest->controllers, array(
     76                        'BP_REST_XProfile_Fields_Endpoint',
     77                        'BP_REST_XProfile_Field_Groups_Endpoint',
     78                        'BP_REST_XProfile_Data_Endpoint',
    6879                        'BP_REST_Attachments_Member_Avatar_Endpoint',
    6980                ) );
    7081        }
     82
     83        public function test_rest_api_init_for_xprofile_component_without_avatar_enabled() {
     84                add_filter( 'bp_disable_avatar_uploads', '__return_true' );
     85
     86                $bp_xprofile = new BP_XProfile_Component();
     87                $bp          = buddypress();
     88
     89                $bp_xprofile->rest_api_init();
     90
     91                remove_filter( 'bp_disable_avatar_uploads', '__return_true' );
     92
     93                $this->assertSame( $bp->unit_test_rest->controllers, array(
     94                        'BP_REST_XProfile_Fields_Endpoint',
     95                        'BP_REST_XProfile_Field_Groups_Endpoint',
     96                        'BP_REST_XProfile_Data_Endpoint',
     97                ) );
     98        }
    7199}