Skip to content

Commit

Permalink
ReplyToGetSetClearTest: test the reply-to message header gets set cor…
Browse files Browse the repository at this point in the history
…rectly

This commit:
* Renames the `testLowPriority()` method to `testReplyToInMessageHeader()`.
    This test method was originally basically testing two things: the priority and the reply to header being set. For this class, it now just focusses on the reply to header, so letting the name reflect that.
* Enhances the test by actually testing that the reply-to header is correctly found in the fully composed message.
* Breaks out the test case to a data provider to allow for adding additional test cases more easily.
  • Loading branch information
jrfnl committed Jul 12, 2021
1 parent 5396226 commit faf8d9f
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions test/PHPMailer/ReplyToGetSetClearTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,58 @@ public function dataAddReplyToInvalidAddressNonIdn()
}

/**
* Test low priority.
* Test that the correct Reply-To message header has been added to the message.
*
* @covers \PHPMailer\PHPMailer\PHPMailer::addReplyTo
* @covers \PHPMailer\PHPMailer\PHPMailer::createHeader
* @covers \PHPMailer\PHPMailer\PHPMailer::addrAppend
*
* @dataProvider dataReplyToInMessageHeader
*
* @param string $addresses The email address(es) to set for Reply-To.
* @param string $expected The expected message header.
*/
public function testLowPriority()
public function testReplyToInMessageHeader($addresses, $expected)
{
$this->Mail->Body = 'Here is the main body. There should be ' .
'a reply to address in this message.';
$this->Mail->Subject .= ': Low Priority';
$this->Mail->addReplyTo('nobody@nobody.com', 'Nobody (Unit Test)');
'a reply to header in this message.';
$this->Mail->Subject .= ': Reply to header';

foreach ($addresses as $address) {
if (isset($address['name'])) {
$this->Mail->addReplyTo($address['address'], $address['name']);
} else {
$this->Mail->addReplyTo($address['address']);
}
}

$this->buildBody();
self::assertTrue($this->Mail->preSend(), $this->Mail->ErrorInfo);

$message = $this->Mail->getSentMIMEMessage();
self::assertStringContainsString($expected, $message, 'Message does not contain the expected reply-to header');
}

/**
* Data provider.
*
* @return array
*/
public function dataReplyToInMessageHeader()
{
$LE = PHPMailer::getLE();

return [
'Single address + name' => [
'addresses' => [
[
'address' => 'nobody@nobody.com',
'name' => 'Nobody (Unit Test)',
],
],
'expected' => $LE . 'Reply-To: "Nobody (Unit Test)" <nobody@nobody.com>' . $LE,
],
];
}

/**
Expand Down

0 comments on commit faf8d9f

Please sign in to comment.