| | 557 | |
| | 558 | /** |
| | 559 | * Test that multiple headers with the same name are sent correctly. |
| | 560 | * |
| | 561 | * @ticket 30128 |
| | 562 | * @ticket 56779 |
| | 563 | */ |
| | 564 | public function test_wp_mail_with_multiple_same_name_headers() { |
| | 565 | $to = 'test@example.com'; |
| | 566 | $subject = 'Testing Multiple Headers'; |
| | 567 | $message = 'This is a test message.'; |
| | 568 | $headers = array( |
| | 569 | 'x-my-things: thing1', |
| | 570 | 'x-my-things: thing2', |
| | 571 | ); |
| | 572 | |
| | 573 | wp_mail( $to, $subject, $message, $headers ); |
| | 574 | |
| | 575 | $mailer = tests_retrieve_phpmailer_instance(); |
| | 576 | $sent_header = $mailer->get_sent()->header; |
| | 577 | |
| | 578 | $this->assertStringContainsString( 'x-my-things: thing1', $sent_header, 'The first header was not sent.' ); |
| | 579 | $this->assertStringContainsString( 'x-my-things: thing2', $sent_header, 'The second header was not sent.' ); |
| | 580 | } |
| | 581 | |
| | 582 | /** |
| | 583 | * Tests that headers are handled correctly in various formats. |
| | 584 | * |
| | 585 | * @dataProvider data_wp_mail_header_formats |
| | 586 | * |
| | 587 | * @ticket 30128 |
| | 588 | */ |
| | 589 | public function test_wp_mail_header_formats( $headers, $expected_strings ) { |
| | 590 | wp_mail( 'test@example.com', 'Test', 'Message', $headers ); |
| | 591 | |
| | 592 | $mailer = tests_retrieve_phpmailer_instance(); |
| | 593 | $sent_header = $mailer->get_sent()->header; |
| | 594 | |
| | 595 | foreach ( $expected_strings as $expected_string ) { |
| | 596 | $this->assertStringContainsString( $expected_string, $sent_header ); |
| | 597 | } |
| | 598 | } |
| | 599 | |
| | 600 | /** |
| | 601 | * Data provider for test_wp_mail_header_formats. |
| | 602 | */ |
| | 603 | public function data_wp_mail_header_formats() { |
| | 604 | return array( |
| | 605 | 'associative array' => array( |
| | 606 | 'headers' => array( |
| | 607 | 'From' => 'Me Myself <me@example.org>', |
| | 608 | 'Cc' => 'Isaaco Harrelson <iharrel@example.org>', |
| | 609 | ), |
| | 610 | 'expected_strings' => array( |
| | 611 | 'From: Me Myself <me@example.org>', |
| | 612 | 'Cc: Isaaco Harrelson <iharrel@example.org>', |
| | 613 | ), |
| | 614 | ), |
| | 615 | 'indexed array' => array( |
| | 616 | 'headers' => array( |
| | 617 | 'From: Me Myself <me@example.org>', |
| | 618 | 'Cc: Isaaco Harrelson <iharrel@example.org>', |
| | 619 | ), |
| | 620 | 'expected_strings' => array( |
| | 621 | 'From: Me Myself <me@example.org>', |
| | 622 | 'Cc: Isaaco Harrelson <iharrel@example.org>', |
| | 623 | ), |
| | 624 | ), |
| | 625 | 'associative array with multiple CCs' => array( |
| | 626 | 'headers' => array( |
| | 627 | 'From' => 'Me Myself <me@example.org>', |
| | 628 | 'Cc' => array( |
| | 629 | 'Isaaco Harrelson <iharrel@example.org>', |
| | 630 | 'frederick@wordpress.org', |
| | 631 | ), |
| | 632 | ), |
| | 633 | 'expected_strings' => array( |
| | 634 | 'From: Me Myself <me@example.org>', |
| | 635 | 'Cc: Isaaco Harrelson <iharrel@example.org>, frederick@wordpress.org', |
| | 636 | ), |
| | 637 | ), |
| | 638 | ); |
| | 639 | } |