mirror of
https://github.com/PHPMailer/PHPMailer.git
synced 2024-09-20 01:52:15 +02:00
PunyencodeAddressTest: add additional test method
This new test method covers a range of cases where the `PHPMailer::punyencodeAddress()` method should (and does) return the original input value unchanged. This test does not require the `mbstring` extension or `idn_to_ascii()` function to be available, which is why it has been set up as a separate test with a separate data provider.
This commit is contained in:
parent
7f6c882395
commit
09ba11ae08
@ -72,4 +72,64 @@ final class PunyencodeAddressTest extends TestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test IDN to ASCII form/punycode conversion returns the original value when no conversion
|
||||
* is needed or when the requirements to convert an address have not been met.
|
||||
*
|
||||
* @dataProvider dataPunyencodeAddressNoConversion
|
||||
*
|
||||
* @param string $input Input text string.
|
||||
* @param string $charset The character set.
|
||||
* @param string $expected Expected funtion output.
|
||||
*/
|
||||
public function testPunyencodeAddressNoConversion($input, $charset, $expected)
|
||||
{
|
||||
$this->Mail->CharSet = $charset;
|
||||
|
||||
// Prevent a warning about html_entity_decode() not supporting charset `us-ascii`.
|
||||
if ($charset !== PHPMailer::CHARSET_ASCII) {
|
||||
$input = html_entity_decode($input, ENT_COMPAT, $charset);
|
||||
$expected = html_entity_decode($expected, ENT_COMPAT, $charset);
|
||||
}
|
||||
|
||||
$result = $this->Mail->punyencodeAddress($input);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dataPunyencodeAddressNoConversion()
|
||||
{
|
||||
return [
|
||||
'ASCII' => [
|
||||
'input' => 'test@example.com',
|
||||
'charset' => PHPMailer::CHARSET_ASCII,
|
||||
'expected' => 'test@example.com',
|
||||
],
|
||||
'Invalid email address' => [
|
||||
'input' => 'françois@',
|
||||
'charset' => PHPMailer::CHARSET_UTF8,
|
||||
'expected' => 'françois@',
|
||||
],
|
||||
'Not an email address' => [
|
||||
'input' => 'testing 1-2-3',
|
||||
'charset' => PHPMailer::CHARSET_UTF8,
|
||||
'expected' => 'testing 1-2-3',
|
||||
],
|
||||
'Empty string' => [
|
||||
'input' => '',
|
||||
'charset' => PHPMailer::CHARSET_UTF8,
|
||||
'expected' => '',
|
||||
],
|
||||
'Empty charset' => [
|
||||
'input' => 'test@françois.ch',
|
||||
'charset' => '',
|
||||
'expected' => 'test@françois.ch',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user