0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-20 01:52:15 +02:00

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.
This commit is contained in:
jrfnl 2021-07-04 06:34:25 +02:00
parent 58b875bfed
commit 8e76e48afb
2 changed files with 70 additions and 37 deletions

View File

@ -0,0 +1,70 @@
<?php
/**
* PHPMailer - PHP email transport unit tests.
* PHP version 5.5.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @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: <img alt="phpmailer" src="' .
'cid:my-attach">' .
'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');
}
}

View File

@ -640,29 +640,6 @@ EOT;
*/
public function testEmbeddedImage()
{
$this->Mail->Body = 'Embedded Image: <img alt="phpmailer" src="' .
'cid:my-attach">' .
'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('<!DOCTYPE html>
<html lang="en">
<head>
@ -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
*/