OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
back_aws-ses
/
vendor
/
phpmailer
/
phpmailer
/
test
/
PHPMailer
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
05/19/2025 10:07:21 AM
rwxr-xr-x
📄
AddEmbeddedImageTest.php
6.45 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
AddStringAttachmentTest.php
5.19 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
AddStringEmbeddedImageTest.php
5.53 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
AddrFormatTest.php
2.08 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
AuthCRAMMD5Test.php
1.54 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
CustomHeaderTest.php
9.2 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
DKIMTest.php
9.51 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
DSNConfiguratorTest.php
6.49 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
EncodeQTest.php
3.96 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
EncodeStringTest.php
4.58 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
FileIsAccessibleTest.php
3.32 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
FilenameToTypeTest.php
2.22 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
GenerateIdTest.php
2.63 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
GetLastMessageIDTest.php
3.32 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
HasLineLongerThanMaxTest.php
4.69 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
Html2TextTest.php
9.79 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
ICalTest.php
4.32 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
IsPermittedPathTest.php
3.74 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
IsValidHostTest.php
4.18 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
LocalizationTest.php
18.51 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
MailTransportTest.php
3.67 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
MbPathinfoTest.php
5.74 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
MimeTypesTest.php
1.93 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
NormalizeBreaksTest.php
3.62 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
PHPMailerTest.php
47.39 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
ParseAddressesTest.php
14.27 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
PunyencodeAddressTest.php
4.77 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
QuotedStringTest.php
2.08 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
ReplyToGetSetClearTest.php
17.23 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
SetErrorTest.php
5.19 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
SetFromTest.php
7.08 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
SetTest.php
2.32 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
SetWordWrapTest.php
4.01 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
Utf8CharBoundaryTest.php
1.95 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
ValidateAddressCustomValidatorTest.php
3.65 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
ValidateAddressTest.php
17.2 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
WrapTextTest.php
6.05 KB
05/19/2025 10:07:21 AM
rw-r--r--
📄
XMailerTest.php
2 KB
05/19/2025 10:07:21 AM
rw-r--r--
Editing: AddEmbeddedImageTest.php
Close
<?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\PreSendTestCase; /** * Test adding embedded image(s) functionality. * * @covers \PHPMailer\PHPMailer\PHPMailer::addEmbeddedImage * @covers \PHPMailer\PHPMailer\PHPMailer::createBody * @covers \PHPMailer\PHPMailer\PHPMailer::getAttachments * @covers \PHPMailer\PHPMailer\PHPMailer::inlineImageExists */ final class AddEmbeddedImageTest extends PreSendTestCase { /** * Test successfully adding an embedded image. */ public function testAddEmbeddedImage() { $pathToFile = realpath(\PHPMAILER_INCLUDE_DIR . '/examples/images/phpmailer.png'); $expected = [ 0 => $pathToFile, 1 => 'phpmailer.png', 2 => 'phpmailer.png', 3 => 'base64', 4 => 'image/png', 5 => false, 6 => 'inline', 7 => 'my-attach', ]; $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); // Test attaching the image. $result = $this->Mail->addEmbeddedImage( $pathToFile, 'my-attach', 'phpmailer.png', 'base64', 'image/png' ); self::assertTrue($result, $this->Mail->ErrorInfo); self::assertTrue($this->Mail->inlineImageExists(), 'Embedded 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($expected, $attachments[0], 'Attachment info does not match the expected array'); // Test that the image was correctly added to the message body. $this->buildBody(); self::assertTrue($this->Mail->preSend(), $this->Mail->ErrorInfo); $sendMessage = $this->Mail->getSentMIMEMessage(); $LE = PHPMailer::getLE(); self::assertStringContainsString( 'Content-Type: image/png; name=phpmailer.png' . $LE, $sendMessage, 'Embedded image header content type incorrect.' ); self::assertStringContainsString( 'Content-ID: <my-attach>' . $LE, $sendMessage, 'Embedded image header content ID incorrect.' ); self::assertStringContainsString( 'Content-Disposition: inline; filename=phpmailer.png' . $LE, $sendMessage, 'Embedded image header content disposition incorrect.' ); } /** * 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'); } /** * 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 $exceptionMessage Unused in this test. * @param string $name Optional. Attachment name to use. * @param string $encoding Optional. File encoding to pass. */ public function testFailToAttach($path, $cid, $exceptionMessage, $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'); } /** * Test that embedding an image throws an exception in select use cases. * * @dataProvider dataFailToAttach * * @param string $path Path to the attachment. * @param string $cid Content ID for the attachment. * @param string $exceptionMessage The exception message to expect. * @param string $name Optional. Attachment name to use. * @param string $encoding Optional. File encoding to pass. */ public function testFailToAttachException( $path, $cid, $exceptionMessage, $name = '', $encoding = PHPMailer::ENCODING_BASE64 ) { $this->expectException(Exception::class); $this->expectExceptionMessage($exceptionMessage); $mail = new PHPMailer(true); $mail->addEmbeddedImage($path, $cid, $name, $encoding); } /** * Data provider. * * @return array */ public function dataFailToAttach() { return [ 'Invalid: non-existent file' => [ 'path' => 'thisfiledoesntexist', 'cid' => 'xyz', 'exceptionMessage' => 'Could not access file: thisfiledoesntexist', ], 'Invalid: invalid encoding' => [ 'path' => __FILE__, 'cid' => 'cid', 'exceptionMessage' => 'Unknown encoding: invalidencoding', 'name' => 'test.png', 'encoding' => 'invalidencoding', ], ]; } }