mirror of
https://github.com/PHPMailer/PHPMailer.git
synced 2024-09-20 01:52:15 +02:00
AddStringAttachmentTest: improve original test
This expands the assertions executed in this test to cover the code under test more comprehensively.
This commit is contained in:
parent
41af61ab2f
commit
40a4fa39b7
@ -24,21 +24,63 @@ final class AddStringAttachmentTest extends PreSendTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Simple plain string attachment test.
|
||||
* Test successfully adding a simple plain string attachment.
|
||||
*/
|
||||
public function testPlainStringAttachment()
|
||||
public function testAddPlainStringAttachment()
|
||||
{
|
||||
$this->Mail->Body = 'Here is the text body';
|
||||
$this->Mail->Subject .= ': Plain + StringAttachment';
|
||||
|
||||
$sAttachment = 'These characters are the content of the ' .
|
||||
"string attachment.\nThis might be taken from a " .
|
||||
'database or some other such thing. ';
|
||||
|
||||
$this->Mail->addStringAttachment($sAttachment, 'string_attach.txt');
|
||||
$expected = [
|
||||
0 => $sAttachment,
|
||||
1 => 'string_attach.txt',
|
||||
2 => 'string_attach.txt',
|
||||
3 => 'base64',
|
||||
4 => 'text/plain',
|
||||
5 => true,
|
||||
6 => 'attachment',
|
||||
7 => 0,
|
||||
];
|
||||
|
||||
$this->Mail->Body = 'Here is the text body';
|
||||
$this->Mail->Subject .= ': Plain + StringAttachment';
|
||||
|
||||
// Test attaching the plain string attachment.
|
||||
$result = $this->Mail->addStringAttachment($sAttachment, 'string_attach.txt');
|
||||
|
||||
self::assertTrue($result, $this->Mail->ErrorInfo);
|
||||
self::assertTrue($this->Mail->attachmentExists(), 'Plain text attachment 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 plain text attachment 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: text/plain; name=string_attach.txt' . $LE,
|
||||
$sendMessage,
|
||||
'Embedded image header content type incorrect.'
|
||||
);
|
||||
|
||||
self::assertStringNotContainsString(
|
||||
'Content-ID: ' . $LE,
|
||||
$sendMessage,
|
||||
'Embedded image header content ID not empty.'
|
||||
);
|
||||
|
||||
self::assertStringContainsString(
|
||||
'Content-Disposition: attachment; filename=string_attach.txt' . $LE,
|
||||
$sendMessage,
|
||||
'Embedded image header content disposition incorrect.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user