From e5b07ba3c36f6fc0fe2ffd76e2e61fa191e41245 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 4 Jul 2021 15:22:38 +0200 Subject: [PATCH] AddEmbeddedImageTest: split off failure test The "failure" case when a non-existent file was being passed, wasn't actually being tested at all as no assertion was used. This commit: * Moves the particular failure test case to a separate test method with a data provider (to allow for more failure test cases to be added). * Uses an assertion on the call to `addEmbeddedImage()` to actually test that the method return a failure state. * Verifies that no attachment for an inline image was added by adding a second assertion with a call to `PHPMailer::inlineImageExists()`. --- test/PHPMailer/AddEmbeddedImageTest.php | 34 ++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/test/PHPMailer/AddEmbeddedImageTest.php b/test/PHPMailer/AddEmbeddedImageTest.php index 332cc7c6..a40e6d84 100644 --- a/test/PHPMailer/AddEmbeddedImageTest.php +++ b/test/PHPMailer/AddEmbeddedImageTest.php @@ -53,10 +53,42 @@ final class AddEmbeddedImageTest extends PreSendTestCase $this->Mail->clearAttachments(); //For code coverage - $this->Mail->addEmbeddedImage('thisfiledoesntexist', 'xyz'); //Non-existent file $this->Mail->addEmbeddedImage(__FILE__, '123'); //Missing name } + /** + * Test that embedding an image fails in select use cases. + * + * @dataProvider dataFailToAttach + * + * @param string $path Path to the attachment. + * @param string $cid Content ID for the attachment. + * @param string $name Optional. Attachment name to use. + * @param string $encoding Optional. File encoding to pass. + */ + public function testFailToAttach($path, $cid, $name = '', $encoding = PHPMailer::ENCODING_BASE64) + { + $result = $this->Mail->addEmbeddedImage($path, $cid, $name, $encoding); + self::assertFalse($result, 'Image did not fail to attach'); + + self::assertFalse($this->Mail->inlineImageExists(), 'Inline image present in attachments array'); + } + + /** + * Data provider. + * + * @return array + */ + public function dataFailToAttach() + { + return [ + 'Invalid: non-existent file' => [ + 'path' => 'thisfiledoesntexist', + 'cid' => 'xyz', + ], + ]; + } + /** * Expect exceptions on bad encoding */