Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/03/2024 06:44:17 PM (23 months ago)
Author:
espellcaste
Message:

Misc changes to the signups and pending accounts.

We are improving how signups and pending accounts are handled in BuddyPress.

  • activation emails resend are blocked for one hour, by default;
  • emails are checked if they are already in use in a signup;
  • signup endpoint (https://developer.buddypress.org/bp-rest-api/reference/signup/) returns a useful error when feature is disabled;
  • Signup::resend: Added the ability to resend to a single ID, instead of an array of IDs.

Props niftythree and imath.

Closes https://github.com/buddypress/buddypress/pull/396
See #9229 and #9145
Fixes #9137

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/members/test-signup-controller.php

    r14070 r14071  
    210210         * @group create_item
    211211         */
     212        public function test_creating_multiple_pending_accounts_with_different_usernames() {
     213                $request = new WP_REST_Request( 'POST', $this->endpoint_url );
     214
     215                $params = $this->set_signup_data( array( 'user_login' => 'user1' ) );
     216                $request->set_body_params( $params );
     217                $request->set_param( 'context', 'edit' );
     218                $response = $this->server->dispatch( $request );
     219
     220                $this->assertEquals( 200, $response->get_status() );
     221
     222                $signup = $response->get_data();
     223
     224                $this->assertSame( $signup['user_login'], $params['user_login'] );
     225                $this->assertSame( $signup['user_email'], $params['user_email'] );
     226                $this->assertTrue( ! isset( $signup['activation_key'] ) );
     227
     228                // Test with the same email.
     229                $params = $this->set_signup_data( array( 'user_login' => 'user2' ) );
     230                $request->set_body_params( $params );
     231                $request->set_param( 'context', 'edit' );
     232                $response = $this->server->dispatch( $request );
     233
     234                $this->assertErrorResponse( 'bp_rest_signup_validation_failed', $response, 500, 'This user\'s email is already registered.' );
     235
     236                // Test with a different email.
     237                $params = $this->set_signup_data( array( 'user_login' => 'user2', 'user_email' => 'user2@example.com' ) );
     238                $request->set_body_params( $params );
     239                $request->set_param( 'context', 'edit' );
     240                $response = $this->server->dispatch( $request );
     241
     242                $this->assertEquals( 200, $response->get_status() );
     243        }
     244
     245        /**
     246         * @group create_item
     247         */
    212248        public function test_create_item_with_signup_fields() {
    213249                $g1 = $this->bp::factory()->xprofile_group->create();
     
    664700         * @group resend_item
    665701         */
    666         public function test_resend_acivation_email_to_active_signup() {
     702        public function test_resend_activation_email_to_active_signup() {
    667703                $signup_id = $this->create_signup();
    668704                $signup    = new BP_Signup( $signup_id );
     
    689725         * @group resend_item
    690726         */
     727        public function test_resend_activation_email_to_locked_signup() {
     728                $signup_id = $this->create_signup();
     729
     730                BP_Signup::resend( $signup_id );
     731
     732                $request = new WP_REST_Request( 'PUT', $this->endpoint_url . '/resend' );
     733                $request->set_param( 'id', $signup_id );
     734                $request->set_param( 'context', 'edit' );
     735                $response = $this->server->dispatch( $request );
     736
     737                $this->assertEquals( 500, $response->get_status() );
     738
     739                $error_code = 'bp_rest_signup_resend_activation_email_fail';
     740                $error      = $response->as_error();
     741                $message    = $error->get_error_message( $error_code );
     742
     743                $this->assertErrorResponse( $error_code, $response, 500 );
     744                $this->assertSame(
     745                        $message,
     746                        "You've reached the limit for resending your account activation email. Please wait a few minutes and try again. If you continue to experience issues, contact support for assistance."
     747                );
     748        }
     749
     750        /**
     751         * @group resend_item
     752         */
     753        public function test_resend_activation_email_to_locked_signup_with_hook() {
     754                $signup_id = $this->create_signup();
     755
     756                BP_Signup::resend( $signup_id );
     757
     758                add_filter( 'bp_core_signup_resend_activation_lock_time', '__return_zero' );
     759
     760                $request = new WP_REST_Request( 'PUT', $this->endpoint_url . '/resend' );
     761                $request->set_param( 'id', $signup_id );
     762                $request->set_param( 'context', 'edit' );
     763                $response = $this->server->dispatch( $request );
     764
     765                $this->assertEquals( 200, $response->get_status() );
     766
     767                $all_data = $response->get_data();
     768
     769                $this->assertTrue( $all_data['sent'] );
     770
     771                remove_filter( 'bp_core_signup_resend_activation_lock_time', '__return_zero' );
     772        }
     773
     774        /**
     775         * @group resend_item
     776         */
    691777        public function test_resend_activation_email_invalid_signup_id() {
    692778                $request = new WP_REST_Request( 'PUT', $this->endpoint_url . '/resend' );
     
    734820
    735821        protected function create_signup() {
    736                 return BP_Signup::add(
     822                return $this->bp::factory()->signup->create(
    737823                        array(
    738824                                'user_login'     => 'user' . wp_rand( 1, 20 ),
     
    805891                $this->assertEquals( array( 'view', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    806892        }
     893
     894        public function test_bp_rest_api_signup_disabled_feature_dispatch_error() {
     895                // Disable signups registration.
     896                bp_update_option( 'users_can_register', 0 );
     897
     898                if  ( is_multisite() ) {
     899                        update_site_option( 'registration', '' );
     900                }
     901
     902                $request  = new WP_REST_Request( 'OPTIONS', $this->endpoint_url );
     903                $response = $this->server->dispatch( $request );
     904                $data     = $response->get_data();
     905
     906                $this->assertEquals( 403, $response->get_status() );
     907                $this->assertSame(
     908                        $data['message'],
     909                        'BuddyPress: The user signup feature is currently disabled. Please activate this feature to proceed.'
     910                );
     911        }
    807912}
Note: See TracChangeset for help on using the changeset viewer.