From d034bef1364a66d9a089b74cbd5cc2c037dfa3fd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 4 Jul 2021 17:17:43 +0200 Subject: [PATCH] AddEmbeddedImageTest: split off "missing name" test The test case when a file was attached without explicitly adding a filename wasn't actually being tested at all as no assertion was used. This commit: * Moves that particular test case to a separate test method. * Adds relevant assertions to actually test the test case. --- test/PHPMailer/AddEmbeddedImageTest.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/PHPMailer/AddEmbeddedImageTest.php b/test/PHPMailer/AddEmbeddedImageTest.php index a40e6d84..2a9073fa 100644 --- a/test/PHPMailer/AddEmbeddedImageTest.php +++ b/test/PHPMailer/AddEmbeddedImageTest.php @@ -51,9 +51,22 @@ final class AddEmbeddedImageTest extends PreSendTestCase $this->buildBody(); self::assertTrue($this->Mail->preSend(), $this->Mail->ErrorInfo); $this->Mail->clearAttachments(); + } - //For code coverage - $this->Mail->addEmbeddedImage(__FILE__, '123'); //Missing name + /** + * Test adding an image without explicitly adding a name for the image will set the name as the existing file name. + */ + public function testAddingImageWithoutExplicitName() + { + $result = $this->Mail->addEmbeddedImage(__FILE__, '123'); + self::assertTrue($result, 'File failed to attach'); + + self::assertTrue($this->Mail->inlineImageExists(), 'Inline image not present in attachments array'); + + $attachments = $this->Mail->getAttachments(); + self::assertIsArray($attachments, 'Attachments is not an array'); + self::assertArrayHasKey(0, $attachments, 'Attachments does not have the expected array entry'); + self::assertSame($attachments[0][1], $attachments[0][2], 'Name is not the same as filename'); } /**