Skip to content
Snippets Groups Projects
Verified Commit dee0d98a authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #2980952 by dcam, arunkumark, tanuj., guypaddock, Yogesh Sahu,...

Issue #2980952 by dcam, arunkumark, tanuj., guypaddock, Yogesh Sahu, aaronmchale, smustgrave: Wrong message on cancelling account with e-mail confirmation request
parent 849a6872
No related branches found
No related tags found
No related merge requests found
Pipeline #465326 passed with warnings
Pipeline: drupal

#465329

    ......@@ -149,9 +149,14 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->entity->user_cancel_notify = $form_state->getValue('user_cancel_notify');
    $this->entity->save();
    _user_mail_notify('cancel_confirm', $this->entity);
    $this->messenger()->addStatus($this->t('A confirmation request to cancel your account has been sent to your email address.'));
    $this->logger('user')->info('Sent account cancellation request to %name %email.', ['%name' => $this->entity->label(), '%email' => '<' . $this->entity->getEmail() . '>']);
    $cancel_message = $this->t('A confirmation request to cancel your account has been sent to your email address.');
    if ($this->entity->id() !== $this->currentUser()->id()) {
    $cancel_message = $this->t("A confirmation request to cancel the account %name has been sent to the user's email address.", ['%name' => $this->entity->label()]);
    }
    $this->messenger()->addStatus($cancel_message);
    $form_state->setRedirect(
    'entity.user.canonical',
    ['user' => $this->entity->id()]
    ......
    ......@@ -514,27 +514,40 @@ public function testUserDelete(): void {
    }
    /**
    * Create an administrative user and delete another user.
    * Create an administrative user and delete other users.
    */
    public function testUserCancelByAdmin(): void {
    $this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
    // Create a regular user.
    $account = $this->drupalCreateUser([]);
    // Create administrative user.
    $admin_user = $this->drupalCreateUser(['administer users']);
    $this->drupalLogin($admin_user);
    // Test deletion of a user account without email confirmation.
    $account1 = $this->drupalCreateUser([]);
    // Delete regular user.
    $this->drupalGet('user/' . $account->id() . '/cancel');
    $this->assertSession()->pageTextContains("Are you sure you want to cancel the account {$account->getAccountName()}?");
    $this->drupalGet('user/' . $account1->id() . '/cancel');
    $this->assertSession()->pageTextContains("Are you sure you want to cancel the account {$account1->getAccountName()}?");
    $this->assertSession()->pageTextContains('Cancellation method');
    // Confirm deletion.
    $this->submitForm([], 'Confirm');
    $this->assertSession()->pageTextContains("Account {$account->getAccountName()} has been deleted.");
    $this->assertNull(User::load($account->id()), 'User is not found in the database.');
    $this->assertSession()->pageTextContains("Account {$account1->getAccountName()} has been deleted.");
    $this->assertNull(User::load($account1->id()), 'User is not found in the database.');
    // Test deletion of a user account with email confirmation.
    $account2 = $this->drupalCreateUser([]);
    // Delete regular user.
    $this->drupalGet('user/' . $account2->id() . '/cancel');
    $this->assertSession()->pageTextContains("Are you sure you want to cancel the account {$account2->getAccountName()}?");
    $this->assertSession()->pageTextContains('Cancellation method');
    // Confirm deletion.
    $this->submitForm(['edit-user-cancel-confirm' => 1], 'Confirm');
    $this->assertSession()->pageTextContains("A confirmation request to cancel the account {$account2->getAccountName()} has been sent to the user's email address.");
    $this->assertNotNull(User::load($account2->id()), 'User is found in the database.');
    }
    /**
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment