From 641b4c239171d3dbf553d92ecfa95ab991d314ca Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Jul 2021 06:34:02 +0200 Subject: [PATCH] Tests: introduce dedicated tests for the `PHPMailer::quotedString()` method So far, this method did not have dedicated tests, though the `PHPMailerTest::testAttachmentNaming()` test covered this partially. The test file this commit introduces, tests all aspects of the method as well as documents the current behaviour of the method. Test cases largely inspired by the tests in the `PHPMailerTest::testAttachmentNaming()` method. --- test/PHPMailer/QuotedStringTest.php | 71 +++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 test/PHPMailer/QuotedStringTest.php diff --git a/test/PHPMailer/QuotedStringTest.php b/test/PHPMailer/QuotedStringTest.php new file mode 100644 index 00000000..7948054b --- /dev/null +++ b/test/PHPMailer/QuotedStringTest.php @@ -0,0 +1,71 @@ + + * @author Andy Prevost + * @copyright 2012 - 2020 Marcus Bointon + * @copyright 2004 - 2009 Andy Prevost + * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License + */ + +namespace PHPMailer\Test\PHPMailer; + +use PHPMailer\PHPMailer\PHPMailer; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; + +/** + * Test quoted string functionality. + * + * @covers \PHPMailer\PHPMailer\PHPMailer::quotedString + */ +final class QuotedStringTest extends TestCase +{ + + /** + * Test quoting of a string depending on the content of the string. + * + * @dataProvider dataQuotedString + * + * @param string $input Input text string. + * @param string $expected Expected funtion output. + */ + public function testQuotedString($input, $expected) + { + $result = PHPMailer::quotedString($input); + self::assertSame($expected, $result); + } + + /** + * Data provider. + * + * @return array + */ + public function dataQuotedString() + { + return [ + 'No special chars' => [ + 'input' => 'phpmailer.png', + 'expected' => 'phpmailer.png', + ], + 'Text containing double quote char' => [ + 'input' => 'phpmailer_mini".png', + 'expected' => '"phpmailer_mini\".png"', + ], + 'Text containing pre-escaped double quote char' => [ + 'input' => 'phpmailer_mini\".png', + 'expected' => '"phpmailer_mini\\\".png"', + ], + 'Text containing spaces' => [ + 'input' => 'PHPMailer card logo.png', + 'expected' => '"PHPMailer card logo.png"', + ], + 'Text containing variety of "special" chars' => [ + 'input' => 'php@ma;ler=m:ni,p?q=[foo]', + 'expected' => '"php@ma;ler=m:ni,p?q=[foo]"', + ], + ]; + } +}