Make WordPress Core

Ticket #28407: 28407.3.diff

File 28407.3.diff, 2.2 KB (added by johnjamesjacoby, 2 years ago)

Refresh

  • src/wp-includes/pluggable.php

     
    517517                }
    518518
    519519                if ( ! empty( $attachments ) ) {
    520                         foreach ( $attachments as $attachment ) {
     520                        foreach ( $attachments as $filename => $attachment ) {
     521                                $filename = is_string( $filename ) ? $filename : '';
     522
    521523                                try {
    522                                         $phpmailer->addAttachment( $attachment );
     524                                        $phpmailer->addAttachment( $attachment, $filename );
    523525                                } catch ( PHPMailer\PHPMailer\Exception $e ) {
    524526                                        continue;
    525527                                }
  • tests/phpunit/tests/pluggable/wpMail.php

     
    455455        }
    456456
    457457        /**
     458         * Test that attachment file names are derived from array values when their
     459         * associative array keys are numeric.
     460         *
     461         * @ticket 28407
     462         */
     463        public function test_wp_mail_sends_attachments_with_original_name() {
     464                wp_mail( 'user@example.org', 'Subject', 'Hello World', '', array(
     465                        DIR_TESTDATA . '/images/canola.jpg',
     466                        DIR_TESTDATA . '/images/waffles.jpg'
     467                ) );
     468
     469                /** @var PHPMailer $mailer */
     470                $mailer = tests_retrieve_phpmailer_instance();
     471
     472                $attachments = $mailer->getAttachments();
     473
     474                $this->assertTrue( $mailer->attachmentExists() );
     475                $this->assertSame( $attachments[0][1], $attachments[0][2] );
     476                $this->assertSame( $attachments[1][1], $attachments[1][2] );
     477        }
     478
     479        /**
     480         * Test that attachment file names are derived from array keys when they
     481         * are non-empty strings.
     482         *
     483         * @ticket 28407
     484         */
     485        public function test_wp_mail_sends_attachments_with_custom_name() {
     486                wp_mail( 'user@example.org', 'Subject', 'Hello World', '', array(
     487                        'alonac.jpg'  => DIR_TESTDATA . '/images/canola.jpg',
     488                        'selffaw.jpg' => DIR_TESTDATA . '/images/waffles.jpg'
     489                ) );
     490
     491                /** @var PHPMailer $mailer */
     492                $mailer = tests_retrieve_phpmailer_instance();
     493
     494                $attachments = $mailer->getAttachments();
     495
     496                $this->assertTrue( $mailer->attachmentExists() );
     497                $this->assertSame( 'alonac.jpg', $attachments[0][2] );
     498                $this->assertSame( 'selffaw.jpg', $attachments[1][2] );
     499        }
     500
     501        /**
    458502         * @ticket 50720
    459503         */
    460504        public function test_phpmailer_validator() {