Skip to content
Snippets Groups Projects
Verified Commit e1a29d08 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #124969 by Dave Reid, andregp, naxoc, pameeela, ravi.shankar,...

Issue #124969 by Dave Reid, andregp, naxoc, pameeela, ravi.shankar, bruno.bicudo, _pratik_, jnlar, yogeshmpawar, marcingy, StevenPatz, amitgoyal, Johnny Santos, larowlan, smustgrave, Dries, DanielVeza, mstrelan, cburschka, quietone, alexpott, bradlis7: Contact form opt-out line should be excluded from admin-sent and sender-copy e-mails

(cherry picked from commit 1dbf2cc2)
parent 39d29ea6
No related branches found
No related tags found
32 merge requests!12802Issue #3537193 by opauwlo: Add enable absolute path option for CKEditor5 image uploads,!12745Fixed: Path alias language doesn't changes on changing of node language,!12684Issue #3220784,!12537Add ViewsConfigUpdater deprecation support for default_argument_skip_url,!12523Issue #3493858 by vidorado, xavier.masson, smustgrave: Extend ViewsBlockBase...,!122353526426-warning-for-missing,!12212Issue #3445525 by alexpott, japerry, catch, mglaman, longwave: Add BC layer...,!11958Issue #3490507 by alexpott, smustgrave: Fix bogus mocking in...,!11769Issue #3517987: Add option to contextual filters to encode slashes in query parameter.,!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7384Add constraints to system.advisories,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #136273 passed with warnings
Pipeline: drupal

#136309

    Pipeline: drupal

    #136302

      Pipeline: drupal

      #136290

        +1
        ......@@ -161,7 +161,13 @@ function contact_mail($key, &$message, $params) {
        $message['subject'] .= t('[@site-name] @subject', $variables, $options);
        $message['body'][] = t('Hello @recipient-name,', $variables, $options);
        $message['body'][] = t("@sender-name (@sender-url) has sent you a message via your contact form at @site-name.", $variables, $options);
        $message['body'][] = t("If you don't want to receive such emails, you can change your settings at @recipient-edit-url.", $variables, $options);
        // Only include the opt-out line in the original email and not in the
        // copy to the sender. Also exclude this if the email was sent from a
        // user administrator because they can always send emails even if the
        // contacted user has disabled their contact form.
        if ($key === 'user_mail' && !$params['sender']->hasPermission('administer users')) {
        $message['body'][] = t("If you don't want to receive such messages, you can change your settings at @recipient-edit-url.", $variables, $options);
        }
        $build = \Drupal::entityTypeManager()
        ->getViewBuilder('contact_message')
        ->view($contact_message, 'mail');
        ......
        ......@@ -338,18 +338,65 @@ protected function checkContactAccess($response, $contact_value = NULL) {
        * @param array $message
        * (optional) An array with the form fields being used. Defaults to an empty
        * array.
        * @param bool $user_copy
        * (optional) A boolean to determine whether to send a user copy email.
        * Defaults to FALSE.
        *
        * @return array
        * An array with the form fields being used.
        */
        protected function submitPersonalContact(AccountInterface $account, array $message = []) {
        protected function submitPersonalContact(AccountInterface $account, array $message = [], bool $user_copy = FALSE) {
        $message += [
        'subject[0][value]' => $this->randomMachineName(16) . '< " =+ >',
        'message[0][value]' => $this->randomMachineName(64) . '< " =+ >',
        'copy' => $user_copy,
        ];
        $this->drupalGet('user/' . $account->id() . '/contact');
        $this->submitForm($message, 'Send message');
        return $message;
        }
        /**
        * Tests that the opt-out message is included correctly in contact emails.
        */
        public function testPersonalContactForm(): void {
        $opt_out_message = "If you don't want to receive such messages, you can change your settings at";
        // Send an email from an admin (should not contain the opt-out message).
        $this->drupalLogin($this->adminUser);
        $this->submitPersonalContact($this->contactUser);
        $this->drupalLogout();
        $this->assertStringNotContainsString($opt_out_message, $this->getMails()[0]['body'], 'Opt-out message excluded in email.');
        // Send an email from a non-admin (should contain the opt-out message).
        $this->drupalLogin($this->webUser);
        $this->submitPersonalContact($this->contactUser);
        $this->assertMailString('body', $opt_out_message, 1, 'Opt-out message included in email.');
        }
        /**
        * Tests that the opt-out message is not included in user copy emails.
        */
        public function testPersonalContactFormUserCopy(): void {
        $opt_out_message = "If you don't want to receive such messages, you can change your settings at";
        // Send an email from an admin.
        $this->drupalLogin($this->adminUser);
        $this->submitPersonalContact($this->contactUser, [], TRUE);
        $this->drupalLogout();
        // Send an email from a non-admin.
        $this->drupalLogin($this->webUser);
        $this->submitPersonalContact($this->contactUser, [], TRUE);
        $user_copy_emails = $this->getMails(['id' => 'contact_user_copy']);
        // Tests that the opt-out message is not included in admin user copy emails.
        $this->assertStringNotContainsString($opt_out_message, $user_copy_emails[0]['body'], 'Opt-out message not included in admin user copy email.');
        // Tests that the opt-out message is not included in non-admin user copy emails.
        $this->assertStringNotContainsString($opt_out_message, $user_copy_emails[1]['body'], 'Opt-out message not included in non-admin user copy email.');
        }
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment