AddEmbeddedImageTest: split off failure test
The "failure" case when a non-existent file was being passed, wasn't actually being tested at all as no assertion was used. This commit: * Moves the particular failure test case to a separate test method with a data provider (to allow for more failure test cases to be added). * Uses an assertion on the call to `addEmbeddedImage()` to actually test that the method return a failure state. * Verifies that no attachment for an inline image was added by adding a second assertion with a call to `PHPMailer::inlineImageExists()`.
This commit is contained in:
parent
a866bc9eda
commit
e5b07ba3c3
|
|
@ -53,10 +53,42 @@ final class AddEmbeddedImageTest extends PreSendTestCase
|
|||
$this->Mail->clearAttachments();
|
||||
|
||||
//For code coverage
|
||||
$this->Mail->addEmbeddedImage('thisfiledoesntexist', 'xyz'); //Non-existent file
|
||||
$this->Mail->addEmbeddedImage(__FILE__, '123'); //Missing name
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $name Optional. Attachment name to use.
|
||||
* @param string $encoding Optional. File encoding to pass.
|
||||
*/
|
||||
public function testFailToAttach($path, $cid, $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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dataFailToAttach()
|
||||
{
|
||||
return [
|
||||
'Invalid: non-existent file' => [
|
||||
'path' => 'thisfiledoesntexist',
|
||||
'cid' => 'xyz',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Expect exceptions on bad encoding
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue