From 8e76e48afbe07d9e248001ef598df5109e81dfb6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 4 Jul 2021 06:34:25 +0200 Subject: [PATCH] Tests/reorganize: move addEmbeddedImage tests to own file Note: this doesn't move the complete test from the original test file, just select parts of the test method. --- test/PHPMailer/AddEmbeddedImageTest.php | 70 +++++++++++++++++++++++++ test/PHPMailer/PHPMailerTest.php | 37 ------------- 2 files changed, 70 insertions(+), 37 deletions(-) create mode 100644 test/PHPMailer/AddEmbeddedImageTest.php diff --git a/test/PHPMailer/AddEmbeddedImageTest.php b/test/PHPMailer/AddEmbeddedImageTest.php new file mode 100644 index 00000000..e090d974 --- /dev/null +++ b/test/PHPMailer/AddEmbeddedImageTest.php @@ -0,0 +1,70 @@ + + * @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\Exception; +use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\Test\SendTestCase; + +/** + * Test adding embedded image(s) functionality. + */ +final class AddEmbeddedImageTest extends SendTestCase +{ + + /** + * An embedded attachment test. + */ + public function testEmbeddedImage() + { + $this->Mail->Body = 'Embedded Image: phpmailer' . + 'Here is an image!'; + $this->Mail->Subject .= ': Embedded Image'; + $this->Mail->isHTML(true); + + if ( + !$this->Mail->addEmbeddedImage( + realpath(\PHPMAILER_INCLUDE_DIR . '/examples/images/phpmailer.png'), + 'my-attach', + 'phpmailer.png', + 'base64', + 'image/png' + ) + ) { + self::assertTrue(false, $this->Mail->ErrorInfo); + + return; + } + + $this->buildBody(); + self::assertTrue($this->Mail->send(), $this->Mail->ErrorInfo); + $this->Mail->clearAttachments(); + + //For code coverage + $this->Mail->addEmbeddedImage('thisfiledoesntexist', 'xyz'); //Non-existent file + $this->Mail->addEmbeddedImage(__FILE__, '123'); //Missing name + } + + /** + * Expect exceptions on bad encoding + */ + public function testEmbeddedImageEncodingException() + { + $this->expectException(Exception::class); + + $mail = new PHPMailer(true); + $mail->addEmbeddedImage(__FILE__, 'cid', 'test.png', 'invalidencoding'); + } +} diff --git a/test/PHPMailer/PHPMailerTest.php b/test/PHPMailer/PHPMailerTest.php index 1a461e8e..9b6403e1 100644 --- a/test/PHPMailer/PHPMailerTest.php +++ b/test/PHPMailer/PHPMailerTest.php @@ -640,29 +640,6 @@ EOT; */ public function testEmbeddedImage() { - $this->Mail->Body = 'Embedded Image: phpmailer' . - 'Here is an image!'; - $this->Mail->Subject .= ': Embedded Image'; - $this->Mail->isHTML(true); - - if ( - !$this->Mail->addEmbeddedImage( - realpath(\PHPMAILER_INCLUDE_DIR . '/examples/images/phpmailer.png'), - 'my-attach', - 'phpmailer.png', - 'base64', - 'image/png' - ) - ) { - self::assertTrue(false, $this->Mail->ErrorInfo); - - return; - } - - $this->buildBody(); - self::assertTrue($this->Mail->send(), $this->Mail->ErrorInfo); - $this->Mail->clearAttachments(); $this->Mail->msgHTML(' @@ -679,9 +656,6 @@ EOT; $this->Mail->getSentMIMEMessage(), 'Embedded image header encoding incorrect.' ); - //For code coverage - $this->Mail->addEmbeddedImage('thisfiledoesntexist', 'xyz'); //Non-existent file - $this->Mail->addEmbeddedImage(__FILE__, '123'); //Missing name } /** @@ -1031,17 +1005,6 @@ EOT; $mail->addStringAttachment('hello', 'test.txt', 'invalidencoding'); } - /** - * Expect exceptions on bad encoding - */ - public function testEmbeddedImageEncodingException() - { - $this->expectException(Exception::class); - - $mail = new PHPMailer(true); - $mail->addEmbeddedImage(__FILE__, 'cid', 'test.png', 'invalidencoding'); - } - /** * Expect exceptions on bad encoding */