update v1.0.3.3
This commit is contained in:
42
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug111Test.php
vendored
Normal file
42
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug111Test.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class Swift_Bug111Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testUnstructuredHeaderSlashesShouldNotBeEscaped()
|
||||
{
|
||||
$complicated_header = array(
|
||||
'to' => array(
|
||||
'email1@example.com',
|
||||
'email2@example.com',
|
||||
'email3@example.com',
|
||||
'email4@example.com',
|
||||
'email5@example.com',
|
||||
),
|
||||
'sub' => array(
|
||||
'-name-' => array(
|
||||
'email1',
|
||||
'"email2"',
|
||||
'email3\\',
|
||||
'email4',
|
||||
'email5',
|
||||
),
|
||||
'-url-' => array(
|
||||
'http://google.com',
|
||||
'http://yahoo.com',
|
||||
'http://hotmail.com',
|
||||
'http://aol.com',
|
||||
'http://facebook.com',
|
||||
),
|
||||
),
|
||||
);
|
||||
$json = json_encode($complicated_header);
|
||||
|
||||
$message = new Swift_Message();
|
||||
$headers = $message->getHeaders();
|
||||
$headers->addTextHeader('X-SMTPAPI', $json);
|
||||
$header = $headers->get('X-SMTPAPI');
|
||||
|
||||
$this->assertEquals('Swift_Mime_Headers_UnstructuredHeader', get_class($header));
|
||||
$this->assertEquals($json, $header->getFieldBody());
|
||||
}
|
||||
}
|
||||
20
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug118Test.php
vendored
Normal file
20
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug118Test.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
class Swift_Bug118Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_message;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_message = new Swift_Message();
|
||||
}
|
||||
|
||||
public function testCallingGenerateIdChangesTheMessageId()
|
||||
{
|
||||
$currentId = $this->_message->getId();
|
||||
$this->_message->generateId();
|
||||
$newId = $this->_message->getId();
|
||||
|
||||
$this->assertNotEquals($currentId, $newId);
|
||||
}
|
||||
}
|
||||
38
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug206Test.php
vendored
Normal file
38
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug206Test.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
class Swift_Bug206Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_factory;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
|
||||
$headerEncoder = new Swift_Mime_HeaderEncoder_QpHeaderEncoder(
|
||||
new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
|
||||
);
|
||||
$paramEncoder = new Swift_Encoder_Rfc2231Encoder(
|
||||
new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
|
||||
);
|
||||
$grammar = new Swift_Mime_Grammar();
|
||||
$this->_factory = new Swift_Mime_SimpleHeaderFactory($headerEncoder, $paramEncoder, $grammar);
|
||||
}
|
||||
|
||||
public function testMailboxHeaderEncoding()
|
||||
{
|
||||
$this->_testHeaderIsFullyEncoded('email@example.org', 'Family Name, Name', ' "Family Name, Name" <email@example.org>');
|
||||
$this->_testHeaderIsFullyEncoded('email@example.org', 'Family Namé, Name', ' Family =?utf-8?Q?Nam=C3=A9=2C?= Name');
|
||||
$this->_testHeaderIsFullyEncoded('email@example.org', 'Family Namé , Name', ' Family =?utf-8?Q?Nam=C3=A9_=2C?= Name');
|
||||
$this->_testHeaderIsFullyEncoded('email@example.org', 'Family Namé ;Name', ' Family =?utf-8?Q?Nam=C3=A9_=3BName?= ');
|
||||
}
|
||||
|
||||
private function _testHeaderIsFullyEncoded($email, $name, $expected)
|
||||
{
|
||||
$mailboxHeader = $this->_factory->createMailboxHeader('To', array(
|
||||
$email => $name,
|
||||
));
|
||||
|
||||
$headerBody = substr($mailboxHeader->toString(), 3, strlen($expected));
|
||||
|
||||
$this->assertEquals($expected, $headerBody);
|
||||
}
|
||||
}
|
||||
21
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug274Test.php
vendored
Normal file
21
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug274Test.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
class Swift_Bug274Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEmptyFileNameAsAttachement()
|
||||
{
|
||||
$message = new Swift_Message();
|
||||
$this->setExpectedException('Swift_IoException', 'The path cannot be empty');
|
||||
$message->attach(Swift_Attachment::fromPath(''));
|
||||
}
|
||||
|
||||
public function testNonEmptyFileNameAsAttachement()
|
||||
{
|
||||
$message = new Swift_Message();
|
||||
try {
|
||||
$message->attach(Swift_Attachment::fromPath(__FILE__));
|
||||
} catch (Exception $e) {
|
||||
$this->fail('Path should not be empty');
|
||||
}
|
||||
}
|
||||
}
|
||||
75
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug34Test.php
vendored
Normal file
75
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug34Test.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
class Swift_Bug34Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
Swift_Preferences::getInstance()->setCharset('utf-8');
|
||||
}
|
||||
|
||||
public function testEmbeddedFilesWithMultipartDataCreateMultipartRelatedContentAsAnAlternative()
|
||||
{
|
||||
$message = Swift_Message::newInstance();
|
||||
$message->setCharset('utf-8');
|
||||
$message->setSubject('test subject');
|
||||
$message->addPart('plain part', 'text/plain');
|
||||
|
||||
$image = Swift_Image::newInstance('<image data>', 'image.gif', 'image/gif');
|
||||
$cid = $message->embed($image);
|
||||
|
||||
$message->setBody('<img src="'.$cid.'" />', 'text/html');
|
||||
|
||||
$message->setTo(array('user@domain.tld' => 'User'));
|
||||
|
||||
$message->setFrom(array('other@domain.tld' => 'Other'));
|
||||
$message->setSender(array('other@domain.tld' => 'Other'));
|
||||
|
||||
$id = $message->getId();
|
||||
$date = preg_quote(date('r', $message->getDate()), '~');
|
||||
$boundary = $message->getBoundary();
|
||||
$cidVal = $image->getId();
|
||||
|
||||
$this->assertRegExp(
|
||||
'~^'.
|
||||
'Sender: Other <other@domain.tld>'."\r\n".
|
||||
'Message-ID: <'.$id.'>'."\r\n".
|
||||
'Date: '.$date."\r\n".
|
||||
'Subject: test subject'."\r\n".
|
||||
'From: Other <other@domain.tld>'."\r\n".
|
||||
'To: User <user@domain.tld>'."\r\n".
|
||||
'MIME-Version: 1.0'."\r\n".
|
||||
'Content-Type: multipart/alternative;'."\r\n".
|
||||
' boundary="'.$boundary.'"'."\r\n".
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary."\r\n".
|
||||
'Content-Type: text/plain; charset=utf-8'."\r\n".
|
||||
'Content-Transfer-Encoding: quoted-printable'."\r\n".
|
||||
"\r\n".
|
||||
'plain part'.
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary."\r\n".
|
||||
'Content-Type: multipart/related;'."\r\n".
|
||||
' boundary="(.*?)"'."\r\n".
|
||||
"\r\n\r\n".
|
||||
'--\\1'."\r\n".
|
||||
'Content-Type: text/html; charset=utf-8'."\r\n".
|
||||
'Content-Transfer-Encoding: quoted-printable'."\r\n".
|
||||
"\r\n".
|
||||
'<img.*?/>'.
|
||||
"\r\n\r\n".
|
||||
'--\\1'."\r\n".
|
||||
'Content-Type: image/gif; name=image.gif'."\r\n".
|
||||
'Content-Transfer-Encoding: base64'."\r\n".
|
||||
'Content-Disposition: inline; filename=image.gif'."\r\n".
|
||||
'Content-ID: <'.$cidVal.'>'."\r\n".
|
||||
"\r\n".
|
||||
preg_quote(base64_encode('<image data>'), '~').
|
||||
"\r\n\r\n".
|
||||
'--\\1--'."\r\n".
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary.'--'."\r\n".
|
||||
'$~D',
|
||||
$message->toString()
|
||||
);
|
||||
}
|
||||
}
|
||||
73
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug35Test.php
vendored
Normal file
73
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug35Test.php
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
class Swift_Bug35Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
Swift_Preferences::getInstance()->setCharset('utf-8');
|
||||
}
|
||||
|
||||
public function testHTMLPartAppearsLastEvenWhenAttachmentsAdded()
|
||||
{
|
||||
$message = Swift_Message::newInstance();
|
||||
$message->setCharset('utf-8');
|
||||
$message->setSubject('test subject');
|
||||
$message->addPart('plain part', 'text/plain');
|
||||
|
||||
$attachment = Swift_Attachment::newInstance('<data>', 'image.gif', 'image/gif');
|
||||
$message->attach($attachment);
|
||||
|
||||
$message->setBody('HTML part', 'text/html');
|
||||
|
||||
$message->setTo(array('user@domain.tld' => 'User'));
|
||||
|
||||
$message->setFrom(array('other@domain.tld' => 'Other'));
|
||||
$message->setSender(array('other@domain.tld' => 'Other'));
|
||||
|
||||
$id = $message->getId();
|
||||
$date = preg_quote(date('r', $message->getDate()), '~');
|
||||
$boundary = $message->getBoundary();
|
||||
|
||||
$this->assertRegExp(
|
||||
'~^'.
|
||||
'Sender: Other <other@domain.tld>'."\r\n".
|
||||
'Message-ID: <'.$id.'>'."\r\n".
|
||||
'Date: '.$date."\r\n".
|
||||
'Subject: test subject'."\r\n".
|
||||
'From: Other <other@domain.tld>'."\r\n".
|
||||
'To: User <user@domain.tld>'."\r\n".
|
||||
'MIME-Version: 1.0'."\r\n".
|
||||
'Content-Type: multipart/mixed;'."\r\n".
|
||||
' boundary="'.$boundary.'"'."\r\n".
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary."\r\n".
|
||||
'Content-Type: multipart/alternative;'."\r\n".
|
||||
' boundary="(.*?)"'."\r\n".
|
||||
"\r\n\r\n".
|
||||
'--\\1'."\r\n".
|
||||
'Content-Type: text/plain; charset=utf-8'."\r\n".
|
||||
'Content-Transfer-Encoding: quoted-printable'."\r\n".
|
||||
"\r\n".
|
||||
'plain part'.
|
||||
"\r\n\r\n".
|
||||
'--\\1'."\r\n".
|
||||
'Content-Type: text/html; charset=utf-8'."\r\n".
|
||||
'Content-Transfer-Encoding: quoted-printable'."\r\n".
|
||||
"\r\n".
|
||||
'HTML part'.
|
||||
"\r\n\r\n".
|
||||
'--\\1--'."\r\n".
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary."\r\n".
|
||||
'Content-Type: image/gif; name=image.gif'."\r\n".
|
||||
'Content-Transfer-Encoding: base64'."\r\n".
|
||||
'Content-Disposition: attachment; filename=image.gif'."\r\n".
|
||||
"\r\n".
|
||||
preg_quote(base64_encode('<data>'), '~').
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary.'--'."\r\n".
|
||||
'$~D',
|
||||
$message->toString()
|
||||
);
|
||||
}
|
||||
}
|
||||
194
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug38Test.php
vendored
Normal file
194
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug38Test.php
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
class Swift_Bug38Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_attFile;
|
||||
private $_attFileName;
|
||||
private $_attFileType;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_attFileName = 'data.txt';
|
||||
$this->_attFileType = 'text/plain';
|
||||
$this->_attFile = __DIR__.'/../../_samples/files/data.txt';
|
||||
Swift_Preferences::getInstance()->setCharset('utf-8');
|
||||
}
|
||||
|
||||
public function testWritingMessageToByteStreamProducesCorrectStructure()
|
||||
{
|
||||
$message = new Swift_Message();
|
||||
$message->setSubject('test subject');
|
||||
$message->setTo('user@domain.tld');
|
||||
$message->setCc('other@domain.tld');
|
||||
$message->setFrom('user@domain.tld');
|
||||
|
||||
$image = new Swift_Image('<data>', 'image.gif', 'image/gif');
|
||||
|
||||
$cid = $message->embed($image);
|
||||
$message->setBody('HTML part', 'text/html');
|
||||
|
||||
$id = $message->getId();
|
||||
$date = preg_quote(date('r', $message->getDate()), '~');
|
||||
$boundary = $message->getBoundary();
|
||||
$imgId = $image->getId();
|
||||
|
||||
$stream = new Swift_ByteStream_ArrayByteStream();
|
||||
|
||||
$message->toByteStream($stream);
|
||||
|
||||
$this->assertPatternInStream(
|
||||
'~^'.
|
||||
'Message-ID: <'.$id.'>'."\r\n".
|
||||
'Date: '.$date."\r\n".
|
||||
'Subject: test subject'."\r\n".
|
||||
'From: user@domain.tld'."\r\n".
|
||||
'To: user@domain.tld'."\r\n".
|
||||
'Cc: other@domain.tld'."\r\n".
|
||||
'MIME-Version: 1.0'."\r\n".
|
||||
'Content-Type: multipart/related;'."\r\n".
|
||||
' boundary="'.$boundary.'"'."\r\n".
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary."\r\n".
|
||||
'Content-Type: text/html; charset=utf-8'."\r\n".
|
||||
'Content-Transfer-Encoding: quoted-printable'."\r\n".
|
||||
"\r\n".
|
||||
'HTML part'.
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary."\r\n".
|
||||
'Content-Type: image/gif; name=image.gif'."\r\n".
|
||||
'Content-Transfer-Encoding: base64'."\r\n".
|
||||
'Content-Disposition: inline; filename=image.gif'."\r\n".
|
||||
'Content-ID: <'.preg_quote($imgId, '~').'>'."\r\n".
|
||||
"\r\n".
|
||||
preg_quote(base64_encode('<data>'), '~').
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary.'--'."\r\n".
|
||||
'$~D',
|
||||
$stream
|
||||
);
|
||||
}
|
||||
|
||||
public function testWritingMessageToByteStreamTwiceProducesCorrectStructure()
|
||||
{
|
||||
$message = new Swift_Message();
|
||||
$message->setSubject('test subject');
|
||||
$message->setTo('user@domain.tld');
|
||||
$message->setCc('other@domain.tld');
|
||||
$message->setFrom('user@domain.tld');
|
||||
|
||||
$image = new Swift_Image('<data>', 'image.gif', 'image/gif');
|
||||
|
||||
$cid = $message->embed($image);
|
||||
$message->setBody('HTML part', 'text/html');
|
||||
|
||||
$id = $message->getId();
|
||||
$date = preg_quote(date('r', $message->getDate()), '~');
|
||||
$boundary = $message->getBoundary();
|
||||
$imgId = $image->getId();
|
||||
|
||||
$pattern = '~^'.
|
||||
'Message-ID: <'.$id.'>'."\r\n".
|
||||
'Date: '.$date."\r\n".
|
||||
'Subject: test subject'."\r\n".
|
||||
'From: user@domain.tld'."\r\n".
|
||||
'To: user@domain.tld'."\r\n".
|
||||
'Cc: other@domain.tld'."\r\n".
|
||||
'MIME-Version: 1.0'."\r\n".
|
||||
'Content-Type: multipart/related;'."\r\n".
|
||||
' boundary="'.$boundary.'"'."\r\n".
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary."\r\n".
|
||||
'Content-Type: text/html; charset=utf-8'."\r\n".
|
||||
'Content-Transfer-Encoding: quoted-printable'."\r\n".
|
||||
"\r\n".
|
||||
'HTML part'.
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary."\r\n".
|
||||
'Content-Type: image/gif; name=image.gif'."\r\n".
|
||||
'Content-Transfer-Encoding: base64'."\r\n".
|
||||
'Content-Disposition: inline; filename=image.gif'."\r\n".
|
||||
'Content-ID: <'.preg_quote($imgId, '~').'>'."\r\n".
|
||||
"\r\n".
|
||||
preg_quote(base64_encode('<data>'), '~').
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary.'--'."\r\n".
|
||||
'$~D'
|
||||
;
|
||||
|
||||
$streamA = new Swift_ByteStream_ArrayByteStream();
|
||||
$streamB = new Swift_ByteStream_ArrayByteStream();
|
||||
|
||||
$message->toByteStream($streamA);
|
||||
$message->toByteStream($streamB);
|
||||
|
||||
$this->assertPatternInStream($pattern, $streamA);
|
||||
$this->assertPatternInStream($pattern, $streamB);
|
||||
}
|
||||
|
||||
public function testWritingMessageToByteStreamTwiceUsingAFileAttachment()
|
||||
{
|
||||
$message = new Swift_Message();
|
||||
$message->setSubject('test subject');
|
||||
$message->setTo('user@domain.tld');
|
||||
$message->setCc('other@domain.tld');
|
||||
$message->setFrom('user@domain.tld');
|
||||
|
||||
$attachment = Swift_Attachment::fromPath($this->_attFile);
|
||||
|
||||
$message->attach($attachment);
|
||||
|
||||
$message->setBody('HTML part', 'text/html');
|
||||
|
||||
$id = $message->getId();
|
||||
$date = preg_quote(date('r', $message->getDate()), '~');
|
||||
$boundary = $message->getBoundary();
|
||||
|
||||
$streamA = new Swift_ByteStream_ArrayByteStream();
|
||||
$streamB = new Swift_ByteStream_ArrayByteStream();
|
||||
|
||||
$pattern = '~^'.
|
||||
'Message-ID: <'.$id.'>'."\r\n".
|
||||
'Date: '.$date."\r\n".
|
||||
'Subject: test subject'."\r\n".
|
||||
'From: user@domain.tld'."\r\n".
|
||||
'To: user@domain.tld'."\r\n".
|
||||
'Cc: other@domain.tld'."\r\n".
|
||||
'MIME-Version: 1.0'."\r\n".
|
||||
'Content-Type: multipart/mixed;'."\r\n".
|
||||
' boundary="'.$boundary.'"'."\r\n".
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary."\r\n".
|
||||
'Content-Type: text/html; charset=utf-8'."\r\n".
|
||||
'Content-Transfer-Encoding: quoted-printable'."\r\n".
|
||||
"\r\n".
|
||||
'HTML part'.
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary."\r\n".
|
||||
'Content-Type: '.$this->_attFileType.'; name='.$this->_attFileName."\r\n".
|
||||
'Content-Transfer-Encoding: base64'."\r\n".
|
||||
'Content-Disposition: attachment; filename='.$this->_attFileName."\r\n".
|
||||
"\r\n".
|
||||
preg_quote(base64_encode(file_get_contents($this->_attFile)), '~').
|
||||
"\r\n\r\n".
|
||||
'--'.$boundary.'--'."\r\n".
|
||||
'$~D'
|
||||
;
|
||||
|
||||
$message->toByteStream($streamA);
|
||||
$message->toByteStream($streamB);
|
||||
|
||||
$this->assertPatternInStream($pattern, $streamA);
|
||||
$this->assertPatternInStream($pattern, $streamB);
|
||||
}
|
||||
|
||||
// -- Helpers
|
||||
|
||||
public function assertPatternInStream($pattern, $stream, $message = '%s')
|
||||
{
|
||||
$string = '';
|
||||
while (false !== $bytes = $stream->read(8192)) {
|
||||
$string .= $bytes;
|
||||
}
|
||||
$this->assertRegExp($pattern, $string, $message);
|
||||
}
|
||||
}
|
||||
38
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug518Test.php
vendored
Normal file
38
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug518Test.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Mockery as m;
|
||||
|
||||
class Swift_Bug518Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testIfEmailChangesAfterQueued()
|
||||
{
|
||||
$failedRecipients = 'value';
|
||||
$message = new Swift_Message();
|
||||
$message->setTo('foo@bar.com');
|
||||
|
||||
$that = $this;
|
||||
$messageValidation = function ($m) use ($that) {
|
||||
//the getTo should return the same value as we put in
|
||||
$that->assertEquals('foo@bar.com', key($m->getTo()), 'The message has changed after it was put to the memory queue');
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
$transport = m::mock('Swift_Transport');
|
||||
$transport->shouldReceive('isStarted')->andReturn(true);
|
||||
$transport->shouldReceive('send')
|
||||
->with(m::on($messageValidation), $failedRecipients)
|
||||
->andReturn(1);
|
||||
|
||||
$memorySpool = new Swift_MemorySpool();
|
||||
$memorySpool->queueMessage($message);
|
||||
|
||||
/*
|
||||
* The message is queued in memory.
|
||||
* Lets change the message
|
||||
*/
|
||||
$message->setTo('other@value.com');
|
||||
|
||||
$memorySpool->flushQueue($transport, $failedRecipients);
|
||||
}
|
||||
}
|
||||
121
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug51Test.php
vendored
Normal file
121
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug51Test.php
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
class Swift_Bug51Test extends \SwiftMailerTestCase
|
||||
{
|
||||
private $_attachmentFile;
|
||||
private $_outputFile;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
if (!defined('SWIFT_TMP_DIR') || !is_writable(SWIFT_TMP_DIR)) {
|
||||
$this->markTestSkipped(
|
||||
'Cannot run test without a writable directory to use ('.
|
||||
'define SWIFT_TMP_DIR in tests/config.php if you wish to run this test)'
|
||||
);
|
||||
}
|
||||
|
||||
$this->_attachmentFile = SWIFT_TMP_DIR.'/attach.rand.bin';
|
||||
file_put_contents($this->_attachmentFile, '');
|
||||
|
||||
$this->_outputFile = SWIFT_TMP_DIR.'/attach.out.bin';
|
||||
file_put_contents($this->_outputFile, '');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
unlink($this->_attachmentFile);
|
||||
unlink($this->_outputFile);
|
||||
}
|
||||
|
||||
public function testAttachmentsDoNotGetTruncatedUsingToByteStream()
|
||||
{
|
||||
//Run 100 times with 10KB attachments
|
||||
for ($i = 0; $i < 10; ++$i) {
|
||||
$message = $this->_createMessageWithRandomAttachment(
|
||||
10000, $this->_attachmentFile
|
||||
);
|
||||
|
||||
file_put_contents($this->_outputFile, '');
|
||||
$message->toByteStream(
|
||||
new Swift_ByteStream_FileByteStream($this->_outputFile, true)
|
||||
);
|
||||
|
||||
$emailSource = file_get_contents($this->_outputFile);
|
||||
|
||||
$this->assertAttachmentFromSourceMatches(
|
||||
file_get_contents($this->_attachmentFile),
|
||||
$emailSource
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testAttachmentsDoNotGetTruncatedUsingToString()
|
||||
{
|
||||
//Run 100 times with 10KB attachments
|
||||
for ($i = 0; $i < 10; ++$i) {
|
||||
$message = $this->_createMessageWithRandomAttachment(
|
||||
10000, $this->_attachmentFile
|
||||
);
|
||||
|
||||
$emailSource = $message->toString();
|
||||
|
||||
$this->assertAttachmentFromSourceMatches(
|
||||
file_get_contents($this->_attachmentFile),
|
||||
$emailSource
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// -- Custom Assertions
|
||||
|
||||
public function assertAttachmentFromSourceMatches($attachmentData, $source)
|
||||
{
|
||||
$encHeader = 'Content-Transfer-Encoding: base64';
|
||||
$base64declaration = strpos($source, $encHeader);
|
||||
|
||||
$attachmentDataStart = strpos($source, "\r\n\r\n", $base64declaration);
|
||||
$attachmentDataEnd = strpos($source, "\r\n--", $attachmentDataStart);
|
||||
|
||||
if (false === $attachmentDataEnd) {
|
||||
$attachmentBase64 = trim(substr($source, $attachmentDataStart));
|
||||
} else {
|
||||
$attachmentBase64 = trim(substr(
|
||||
$source, $attachmentDataStart,
|
||||
$attachmentDataEnd - $attachmentDataStart
|
||||
));
|
||||
}
|
||||
|
||||
$this->assertIdenticalBinary($attachmentData, base64_decode($attachmentBase64));
|
||||
}
|
||||
|
||||
// -- Creation Methods
|
||||
|
||||
private function _fillFileWithRandomBytes($byteCount, $file)
|
||||
{
|
||||
// I was going to use dd with if=/dev/random but this way seems more
|
||||
// cross platform even if a hella expensive!!
|
||||
|
||||
file_put_contents($file, '');
|
||||
$fp = fopen($file, 'wb');
|
||||
for ($i = 0; $i < $byteCount; ++$i) {
|
||||
$byteVal = rand(0, 255);
|
||||
fwrite($fp, pack('i', $byteVal));
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
private function _createMessageWithRandomAttachment($size, $attachmentPath)
|
||||
{
|
||||
$this->_fillFileWithRandomBytes($size, $attachmentPath);
|
||||
|
||||
$message = Swift_Message::newInstance()
|
||||
->setSubject('test')
|
||||
->setBody('test')
|
||||
->setFrom('a@b.c')
|
||||
->setTo('d@e.f')
|
||||
->attach(Swift_Attachment::fromPath($attachmentPath))
|
||||
;
|
||||
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
38
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug534Test.php
vendored
Normal file
38
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug534Test.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Mockery as m;
|
||||
|
||||
class Swift_Bug534Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEmbeddedImagesAreEmbedded()
|
||||
{
|
||||
$message = Swift_Message::newInstance()
|
||||
->setFrom('from@example.com')
|
||||
->setTo('to@example.com')
|
||||
->setSubject('test')
|
||||
;
|
||||
$cid = $message->embed(Swift_Image::fromPath(__DIR__.'/../../_samples/files/swiftmailer.png'));
|
||||
$message->setBody('<img src="'.$cid.'" />', 'text/html');
|
||||
|
||||
$that = $this;
|
||||
$messageValidation = function (Swift_Mime_Message $message) use ($that) {
|
||||
preg_match('/cid:(.*)"/', $message->toString(), $matches);
|
||||
$cid = $matches[1];
|
||||
preg_match('/Content-ID: <(.*)>/', $message->toString(), $matches);
|
||||
$contentId = $matches[1];
|
||||
$that->assertEquals($cid, $contentId, 'cid in body and mime part Content-ID differ');
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
$failedRecipients = array();
|
||||
|
||||
$transport = m::mock('Swift_Transport');
|
||||
$transport->shouldReceive('isStarted')->andReturn(true);
|
||||
$transport->shouldReceive('send')->with(m::on($messageValidation), $failedRecipients)->andReturn(1);
|
||||
|
||||
$memorySpool = new Swift_MemorySpool();
|
||||
$memorySpool->queueMessage($message);
|
||||
$memorySpool->flushQueue($transport, $failedRecipients);
|
||||
}
|
||||
}
|
||||
20
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug71Test.php
vendored
Normal file
20
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug71Test.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
class Swift_Bug71Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_message;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_message = new Swift_Message('test');
|
||||
}
|
||||
|
||||
public function testCallingToStringAfterSettingNewBodyReflectsChanges()
|
||||
{
|
||||
$this->_message->setBody('BODY1');
|
||||
$this->assertRegExp('/BODY1/', $this->_message->toString());
|
||||
|
||||
$this->_message->setBody('BODY2');
|
||||
$this->assertRegExp('/BODY2/', $this->_message->toString());
|
||||
}
|
||||
}
|
||||
82
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug76Test.php
vendored
Normal file
82
vendor/swiftmailer/swiftmailer/tests/bug/Swift/Bug76Test.php
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
class Swift_Bug76Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_inputFile;
|
||||
private $_outputFile;
|
||||
private $_encoder;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
if (!defined('SWIFT_TMP_DIR') || !is_writable(SWIFT_TMP_DIR)) {
|
||||
$this->markTestSkipped(
|
||||
'Cannot run test without a writable directory to use ('.
|
||||
'define SWIFT_TMP_DIR in tests/config.php if you wish to run this test)'
|
||||
);
|
||||
}
|
||||
|
||||
$this->_inputFile = SWIFT_TMP_DIR.'/in.bin';
|
||||
file_put_contents($this->_inputFile, '');
|
||||
|
||||
$this->_outputFile = SWIFT_TMP_DIR.'/out.bin';
|
||||
file_put_contents($this->_outputFile, '');
|
||||
|
||||
$this->_encoder = $this->_createEncoder();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
unlink($this->_inputFile);
|
||||
unlink($this->_outputFile);
|
||||
}
|
||||
|
||||
public function testBase64EncodedLineLengthNeverExceeds76CharactersEvenIfArgsDo()
|
||||
{
|
||||
$this->_fillFileWithRandomBytes(1000, $this->_inputFile);
|
||||
|
||||
$os = $this->_createStream($this->_inputFile);
|
||||
$is = $this->_createStream($this->_outputFile);
|
||||
|
||||
$this->_encoder->encodeByteStream($os, $is, 0, 80); //Exceeds 76
|
||||
|
||||
$this->assertMaxLineLength(76, $this->_outputFile,
|
||||
'%s: Line length should not exceed 76 characters'
|
||||
);
|
||||
}
|
||||
|
||||
// -- Custom Assertions
|
||||
|
||||
public function assertMaxLineLength($length, $filePath, $message = '%s')
|
||||
{
|
||||
$lines = file($filePath);
|
||||
foreach ($lines as $line) {
|
||||
$this->assertTrue((strlen(trim($line)) <= 76), $message);
|
||||
}
|
||||
}
|
||||
|
||||
// -- Creation Methods
|
||||
|
||||
private function _fillFileWithRandomBytes($byteCount, $file)
|
||||
{
|
||||
// I was going to use dd with if=/dev/random but this way seems more
|
||||
// cross platform even if a hella expensive!!
|
||||
|
||||
file_put_contents($file, '');
|
||||
$fp = fopen($file, 'wb');
|
||||
for ($i = 0; $i < $byteCount; ++$i) {
|
||||
$byteVal = rand(0, 255);
|
||||
fwrite($fp, pack('i', $byteVal));
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
private function _createEncoder()
|
||||
{
|
||||
return new Swift_Mime_ContentEncoder_Base64ContentEncoder();
|
||||
}
|
||||
|
||||
private function _createStream($file)
|
||||
{
|
||||
return new Swift_ByteStream_FileByteStream($file, true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user