Fragment gemist bijna af

This commit is contained in:
2020-01-06 02:36:10 +01:00
parent 150d0179fc
commit ed1871ae68
6310 changed files with 727834 additions and 1 deletions

View File

@@ -0,0 +1,62 @@
<?php
/**
* A binary safe string comparison.
*
* @author Chris Corbyn
*/
class IdenticalBinaryConstraint extends \PHPUnit_Framework_Constraint
{
protected $value;
public function __construct($value)
{
$this->value = $value;
}
/**
* Evaluates the constraint for parameter $other. Returns TRUE if the
* constraint is met, FALSE otherwise.
*
* @param mixed $other Value or object to evaluate.
*
* @return bool
*/
public function matches($other)
{
$aHex = $this->asHexString($this->value);
$bHex = $this->asHexString($other);
return $aHex === $bHex;
}
/**
* Returns a string representation of the constraint.
*
* @return string
*/
public function toString()
{
return 'indentical binary';
}
/**
* Get the given string of bytes as a stirng of Hexadecimal sequences.
*
* @param string $binary
*
* @return string
*/
private function asHexString($binary)
{
$hex = '';
$bytes = unpack('H*', $binary);
foreach ($bytes as &$byte) {
$byte = strtoupper($byte);
}
return implode('', $bytes);
}
}

View File

@@ -0,0 +1,11 @@
<?php
class Swift_StreamCollector
{
public $content = '';
public function __invoke($arg)
{
$this->content .= $arg;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* Base test for smoke tests.
*
* @author Rouven Weßling
*/
class SwiftMailerSmokeTestCase extends SwiftMailerTestCase
{
protected function setUp()
{
if (!defined('SWIFT_SMOKE_TRANSPORT_TYPE')) {
$this->markTestSkipped(
'Smoke tests are skipped if tests/smoke.conf.php is not edited'
);
}
}
protected function _getMailer()
{
switch (SWIFT_SMOKE_TRANSPORT_TYPE) {
case 'smtp':
$transport = Swift_DependencyContainer::getInstance()->lookup('transport.smtp')
->setHost(SWIFT_SMOKE_SMTP_HOST)
->setPort(SWIFT_SMOKE_SMTP_PORT)
->setUsername(SWIFT_SMOKE_SMTP_USER)
->setPassword(SWIFT_SMOKE_SMTP_PASS)
->setEncryption(SWIFT_SMOKE_SMTP_ENCRYPTION)
;
break;
case 'sendmail':
$transport = Swift_DependencyContainer::getInstance()->lookup('transport.sendmail')
->setCommand(SWIFT_SMOKE_SENDMAIL_COMMAND)
;
break;
case 'mail':
case 'nativemail':
$transport = Swift_DependencyContainer::getInstance()->lookup('transport.mail');
break;
default:
throw new Exception('Undefined transport ['.SWIFT_SMOKE_TRANSPORT_TYPE.']');
}
return new Swift_Mailer($transport);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* A base test case with some custom expectations.
*
* @author Rouven Weßling
*/
class SwiftMailerTestCase extends \PHPUnit_Framework_TestCase
{
public static function regExp($pattern)
{
if (!is_string($pattern)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
}
return new PHPUnit_Framework_Constraint_PCREMatch($pattern);
}
public function assertIdenticalBinary($expected, $actual, $message = '')
{
$constraint = new IdenticalBinaryConstraint($expected);
self::assertThat($actual, $constraint, $message);
}
protected function tearDown()
{
\Mockery::close();
}
protected function getMockery($class)
{
return \Mockery::mock($class);
}
}

View File

@@ -0,0 +1,11 @@
ISO-2022-JPは、インターネット上(特に電子メール)などで使われる日本の文字用の文字符号化方式。ISO/IEC 2022のエスケープシーケンスを利用して文字集合を切り替える7ビットのコードであることを特徴とする (アナウンス機能のエスケープシーケンスは省略される)。俗に「JISコード」と呼ばれることもある。
概要
日本語表記への利用が想定されている文字コードであり、日本語の利用されるネットワークにおいて、日本の規格を応用したものである。また文字集合としては、日本語で用いられる漢字、ひらがな、カタカナはもちろん、ラテン文字、ギリシア文字、キリル文字なども含んでおり、学術や産業の分野での利用も考慮たものとなっている。規格名に、ISOの日本語の言語コードであるjaではなく、国・地域名コードのJPが示されているゆえんである。
文字集合としてJIS X 0201のC0集合制御文字、JIS X 0201のラテン文字集合、ISO 646の国際基準版図形文字、JIS X 0208の1978年版JIS C 6226-1978と1983年および1990年版が利用できる。JIS X 0201の片仮名文字集合は利用できない。1986年以降、日本の電子メールで用いられてきたJUNETコードを、村井純・Mark Crispin・Erik van der Poelが1993年にRFC化したもの(RFC 1468)。後にJIS X 0208:1997の附属書2としてJISに規定された。MIMEにおける文字符号化方式の識別用の名前として IANA に登録されている。
なお、符号化の仕様についてはISO/IEC 2022#ISO-2022-JPも参照。
ISO-2022-JPと非標準的拡張使用
「JISコード」または「ISO-2022-JP」というコード名の規定下では、その仕様通りの使用が求められる。しかし、Windows OS上では、実際にはCP932コード (MicrosoftによるShift JISを拡張した亜種。ISO-2022-JP規定外文字が追加されている。による独自拡張の文字を断りなく使うアプリケーションが多い。この例としてInternet ExplorerやOutlook Expressがある。また、EmEditor、秀丸エディタやThunderbirdのようなMicrosoft社以外のWindowsアプリケーションでも同様の場合がある。この場合、ISO-2022-JPの範囲外の文字を使ってしまうと、異なる製品間では未定義不明文字として認識されるか、もしくは文字化けを起こす原因となる。そのため、Windows用の電子メールクライアントであっても独自拡張の文字を使用すると警告を出したり、あえて使えないように制限しているものも存在する。さらにはISO-2022-JPの範囲内であってもCP932は非標準文字FULLWIDTH TILDE等を持つので文字化けの原因になり得る。
また、符号化方式名をISO-2022-JPとしているのに、文字集合としてはJIS X 0212 (いわゆる補助漢字) やJIS X 0201の片仮名文字集合 (いわゆる半角カナ) をも符号化している例があるが、ISO-2022-JPではこれらの文字を許容していない。これらの符号化は独自拡張の実装であり、中にはISO/IEC 2022の仕様に準拠すらしていないものもある[2]。従って受信側の電子メールクライアントがこれらの独自拡張に対応していない場合、その文字あるいはその文字を含む行、時にはテキスト全体が文字化けすることがある。

View File

@@ -0,0 +1,19 @@
Op mat eraus hinnen beschte, rou zënne schaddreg ké. Ké sin Eisen Kaffi prächteg, den haut esou Fielse wa, Well zielen d'Welt am dir. Aus grousse rëschten d'Stroos do, as dat Kléder gewëss d'Kàchen. Schied gehéiert d'Vioule net hu, rou ke zënter Säiten d'Hierz. Ze eise Fletschen mat, gei as gréng d'Lëtzebuerger. Wäit räich no mat.
Säiten d'Liewen aus en. Un gëtt bléit lossen wee, da wéi alle weisen Kolrettchen. Et deser d'Pan d'Kirmes vun, en wuel Benn rëschten méi. En get drem ménger beschte, da wär Stad welle. Nun Dach d'Pied do, mä gét ruffen gehéiert. Ze onser ugedon fir, d'Liewen Plett'len ech no, si Räis wielen bereet wat. Iwer spilt fir jo.
An hin däischter Margréitchen, eng ke Frot brommt, vu den Räis néierens. Da hir Hunn Frot nozegon, rout Fläiß Himmel zum si, net gutt Kaffi Gesträich fu. Vill lait Gaart sou wa, Land Mamm Schuebersonndeg rei do. Gei geet Minutt en, gei d'Leit beschte Kolrettchen et, Mamm fergiess un hun.
Et gutt Heck kommen oft, Lann rëscht rei um, Hunn rëscht schéinste ke der. En lait zielen schnéiwäiss hir, fu rou botze éiweg Minutt, rem fest gudden schaddreg en. Noper bereet Margréitchen mat op, dem denkt d'Leit d'Vioule no, oft ké Himmel Hämmel. En denkt blénken Fréijor net, Gart Schiet d'Natur no wou. No hin Ierd Frot d'Kirmes. Hire aremt un rou, ké den éiweg wielen Milliounen.
Mir si Hunn Blénkeg. Ké get ston derfir d'Kàchen. Haut d'Pan fu ons, dé frou löschteg d'Meereische rei. Sou op wuel Léift. Stret schlon grousse gin hu. Mä denkt d'Leit hinnen net, ké gét haut fort rëscht.
Koum d'Pan hannendrun ass ké, ké den brét Kaffi geplot. Schéi Hären d'Pied fu gét, do d'Mier néierens bei. Rëm päift Hämmel am, wee Engel beschéngt mä. Brommt klinzecht der ke, wa rout jeitzt dén. Get Zalot d'Vioule däischter da, jo fir Bänk päift duerch, bei d'Beem schéinen Plett'len jo. Den haut Faarwen ze, eng en Biereg Kirmesdag, um sin alles Faarwen d'Vioule.
Eng Hunn Schied et, wat wa Frot fest gebotzt. Bei jo bleiwe ruffen Klarinett. Un Feld klinzecht gét, rifft Margréitchen rem ke. Mir dé Noper duurch gewëss, ston sech kille sin en. Gei Stret d'Wise um, Haus Gart wee as. Monn ménger an blo, wat da Gart gefällt Hämmelsbrot.
Brommt geplot och ze, dat wa Räis Well Kaffi. Do get spilt prächteg, as wär kille bleiwe gewalteg. Onser frësch Margréitchen rem ke, blo en huet ugedon. Onser Hemecht wär de, hu eraus d'Sonn dat, eise deser hannendrun da och.
As durch Himmel hun, no fest iw'rem schéinste mir, Hunn séngt Hierz ke zum. Séngt iw'rem d'Natur zum an. Ke wär gutt Grénge. Kënnt gudden prächteg mä rei. Dé dir Blénkeg Klarinett Kolrettchen, da fort muerges d'Kanner wou, main Feld ruffen vu wéi. Da gin esou Zalot gewalteg, gét vill Hemecht blénken dé.
Haut gréng nun et, nei vu Bass gréng d'Gaassen. Fest d'Beem uechter si gin. Oft vu sinn wellen kréien. Et ass lait Zalot schéinen.

View File

@@ -0,0 +1,22 @@
Код одно гринспана руководишь на. Его вы знания движение. Ты две начать
одиночку, сказать основатель удовольствием но миф. Бы какие система тем.
Полностью использует три мы, человек клоунов те нас, бы давать творческую
эзотерическая шеф.
Мог не помнить никакого сэкономленного, две либо какие пишите бы. Должен
компанию кто те, этот заключалась проектировщик не ты. Глупые периоды ты
для. Вам который хороший он. Те любых кремния концентрируются мог,
собирать принадлежите без вы.
Джоэла меньше хорошего вы миф, за тем году разработки. Даже управляющим
руководители был не. Три коде выпускать заботиться ну. То его система
удовольствием безостановочно, или ты главной процессорах. Мы без джоэл
знания получат, статьи остальные мы ещё.
Них русском касается поскольку по, образование должником
систематизированный ну мои. Прийти кандидата университет но нас, для бы
должны никакого, биг многие причин интервьюирования за.
Тем до плиту почему. Вот учёт такие одного бы, об биг разным внешних
промежуток. Вас до какому возможностей безответственный, были погодите бы
его, по них глупые долгий количества.

View File

@@ -0,0 +1,45 @@
Αν ήδη διάβασε γλιτώσει μεταγλωτίσει, αυτήν θυμάμαι μου μα. Την κατάσταση χρησιμοποίησέ να! Τα διαφορά φαινόμενο διολισθήσεις πες, υψηλότερη προκαλείς περισσότερες όχι κι. Με ελέγχου γίνεται σας, μικρής δημιουργούν τη του. Τις τα γράψει εικόνες απαράδεκτη?
Να ότι πρώτοι απαραίτητο. Άμεση πετάνε κακόκεφος τον ώς, να χώρου πιθανότητες του. Το μέχρι ορίστε λιγότερους σας. Πω ναί φυσικά εικόνες.
Μου οι κώδικα αποκλειστικούς, λες το μάλλον συνεχώς. Νέου σημεία απίστευτα σας μα. Χρόνου μεταγλωτιστής σε νέα, τη τις πιάνει μπορούσες προγραμματιστές. Των κάνε βγαίνει εντυπωσιακό τα? Κρατάει τεσσαρών δυστυχώς της κι, ήδη υψηλότερη εξακολουθεί τα?
Ώρα πετάνε μπορούσε λιγότερους αν, τα απαράδεκτη συγχωνευτεί ροή. Τη έγραψες συνηθίζουν σαν. Όλα με υλικό στήλες χειρότερα. Ανώδυνη δουλέψει επί ως, αν διαδίκτυο εσωτερικών παράγοντες από. Κεντρικό επιτυχία πες το.
Πω ναι λέει τελειώσει, έξι ως έργων τελειώσει. Με αρχεία βουτήξουν ανταγωνιστής ώρα, πολύ γραφικά σελίδων τα στη. Όρο οέλεγχος δημιουργούν δε, ας θέλεις ελέγχου συντακτικό όρο! Της θυμάμαι επιδιόρθωση τα. Για μπορούσε περισσότερο αν, μέγιστη σημαίνει αποφάσισε τα του, άτομο αποτελέσει τι στα.
Τι στην αφήσεις διοίκηση στη. Τα εσφαλμένη δημιουργια επιχείριση έξι! Βήμα μαγικά εκτελέσει ανά τη. Όλη αφήσεις συνεχώς εμπορικά αν, το λες κόλπα επιτυχία. Ότι οι ζώνη κειμένων. Όρο κι ρωτάει γραμμής πελάτες, τελειώσει διολισθήσεις καθυστερούσε αν εγώ? Τι πετούν διοίκηση προβλήματα ήδη.
Τη γλιτώσει αποθηκευτικού μια. Πω έξι δημιουργια πιθανότητες, ως πέντε ελέγχους εκτελείται λες. Πως ερωτήσεις διοικητικό συγκεντρωμένοι οι, ας συνεχώς διοικητικό αποστηθίσει σαν. Δε πρώτες συνεχώς διολισθήσεις έχω, από τι κανένας βουτήξουν, γειτονιάς προσεκτικά ανταγωνιστής κι σαν.
Δημιουργια συνηθίζουν κλπ τι? Όχι ποσοστό διακοπής κι. Κλπ φακέλους δεδομένη εξοργιστικά θα? Υποψήφιο καθορίζουν με όλη, στα πήρε προσοχή εταιρείες πω, ώς τον συνάδελφος διοικητικό δημιουργήσεις! Δούλευε επιτίθενται σας θα, με ένας παραγωγικής ένα, να ναι σημεία μέγιστη απαράδεκτη?
Σας τεσσαρών συνεντεύξης τη, αρπάζεις σίγουρος μη για', επί τοπικές εντολές ακούσει θα? Ως δυστυχής μεταγλωτιστής όλη, να την είχαν σφάλμα απαραίτητο! Μην ώς άτομο διορθώσει χρησιμοποιούνταν. Δεν τα κόλπα πετάξαμε, μη που άγχος υόρκη άμεση, αφού δυστυχώς διακόψουμε όρο αν! Όλη μαγικά πετάνε επιδιορθώσεις δε, ροή φυσικά αποτελέσει πω.
Άπειρα παραπάνω φαινόμενο πω ώρα, σαν πόρτες κρατήσουν συνηθίζουν ως. Κι ώρα τρέξει είχαμε εφαρμογή. Απλό σχεδιαστής μεταγλωτιστής ας επί, τις τα όταν έγραψες γραμμής? Όλα κάνεις συνάδελφος εργαζόμενοι θα, χαρτιού χαμηλός τα ροή. Ως ναι όροφο έρθει, μην πελάτες αποφάσισε μεταφραστής με, να βιαστικά εκδόσεις αναζήτησης λες. Των φταίει εκθέσεις προσπαθήσεις οι, σπίτι αποστηθίσει ας λες?
Ώς που υπηρεσία απαραίτητο δημιουργείς. Μη άρα χαρά καθώς νύχτας, πω ματ μπουν είχαν. Άμεση δημιουργείς ώς ροή, γράψει γραμμής σίγουρος στα τι! Αν αφού πρώτοι εργαζόμενων ναί.
Άμεση διορθώσεις με δύο? Έχουν παράδειγμα των θα, μου έρθει θυμάμαι περισσότερο το. Ότι θα αφού χρειάζονται περισσότερες. Σαν συνεχώς περίπου οι.
Ώς πρώτης πετάξαμε λες, όρο κι πρώτες ζητήσεις δυστυχής. Ανά χρόνου διακοπή επιχειρηματίες ας, ώς μόλις άτομο χειρότερα όρο, κρατάει σχεδιαστής προσπαθήσεις νέο το. Πουλάς προσθέσει όλη πω, τύπου χαρακτηριστικό εγώ σε, πω πιο δούλευε αναζήτησης? Αναφορά δίνοντας σαν μη, μάθε δεδομένη εσωτερικών με ναι, αναφέρονται περιβάλλοντος ώρα αν. Και λέει απόλαυσε τα, που το όροφο προσπαθούν?
Πάντα χρόνου χρήματα ναι το, σαν σωστά θυμάμαι σκεφτείς τα. Μα αποτελέσει ανεπιθύμητη την, πιο το τέτοιο ατόμου, τη των τρόπο εργαλείων επιδιόρθωσης. Περιβάλλον παραγωγικής σου κι, κλπ οι τύπου κακόκεφους αποστηθίσει, δε των πλέον τρόποι. Πιθανότητες χαρακτηριστικών σας κι, γραφικά δημιουργήσεις μια οι, πω πολλοί εξαρτάται προσεκτικά εδώ. Σταματάς παράγοντες για' ώς, στις ρωτάει το ναι! Καρέκλα ζητήσεις συνδυασμούς τη ήδη!
Για μαγικά συνεχώς ακούσει το. Σταματάς προϊόντα βουτήξουν ώς ροή. Είχαν πρώτες οι ναι, μα λες αποστηθίσει ανακαλύπτεις. Όροφο άλγεβρα παραπάνω εδώ τη, πρόσληψη λαμβάνουν καταλάθος ήδη ας? Ως και εισαγωγή κρατήσουν, ένας κακόκεφους κι μας, όχι κώδικάς παίξουν πω. Πω νέα κρατάει εκφράσουν, τότε τελικών τη όχι, ας της τρέξει αλλάζοντας αποκλειστικούς.
Ένας βιβλίο σε άρα, ναι ως γράψει ταξινομεί διορθώσεις! Εδώ να γεγονός συγγραφείς, ώς ήδη διακόψουμε επιχειρηματίες? Ότι πακέτων εσφαλμένη κι, θα όρο κόλπα παραγωγικής? Αν έχω κεντρικό υψηλότερη, κι δεν ίδιο πετάνε παρατηρούμενη! Που λοιπόν σημαντικό μα, προκαλείς χειροκροτήματα ως όλα, μα επί κόλπα άγχος γραμμές! Δε σου κάνεις βουτήξουν, μη έργων επενδυτής χρησιμοποίησέ στα, ως του πρώτες διάσημα σημαντικό.
Βιβλίο τεράστιο προκύπτουν σαν το, σαν τρόπο επιδιόρθωση ας. Είχαν προσοχή προσπάθεια κι ματ, εδώ ως έτσι σελίδων συζήτηση. Και στην βγαίνει εσφαλμένη με, δυστυχής παράδειγμα δε μας, από σε υόρκη επιδιόρθωσης. Νέα πω νέου πιθανό, στήλες συγγραφείς μπαίνοντας μα για', το ρωτήσει κακόκεφους της? Μου σε αρέσει συγγραφής συγχωνευτεί, μη μου υόρκη ξέχασε διακοπής! Ώς επί αποφάσισε αποκλειστικούς χρησιμοποιώντας, χρήματα σελίδων ταξινομεί ναι με.
Μη ανά γραμμή απόλαυσε, πω ναι μάτσο διασφαλίζεται. Τη έξι μόλις εργάστηκε δημιουργούν, έκδοση αναφορά δυσκολότερο οι νέο. Σας ως μπορούσε παράδειγμα, αν ότι δούλευε μπορούσε αποκλειστικούς, πιο λέει βουτήξουν διορθώσει ως. Έχω τελευταία κακόκεφους ας, όσο εργαζόμενων δημιουργήσεις τα.
Του αν δουλέψει μπορούσε, πετούν χαμηλός εδώ ας? Κύκλο τύπους με που, δεν σε έχουν συνεχώς χειρότερα, τις τι απαράδεκτη συνηθίζουν? Θα μην τους αυτήν, τη ένα πήρε πακέτων, κι προκύπτουν περιβάλλον πως. Μα για δουλέψει απόλαυσε εφαμοργής, ώς εδώ σημαίνει μπορούσες, άμεση ακούσει προσοχή τη εδώ?
Στα δώσε αθόρυβες λιγότερους οι, δε αναγκάζονται αποκλειστικούς όλα! Ας μπουν διοικητικό μια, πάντα ελέγχου διορθώσεις ώς τον. Ότι πήρε κανόνα μα. Που άτομα κάνεις δημιουργίες τα, οι μας αφού κόλπα προγραμματιστής, αφού ωραίο προκύπτουν στα ως. Θέμα χρησιμοποιήσει αν όλα, του τα άλγεβρα σελίδων. Τα ότι ανώδυνη δυστυχώς συνδυασμούς, μας οι πάντα γνωρίζουμε ανταγωνιστής, όχι τα δοκιμάσεις σχεδιαστής! Στην συνεντεύξης επιδιόρθωση πιο τα, μα από πουλάς περιβάλλον παραγωγικής.
Έχουν μεταγλωτίσει σε σας, σε πάντα πρώτης μειώσει των, γράψει ρουτίνα δυσκολότερο ήδη μα? Ταξινομεί διορθώσεις να μας. Θα της προσπαθούν περιεχόμενα, δε έχω τοπικές στέλνοντάς. Ανά δε αλφα άμεση, κάποιο ρωτάει γνωρίζουμε πω στη, φράση μαγικά συνέχεια δε δύο! Αν είχαμε μειώσει ροή, μας μετράει καθυστερούσε επιδιορθώσεις μη. Χάος υόρκη κεντρικό έχω σε, ανά περίπου αναγκάζονται πω.
Όσο επιστρέφουν χρονοδιαγράμματα μη. Πως ωραίο κακόκεφος διαχειριστής ως, τις να διακοπής αναζήτησης. Κάποιο ποσοστό ταξινομεί επί τη? Μάθε άμεση αλλάζοντας δύο με, μου νέου πάντα να.
Πω του δυστυχώς πιθανότητες. Κι ρωτάει υψηλότερη δημιουργια ότι, πω εισαγωγή τελευταία απομόνωση ναι. Των ζητήσεις γνωρίζουμε ώς? Για' μη παραδοτέου αναφέρονται! Ύψος παραγωγικά ροή ως, φυσικά διάβασε εικόνες όσο σε? Δεν υόρκη διορθώσεις επεξεργασία θα, ως μέση σύστημα χρησιμοποιήσει τις.

View File

@@ -0,0 +1,3 @@
रखति आवश्यकत प्रेरना मुख्यतह हिंदी किएलोग असक्षम कार्यलय करते विवरण किके मानसिक दिनांक पुर्व संसाध एवम् कुशलता अमितकुमार प्रोत्साहित जनित देखने उदेशीत विकसित बलवान ब्रौशर किएलोग विश्लेषण लोगो कैसे जागरुक प्रव्रुति प्रोत्साहित सदस्य आवश्यकत प्रसारन उपलब्धता अथवा हिंदी जनित दर्शाता यन्त्रालय बलवान अतित सहयोग शुरुआत सभीकुछ माहितीवानीज्य लिये खरिदे है।अभी एकत्रित सम्पर्क रिती मुश्किल प्राथमिक भेदनक्षमता विश्व उन्हे गटको द्वारा तकरीबन
विश्व द्वारा व्याख्या सके। आजपर वातावरण व्याख्यान पहोच। हमारी कीसे प्राथमिक विचारशिलता पुर्व करती कम्प्युटर भेदनक्षमता लिये बलवान और्४५० यायेका वार्तालाप सुचना भारत शुरुआत लाभान्वित पढाए संस्था वर्णित मार्गदर्शन चुनने

View File

@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXAIB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DH7xDQzekl9wIDAQAB
-----END PUBLIC KEY-----

View File

@@ -0,0 +1 @@
<data>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@@ -0,0 +1 @@
D42DA34CF90FA0DE

View File

@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDazCCAlOgAwIBAgIJAKJCGQYLxWT1MA0GCSqGSIb3DQEBBQUAMEwxFzAVBgNV
BAMMDlN3aWZ0bWFpbGVyIENBMRQwEgYDVQQKDAtTd2lmdG1haWxlcjEOMAwGA1UE
BwwFUGFyaXMxCzAJBgNVBAYTAkZSMB4XDTEzMTEyNzA4MzkxMFoXDTE3MTEyNjA4
MzkxMFowTDEXMBUGA1UEAwwOU3dpZnRtYWlsZXIgQ0ExFDASBgNVBAoMC1N3aWZ0
bWFpbGVyMQ4wDAYDVQQHDAVQYXJpczELMAkGA1UEBhMCRlIwggEiMA0GCSqGSIb3
DQEBAQUAA4IBDwAwggEKAoIBAQC7RLdHE3OWo9aZwv1xA/cYyPui/gegxpTqClRp
gGcVQ+jxIfnJQDQndyoAvFDiqOiZ+gAjZGJeUHDp9C/2IZp05MLh+omt9N8pBykm
3nj/3ZwPXOAO0uyDPAOHhISITAxEuZCqDnq7iYujywtwfQ7bpW1hCK9PfNZYMStM
kw7LsGr5BqcKkPuOWTvxE3+NqK8HxydYolsoApEGhgonyImVh1Pg1Kjkt5ojvwAX
zOdjfw5poY5NArwuLORUH+XocetRo8DC6S42HkU/MoqcYxa9EuRuwuQh7GtE6baR
PgrDsEYaY4Asy43sK81V51F/8Q1bHZKN/goQdxQwzv+/nOLTAgMBAAGjUDBOMB0G
A1UdDgQWBBRHgqkl543tKhsVAvcx1I0JFU7JuDAfBgNVHSMEGDAWgBRHgqkl543t
KhsVAvcx1I0JFU7JuDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQAz
OJiEQcygKGkkXXDiXGBvP/cSznj3nG9FolON0yHUBgdvLfNnctRMStGzPke0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fxGBlCl05rmWex++/h5E5PbH1Cw/NGjIH1HjmAkO3+5
WyMXhySOJ8yWyCBQ/nxqc0w7+TO4C7wQcEdZdUak25KJ74v0sfmWWrVw6kcnLU6k
oawW/L2F2w7ET3zDoxKh4fOF34pfHpSbZk7XJ68YOfHpYVnP4efkQVMCgYEAyvrM
KA7xjnsKumWh206ag3QEI0M/9uPHWmrh2164p7w1MtawccZTxYYJ5o5SsjTwbxkf
0cAamp4qLInmRUxU1gk76tPYC3Ndp6Yf1C+dt0q/vtzyJetCDrdz8HHT1SpKbW0l
g6z1I5FMwa6oWvWsfS++W51vsxUheNsOJ4uxKIECgYBwM7GRiw+7U3N4wItm0Wmp
Qp642Tu7vzwTzmOmV3klkB6UVrwfv/ewgiVFQGqAIcNn42JW44g2qfq70oQWnws4
K80l15+t6Bm7QUPH4Qg6o4O26IKGFZxEadqpyudyP7um/2B5cfqRuvzYS4YQowyI
N+AirB3YOUJjyyTk7yMSnQKBgGNLpSvDg6+ryWe96Bwcq8G6s3t8noHsk81LlAl4
oOSNUYj5NX+zAbATDizXWuUKuMPgioxVaa5RyVfYbelgme/KvKD32Sxg12P4BIIM
eR79VifMdjjOiZYhcHojdPlGovo89qkfpxwrLF1jT8CPhj4HaRvwPIBiyekRYC9A
Sv4BAoGAXCIC1xxAJP15osUuQjcM8KdsL1qw+LiPB2+cJJ2VMAZGV7CR2K0aCsis
OwRaYM0jZKUpxzp1uwtfrfqbhdYsv+jIBkfwoShYZuo6MhbUrj0sffkhJC3WrT2z
xafCFLFv1idzGvvNxatlp1DNKrndG2NS3syVAox9MnL5OMsvGM8=
-----END RSA PRIVATE KEY-----

View File

@@ -0,0 +1,40 @@
#!/bin/sh
openssl genrsa -out CA.key 2048
openssl req -x509 -new -nodes -key CA.key -days 1460 -subj '/CN=Swiftmailer CA/O=Swiftmailer/L=Paris/C=FR' -out CA.crt
openssl x509 -in CA.crt -clrtrust -out CA.crt
openssl genrsa -out sign.key 2048
openssl req -new -key sign.key -subj '/CN=Swiftmailer-User/O=Swiftmailer/L=Paris/C=FR' -out sign.csr
openssl x509 -req -in sign.csr -CA CA.crt -CAkey CA.key -out sign.crt -days 1460 -addtrust emailProtection
openssl x509 -in sign.crt -clrtrust -out sign.crt
rm sign.csr
openssl genrsa -out intermediate.key 2048
openssl req -new -key intermediate.key -subj '/CN=Swiftmailer Intermediate/O=Swiftmailer/L=Paris/C=FR' -out intermediate.csr
openssl x509 -req -in intermediate.csr -CA CA.crt -CAkey CA.key -set_serial 01 -out intermediate.crt -days 1460
openssl x509 -in intermediate.crt -clrtrust -out intermediate.crt
rm intermediate.csr
openssl genrsa -out sign2.key 2048
openssl req -new -key sign2.key -subj '/CN=Swiftmailer-User2/O=Swiftmailer/L=Paris/C=FR' -out sign2.csr
openssl x509 -req -in sign2.csr -CA intermediate.crt -CAkey intermediate.key -set_serial 01 -out sign2.crt -days 1460 -addtrust emailProtection
openssl x509 -in sign2.crt -clrtrust -out sign2.crt
rm sign2.csr
openssl genrsa -out encrypt.key 2048
openssl req -new -key encrypt.key -subj '/CN=Swiftmailer-User/O=Swiftmailer/L=Paris/C=FR' -out encrypt.csr
openssl x509 -req -in encrypt.csr -CA CA.crt -CAkey CA.key -CAcreateserial -out encrypt.crt -days 1460 -addtrust emailProtection
openssl x509 -in encrypt.crt -clrtrust -out encrypt.crt
rm encrypt.csr
openssl genrsa -out encrypt2.key 2048
openssl req -new -key encrypt2.key -subj '/CN=Swiftmailer-User2/O=Swiftmailer/L=Paris/C=FR' -out encrypt2.csr
openssl x509 -req -in encrypt2.csr -CA CA.crt -CAkey CA.key -CAcreateserial -out encrypt2.crt -days 1460 -addtrust emailProtection
openssl x509 -in encrypt2.crt -clrtrust -out encrypt2.crt
rm encrypt2.csr

View File

@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDFjCCAf4CCQDULaNM+Q+g3TANBgkqhkiG9w0BAQUFADBMMRcwFQYDVQQDDA5T
d2lmdG1haWxlciBDQTEUMBIGA1UECgwLU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@ -0,0 +1,37 @@
<?php
/*
Swift Mailer V4 accpetance test configuration.
YOU ONLY NEED TO EDIT THIS FILE IF YOU WISH TO RUN THE ACCEPTANCE TESTS.
The acceptance tests are run by default when "All Tests" are run with the
testing suite, however, without configuration options here only the unit tests
will be run and the acceptance tests will be skipped.
You can fill out only the parts you know and leave the other bits.
*/
/*
Defines: The name and port of a SMTP server you can connect to.
Recommended: smtp.gmail.com:25
*/
define('SWIFT_SMTP_HOST', 'localhost:4456');
/*
Defines: An SMTP server and port which uses TLS encryption.
Recommended: smtp.gmail.com:465
*/
define('SWIFT_TLS_HOST', 'smtp.gmail.com:465');
/*
Defines: An SMTP server and port which uses SSL encryption.
Recommended: smtp.gmail.com:465
*/
define('SWIFT_SSL_HOST', 'smtp.gmail.com:465');
/*
Defines: The path to a sendmail binary (one which can run in -bs mode).
Recommended: /usr/sbin/sendmail
*/
define('SWIFT_SENDMAIL_PATH', '/usr/sbin/sendmail -bs');

View File

@@ -0,0 +1,12 @@
<?php
require_once 'swift_required.php';
require_once __DIR__.'/Mime/AttachmentAcceptanceTest.php';
class Swift_AttachmentAcceptanceTest extends Swift_Mime_AttachmentAcceptanceTest
{
protected function _createAttachment()
{
return Swift_Attachment::newInstance();
}
}

View File

@@ -0,0 +1,162 @@
<?php
class Swift_ByteStream_FileByteStreamAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_testFile;
protected function setUp()
{
$this->_testFile = sys_get_temp_dir().'/swift-test-file'.__CLASS__;
file_put_contents($this->_testFile, 'abcdefghijklm');
}
protected function tearDown()
{
unlink($this->_testFile);
}
public function testFileDataCanBeRead()
{
$file = $this->_createFileStream($this->_testFile);
$str = '';
while (false !== $bytes = $file->read(8192)) {
$str .= $bytes;
}
$this->assertEquals('abcdefghijklm', $str);
}
public function testFileDataCanBeReadSequentially()
{
$file = $this->_createFileStream($this->_testFile);
$this->assertEquals('abcde', $file->read(5));
$this->assertEquals('fghijklm', $file->read(8));
$this->assertFalse($file->read(1));
}
public function testFilenameIsReturned()
{
$file = $this->_createFileStream($this->_testFile);
$this->assertEquals($this->_testFile, $file->getPath());
}
public function testFileCanBeWrittenTo()
{
$file = $this->_createFileStream($this->_testFile, true);
$file->write('foobar');
$this->assertEquals('foobar', $file->read(8192));
}
public function testReadingFromThenWritingToFile()
{
$file = $this->_createFileStream($this->_testFile, true);
$file->write('foobar');
$this->assertEquals('foobar', $file->read(8192));
$file->write('zipbutton');
$this->assertEquals('zipbutton', $file->read(8192));
}
public function testWritingToFileWithCanonicalization()
{
$file = $this->_createFileStream($this->_testFile, true);
$file->addFilter($this->_createFilter(array("\r\n", "\r"), "\n"), 'allToLF');
$file->write("foo\r\nbar\r");
$file->write("\nzip\r\ntest\r");
$file->flushBuffers();
$this->assertEquals("foo\nbar\nzip\ntest\n", file_get_contents($this->_testFile));
}
public function testWritingWithFulleMessageLengthOfAMultipleOf8192()
{
$file = $this->_createFileStream($this->_testFile, true);
$file->addFilter($this->_createFilter(array("\r\n", "\r"), "\n"), 'allToLF');
$file->write('');
$file->flushBuffers();
$this->assertEquals('', file_get_contents($this->_testFile));
}
public function testBindingOtherStreamsMirrorsWriteOperations()
{
$file = $this->_createFileStream($this->_testFile, true);
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->at(0))
->method('write')
->with('x');
$is2->expects($this->at(1))
->method('write')
->with('y');
$file->bind($is1);
$file->bind($is2);
$file->write('x');
$file->write('y');
}
public function testBindingOtherStreamsMirrorsFlushOperations()
{
$file = $this->_createFileStream(
$this->_testFile, true
);
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->once())
->method('flushBuffers');
$is2->expects($this->once())
->method('flushBuffers');
$file->bind($is1);
$file->bind($is2);
$file->flushBuffers();
}
public function testUnbindingStreamPreventsFurtherWrites()
{
$file = $this->_createFileStream($this->_testFile, true);
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->once())
->method('write')
->with('x');
$file->bind($is1);
$file->bind($is2);
$file->write('x');
$file->unbind($is2);
$file->write('y');
}
private function _createFilter($search, $replace)
{
return new Swift_StreamFilters_StringReplacementFilter($search, $replace);
}
private function _createMockInputStream()
{
return $this->getMockBuilder('Swift_InputByteStream')->getMock();
}
private function _createFileStream($file, $writable = false)
{
return new Swift_ByteStream_FileByteStream($file, $writable);
}
}

View File

@@ -0,0 +1,179 @@
<?php
class Swift_CharacterReaderFactory_SimpleCharacterReaderFactoryAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_factory;
private $_prefix = 'Swift_CharacterReader_';
protected function setUp()
{
$this->_factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
}
public function testCreatingUtf8Reader()
{
foreach (array('utf8', 'utf-8', 'UTF-8', 'UTF8') as $utf8) {
$reader = $this->_factory->getReaderFor($utf8);
$this->assertInstanceOf($this->_prefix.'Utf8Reader', $reader);
}
}
public function testCreatingIso8859XReaders()
{
$charsets = array();
foreach (range(1, 16) as $number) {
foreach (array('iso', 'iec') as $body) {
$charsets[] = $body.'-8859-'.$number;
$charsets[] = $body.'8859-'.$number;
$charsets[] = strtoupper($body).'-8859-'.$number;
$charsets[] = strtoupper($body).'8859-'.$number;
}
}
foreach ($charsets as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingWindows125XReaders()
{
$charsets = array();
foreach (range(0, 8) as $number) {
$charsets[] = 'windows-125'.$number;
$charsets[] = 'windows125'.$number;
$charsets[] = 'WINDOWS-125'.$number;
$charsets[] = 'WINDOWS125'.$number;
}
foreach ($charsets as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingCodePageReaders()
{
$charsets = array();
foreach (range(0, 8) as $number) {
$charsets[] = 'cp-125'.$number;
$charsets[] = 'cp125'.$number;
$charsets[] = 'CP-125'.$number;
$charsets[] = 'CP125'.$number;
}
foreach (array(437, 737, 850, 855, 857, 858, 860,
861, 863, 865, 866, 869, ) as $number) {
$charsets[] = 'cp-'.$number;
$charsets[] = 'cp'.$number;
$charsets[] = 'CP-'.$number;
$charsets[] = 'CP'.$number;
}
foreach ($charsets as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingAnsiReader()
{
foreach (array('ansi', 'ANSI') as $ansi) {
$reader = $this->_factory->getReaderFor($ansi);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingMacintoshReader()
{
foreach (array('macintosh', 'MACINTOSH') as $mac) {
$reader = $this->_factory->getReaderFor($mac);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingKOIReaders()
{
$charsets = array();
foreach (array('7', '8-r', '8-u', '8u', '8r') as $end) {
$charsets[] = 'koi-'.$end;
$charsets[] = 'koi'.$end;
$charsets[] = 'KOI-'.$end;
$charsets[] = 'KOI'.$end;
}
foreach ($charsets as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingIsciiReaders()
{
foreach (array('iscii', 'ISCII', 'viscii', 'VISCII') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingMIKReader()
{
foreach (array('mik', 'MIK') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingCorkReader()
{
foreach (array('cork', 'CORK', 't1', 'T1') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingUcs2Reader()
{
foreach (array('ucs-2', 'UCS-2', 'ucs2', 'UCS2') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(2, $reader->getInitialByteSize());
}
}
public function testCreatingUtf16Reader()
{
foreach (array('utf-16', 'UTF-16', 'utf16', 'UTF16') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(2, $reader->getInitialByteSize());
}
}
public function testCreatingUcs4Reader()
{
foreach (array('ucs-4', 'UCS-4', 'ucs4', 'UCS4') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(4, $reader->getInitialByteSize());
}
}
public function testCreatingUtf32Reader()
{
foreach (array('utf-32', 'UTF-32', 'utf32', 'UTF32') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceOf($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(4, $reader->getInitialByteSize());
}
}
}

View File

@@ -0,0 +1,24 @@
<?php
require_once 'swift_required.php';
//This is more of a "cross your fingers and hope it works" test!
class Swift_DependencyContainerAcceptanceTest extends \PHPUnit_Framework_TestCase
{
public function testNoLookupsFail()
{
$di = Swift_DependencyContainer::getInstance();
foreach ($di->listItems() as $itemName) {
try {
// to be removed in 6.0
if ('transport.mail' === $itemName) {
continue;
}
$di->lookup($itemName);
} catch (Swift_DependencyException $e) {
$this->fail($e->getMessage());
}
}
}
}

View File

@@ -0,0 +1,12 @@
<?php
require_once 'swift_required.php';
require_once __DIR__.'/Mime/EmbeddedFileAcceptanceTest.php';
class Swift_EmbeddedFileAcceptanceTest extends Swift_Mime_EmbeddedFileAcceptanceTest
{
protected function _createEmbeddedFile()
{
return Swift_EmbeddedFile::newInstance();
}
}

View File

@@ -0,0 +1,45 @@
<?php
class Swift_Encoder_Base64EncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_encoder;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../_samples/charsets');
$this->_encoder = new Swift_Encoder_Base64Encoder();
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$encodedText = $this->_encoder->encodeString($text);
$this->assertEquals(
base64_decode($encodedText), $text,
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
}

View File

@@ -0,0 +1,54 @@
<?php
class Swift_Encoder_QpEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_factory;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../_samples/charsets');
$this->_factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$encoding = $encodingDir;
$charStream = new Swift_CharacterStream_ArrayCharacterStream(
$this->_factory, $encoding);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$encodedText = $encoder->encodeString($text);
foreach (explode("\r\n", $encodedText) as $line) {
$this->assertLessThanOrEqual(76, strlen($line));
}
$this->assertEquals(
quoted_printable_decode($encodedText), $text,
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
}

View File

@@ -0,0 +1,50 @@
<?php
class Swift_Encoder_Rfc2231EncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_factory;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../_samples/charsets');
$this->_factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$encoding = $encodingDir;
$charStream = new Swift_CharacterStream_ArrayCharacterStream(
$this->_factory, $encoding);
$encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$encodedText = $encoder->encodeString($text);
$this->assertEquals(
urldecode(implode('', explode("\r\n", $encodedText))), $text,
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
}

View File

@@ -0,0 +1,30 @@
<?php
require_once 'swift_required.php';
class Swift_EncodingAcceptanceTest extends \PHPUnit_Framework_TestCase
{
public function testGet7BitEncodingReturns7BitEncoder()
{
$encoder = Swift_Encoding::get7BitEncoding();
$this->assertEquals('7bit', $encoder->getName());
}
public function testGet8BitEncodingReturns8BitEncoder()
{
$encoder = Swift_Encoding::get8BitEncoding();
$this->assertEquals('8bit', $encoder->getName());
}
public function testGetQpEncodingReturnsQpEncoder()
{
$encoder = Swift_Encoding::getQpEncoding();
$this->assertEquals('quoted-printable', $encoder->getName());
}
public function testGetBase64EncodingReturnsBase64Encoder()
{
$encoder = Swift_Encoding::getBase64Encoding();
$this->assertEquals('base64', $encoder->getName());
}
}

View File

@@ -0,0 +1,173 @@
<?php
class Swift_KeyCache_ArrayKeyCacheAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_cache;
private $_key1 = 'key1';
private $_key2 = 'key2';
protected function setUp()
{
$this->_cache = new Swift_KeyCache_ArrayKeyCache(
new Swift_KeyCache_SimpleKeyCacheInputStream()
);
}
public function testStringDataCanBeSetAndFetched()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeOverwritten()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'foo', 'whatever', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('whatever', $this->_cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeAppended()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'foo', 'ing', Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testing', $this->_cache->getString($this->_key1, 'foo'));
}
public function testHasKeyReturnValue()
{
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyIsWellPartitioned()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key2, 'foo', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $this->_cache->getString($this->_key2, 'foo'));
}
public function testItemKeyIsWellPartitioned()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'bar', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $this->_cache->getString($this->_key1, 'bar'));
}
public function testByteStreamCanBeImported()
{
$os = new Swift_ByteStream_ArrayByteStream();
$os->write('abcdef');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('abcdef', $this->_cache->getString($this->_key1, 'foo'));
}
public function testByteStreamCanBeAppended()
{
$os1 = new Swift_ByteStream_ArrayByteStream();
$os1->write('abcdef');
$os2 = new Swift_ByteStream_ArrayByteStream();
$os2->write('xyzuvw');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os1, Swift_KeyCache::MODE_APPEND
);
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os2, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('abcdefxyzuvw', $this->_cache->getString($this->_key1, 'foo'));
}
public function testByteStreamAndStringCanBeAppended()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_APPEND
);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write('abcdef');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testabcdef', $this->_cache->getString($this->_key1, 'foo'));
}
public function testDataCanBeExportedToByteStream()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$is = new Swift_ByteStream_ArrayByteStream();
$this->_cache->exportToByteStream($this->_key1, 'foo', $is);
$string = '';
while (false !== $bytes = $is->read(8192)) {
$string .= $bytes;
}
$this->assertEquals('test', $string);
}
public function testKeyCanBeCleared()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
$this->_cache->clearKey($this->_key1, 'foo');
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyCanBeCleared()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'bar', 'xyz', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
$this->assertTrue($this->_cache->hasKey($this->_key1, 'bar'));
$this->_cache->clearAll($this->_key1);
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
$this->assertFalse($this->_cache->hasKey($this->_key1, 'bar'));
}
public function testKeyCacheInputStream()
{
$is = $this->_cache->getInputByteStream($this->_key1, 'foo');
$is->write('abc');
$is->write('xyz');
$this->assertEquals('abcxyz', $this->_cache->getString($this->_key1, 'foo'));
}
}

View File

@@ -0,0 +1,173 @@
<?php
class Swift_KeyCache_DiskKeyCacheAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_cache;
private $_key1;
private $_key2;
protected function setUp()
{
$this->_key1 = uniqid(microtime(true), true);
$this->_key2 = uniqid(microtime(true), true);
$this->_cache = new Swift_KeyCache_DiskKeyCache(new Swift_KeyCache_SimpleKeyCacheInputStream(), sys_get_temp_dir());
}
public function testStringDataCanBeSetAndFetched()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeOverwritten()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'foo', 'whatever', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('whatever', $this->_cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeAppended()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'foo', 'ing', Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testing', $this->_cache->getString($this->_key1, 'foo'));
}
public function testHasKeyReturnValue()
{
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyIsWellPartitioned()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key2, 'foo', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $this->_cache->getString($this->_key2, 'foo'));
}
public function testItemKeyIsWellPartitioned()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'bar', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $this->_cache->getString($this->_key1, 'bar'));
}
public function testByteStreamCanBeImported()
{
$os = new Swift_ByteStream_ArrayByteStream();
$os->write('abcdef');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('abcdef', $this->_cache->getString($this->_key1, 'foo'));
}
public function testByteStreamCanBeAppended()
{
$os1 = new Swift_ByteStream_ArrayByteStream();
$os1->write('abcdef');
$os2 = new Swift_ByteStream_ArrayByteStream();
$os2->write('xyzuvw');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os1, Swift_KeyCache::MODE_APPEND
);
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os2, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('abcdefxyzuvw', $this->_cache->getString($this->_key1, 'foo'));
}
public function testByteStreamAndStringCanBeAppended()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_APPEND
);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write('abcdef');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testabcdef', $this->_cache->getString($this->_key1, 'foo'));
}
public function testDataCanBeExportedToByteStream()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$is = new Swift_ByteStream_ArrayByteStream();
$this->_cache->exportToByteStream($this->_key1, 'foo', $is);
$string = '';
while (false !== $bytes = $is->read(8192)) {
$string .= $bytes;
}
$this->assertEquals('test', $string);
}
public function testKeyCanBeCleared()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
$this->_cache->clearKey($this->_key1, 'foo');
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyCanBeCleared()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'bar', 'xyz', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
$this->assertTrue($this->_cache->hasKey($this->_key1, 'bar'));
$this->_cache->clearAll($this->_key1);
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
$this->assertFalse($this->_cache->hasKey($this->_key1, 'bar'));
}
public function testKeyCacheInputStream()
{
$is = $this->_cache->getInputByteStream($this->_key1, 'foo');
$is->write('abc');
$is->write('xyz');
$this->assertEquals('abcxyz', $this->_cache->getString($this->_key1, 'foo'));
}
}

View File

@@ -0,0 +1,55 @@
<?php
require_once 'swift_required.php';
require_once __DIR__.'/Mime/SimpleMessageAcceptanceTest.php';
class Swift_MessageAcceptanceTest extends Swift_Mime_SimpleMessageAcceptanceTest
{
public function testAddPartWrapper()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = $message->getDate();
$boundary = $message->getBoundary();
$message->addPart('foo', 'text/plain', 'iso-8859-1');
$message->addPart('test <b>foo</b>', 'text/html', 'iso-8859-1');
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\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=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo'.
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/html; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'test <b>foo</b>'.
"\r\n\r\n".
'--'.$boundary.'--'."\r\n",
$message->toString()
);
}
protected function _createMessage()
{
Swift_DependencyContainer::getInstance()
->register('properties.charset')->asValue(null);
return Swift_Message::newInstance();
}
}

View File

@@ -0,0 +1,123 @@
<?php
class Swift_Mime_AttachmentAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_contentEncoder;
private $_cache;
private $_grammar;
private $_headers;
protected function setUp()
{
$this->_cache = new Swift_KeyCache_ArrayKeyCache(
new Swift_KeyCache_SimpleKeyCacheInputStream()
);
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$this->_contentEncoder = new Swift_Mime_ContentEncoder_Base64ContentEncoder();
$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')
);
$this->_grammar = new Swift_Mime_Grammar();
$this->_headers = new Swift_Mime_SimpleHeaderSet(
new Swift_Mime_SimpleHeaderFactory($headerEncoder, $paramEncoder, $this->_grammar)
);
}
public function testDispositionIsSetInHeader()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setDisposition('inline');
$this->assertEquals(
'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline'."\r\n",
$attachment->toString()
);
}
public function testDispositionIsAttachmentByDefault()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$this->assertEquals(
'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment'."\r\n",
$attachment->toString()
);
}
public function testFilenameIsSetInHeader()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; filename=foo.pdf'."\r\n",
$attachment->toString()
);
}
public function testSizeIsSetInHeader()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setSize(12340);
$this->assertEquals(
'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; size=12340'."\r\n",
$attachment->toString()
);
}
public function testMultipleParametersInHeader()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$attachment->setSize(12340);
$this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; filename=foo.pdf; size=12340'."\r\n",
$attachment->toString()
);
}
public function testEndToEnd()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$attachment->setSize(12340);
$attachment->setBody('abcd');
$this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; filename=foo.pdf; size=12340'."\r\n".
"\r\n".
base64_encode('abcd'),
$attachment->toString()
);
}
protected function _createAttachment()
{
$entity = new Swift_Mime_Attachment(
$this->_headers,
$this->_contentEncoder,
$this->_cache,
$this->_grammar
);
return $entity;
}
}

View File

@@ -0,0 +1,56 @@
<?php
class Swift_Mime_ContentEncoder_Base64ContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_encoder;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
$this->_encoder = new Swift_Mime_ContentEncoder_Base64ContentEncoder();
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write($text);
$is = new Swift_ByteStream_ArrayByteStream();
$this->_encoder->encodeByteStream($os, $is);
$encoded = '';
while (false !== $bytes = $is->read(8192)) {
$encoded .= $bytes;
}
$this->assertEquals(
base64_decode($encoded), $text,
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
}

View File

@@ -0,0 +1,88 @@
<?php
class Swift_Mime_ContentEncoder_NativeQpContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
protected $_samplesDir;
/**
* @var Swift_Mime_ContentEncoder_NativeQpContentEncoder
*/
protected $_encoder;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
$this->_encoder = new Swift_Mime_ContentEncoder_NativeQpContentEncoder();
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write($text);
$is = new Swift_ByteStream_ArrayByteStream();
$this->_encoder->encodeByteStream($os, $is);
$encoded = '';
while (false !== $bytes = $is->read(8192)) {
$encoded .= $bytes;
}
$this->assertEquals(
quoted_printable_decode($encoded),
// CR and LF are converted to CRLF
preg_replace('~\r(?!\n)|(?<!\r)\n~', "\r\n", $text),
'%s: Encoded string should decode back to original string for sample '.$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
public function testEncodingAndDecodingSamplesFromDiConfiguredInstance()
{
$encoder = $this->_createEncoderFromContainer();
$this->assertSame('=C3=A4=C3=B6=C3=BC=C3=9F', $encoder->encodeString('äöüß'));
}
/**
* @expectedException \RuntimeException
*/
public function testCharsetChangeNotImplemented()
{
$this->_encoder->charsetChanged('utf-8');
$this->_encoder->charsetChanged('charset');
$this->_encoder->encodeString('foo');
}
public function testGetName()
{
$this->assertSame('quoted-printable', $this->_encoder->getName());
}
private function _createEncoderFromContainer()
{
return Swift_DependencyContainer::getInstance()
->lookup('mime.nativeqpcontentencoder')
;
}
}

View File

@@ -0,0 +1,88 @@
<?php
class Swift_Mime_ContentEncoder_PlainContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_encoder;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
$this->_encoder = new Swift_Mime_ContentEncoder_PlainContentEncoder('8bit');
}
public function testEncodingAndDecodingSamplesString()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$encodedText = $this->_encoder->encodeString($text);
$this->assertEquals(
$encodedText, $text,
'%s: Encoded string should be identical to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
public function testEncodingAndDecodingSamplesByteStream()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write($text);
$is = new Swift_ByteStream_ArrayByteStream();
$this->_encoder->encodeByteStream($os, $is);
$encoded = '';
while (false !== $bytes = $is->read(8192)) {
$encoded .= $bytes;
}
$this->assertEquals(
$encoded, $text,
'%s: Encoded string should be identical to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
}

View File

@@ -0,0 +1,160 @@
<?php
class Swift_Mime_ContentEncoder_QpContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_factory;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
$this->_factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
}
protected function tearDown()
{
Swift_Preferences::getInstance()->setQPDotEscape(false);
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$encoding = $encodingDir;
$charStream = new Swift_CharacterStream_NgCharacterStream(
$this->_factory, $encoding);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write($text);
$is = new Swift_ByteStream_ArrayByteStream();
$encoder->encodeByteStream($os, $is);
$encoded = '';
while (false !== $bytes = $is->read(8192)) {
$encoded .= $bytes;
}
$this->assertEquals(
quoted_printable_decode($encoded), $text,
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
public function testEncodingAndDecodingSamplesFromDiConfiguredInstance()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$encoding = $encodingDir;
$encoder = $this->_createEncoderFromContainer();
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write($text);
$is = new Swift_ByteStream_ArrayByteStream();
$encoder->encodeByteStream($os, $is);
$encoded = '';
while (false !== $bytes = $is->read(8192)) {
$encoded .= $bytes;
}
$this->assertEquals(
str_replace("\r\n", "\n", quoted_printable_decode($encoded)), str_replace("\r\n", "\n", $text),
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
public function testEncodingLFTextWithDiConfiguredInstance()
{
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a\r\nb\r\nc", $encoder->encodeString("a\nb\nc"));
}
public function testEncodingCRTextWithDiConfiguredInstance()
{
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a\r\nb\r\nc", $encoder->encodeString("a\rb\rc"));
}
public function testEncodingLFCRTextWithDiConfiguredInstance()
{
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a\r\n\r\nb\r\n\r\nc", $encoder->encodeString("a\n\rb\n\rc"));
}
public function testEncodingCRLFTextWithDiConfiguredInstance()
{
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a\r\nb\r\nc", $encoder->encodeString("a\r\nb\r\nc"));
}
public function testEncodingDotStuffingWithDiConfiguredInstance()
{
// Enable DotEscaping
Swift_Preferences::getInstance()->setQPDotEscape(true);
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a=2E\r\n=2E\r\n=2Eb\r\nc", $encoder->encodeString("a.\r\n.\r\n.b\r\nc"));
// Return to default
Swift_Preferences::getInstance()->setQPDotEscape(false);
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a.\r\n.\r\n.b\r\nc", $encoder->encodeString("a.\r\n.\r\n.b\r\nc"));
}
public function testDotStuffingEncodingAndDecodingSamplesFromDiConfiguredInstance()
{
// Enable DotEscaping
Swift_Preferences::getInstance()->setQPDotEscape(true);
$this->testEncodingAndDecodingSamplesFromDiConfiguredInstance();
}
private function _createEncoderFromContainer()
{
return Swift_DependencyContainer::getInstance()
->lookup('mime.qpcontentencoder')
;
}
}

View File

@@ -0,0 +1,136 @@
<?php
class Swift_Mime_EmbeddedFileAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_contentEncoder;
private $_cache;
private $_grammar;
private $_headers;
protected function setUp()
{
$this->_cache = new Swift_KeyCache_ArrayKeyCache(
new Swift_KeyCache_SimpleKeyCacheInputStream()
);
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$this->_contentEncoder = new Swift_Mime_ContentEncoder_Base64ContentEncoder();
$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')
);
$this->_grammar = new Swift_Mime_Grammar();
$this->_headers = new Swift_Mime_SimpleHeaderSet(
new Swift_Mime_SimpleHeaderFactory($headerEncoder, $paramEncoder, $this->_grammar)
);
}
public function testContentIdIsSetInHeader()
{
$file = $this->_createEmbeddedFile();
$file->setContentType('application/pdf');
$file->setId('foo@bar');
$this->assertEquals(
'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-ID: <foo@bar>'."\r\n".
'Content-Disposition: inline'."\r\n",
$file->toString()
);
}
public function testDispositionIsSetInHeader()
{
$file = $this->_createEmbeddedFile();
$id = $file->getId();
$file->setContentType('application/pdf');
$file->setDisposition('attachment');
$this->assertEquals(
'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-ID: <'.$id.'>'."\r\n".
'Content-Disposition: attachment'."\r\n",
$file->toString()
);
}
public function testFilenameIsSetInHeader()
{
$file = $this->_createEmbeddedFile();
$id = $file->getId();
$file->setContentType('application/pdf');
$file->setFilename('foo.pdf');
$this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-ID: <'.$id.'>'."\r\n".
'Content-Disposition: inline; filename=foo.pdf'."\r\n",
$file->toString()
);
}
public function testSizeIsSetInHeader()
{
$file = $this->_createEmbeddedFile();
$id = $file->getId();
$file->setContentType('application/pdf');
$file->setSize(12340);
$this->assertEquals(
'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-ID: <'.$id.'>'."\r\n".
'Content-Disposition: inline; size=12340'."\r\n",
$file->toString()
);
}
public function testMultipleParametersInHeader()
{
$file = $this->_createEmbeddedFile();
$id = $file->getId();
$file->setContentType('application/pdf');
$file->setFilename('foo.pdf');
$file->setSize(12340);
$this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-ID: <'.$id.'>'."\r\n".
'Content-Disposition: inline; filename=foo.pdf; size=12340'."\r\n",
$file->toString()
);
}
public function testEndToEnd()
{
$file = $this->_createEmbeddedFile();
$id = $file->getId();
$file->setContentType('application/pdf');
$file->setFilename('foo.pdf');
$file->setSize(12340);
$file->setBody('abcd');
$this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-ID: <'.$id.'>'."\r\n".
'Content-Disposition: inline; filename=foo.pdf; size=12340'."\r\n".
"\r\n".
base64_encode('abcd'),
$file->toString()
);
}
protected function _createEmbeddedFile()
{
$entity = new Swift_Mime_EmbeddedFile(
$this->_headers,
$this->_contentEncoder,
$this->_cache,
$this->_grammar
);
return $entity;
}
}

View File

@@ -0,0 +1,32 @@
<?php
class Swift_Mime_HeaderEncoder_Base64HeaderEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_encoder;
protected function setUp()
{
$this->_encoder = new Swift_Mime_HeaderEncoder_Base64HeaderEncoder();
}
public function testEncodingJIS()
{
if (function_exists('mb_convert_encoding')) {
// base64_encode and split cannot handle long JIS text to fold
$subject = '長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い件名';
$encodedWrapperLength = strlen('=?iso-2022-jp?'.$this->_encoder->getName().'??=');
$old = mb_internal_encoding();
mb_internal_encoding('utf-8');
$newstring = mb_encode_mimeheader($subject, 'iso-2022-jp', 'B', "\r\n");
mb_internal_encoding($old);
$encoded = $this->_encoder->encodeString($subject, 0, 75 - $encodedWrapperLength, 'iso-2022-jp');
$this->assertEquals(
$encoded, $newstring,
'Encoded string should decode back to original string for sample '
);
}
}
}

View File

@@ -0,0 +1,127 @@
<?php
class Swift_Mime_MimePartAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_contentEncoder;
private $_cache;
private $_grammar;
private $_headers;
protected function setUp()
{
$this->_cache = new Swift_KeyCache_ArrayKeyCache(
new Swift_KeyCache_SimpleKeyCacheInputStream()
);
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$this->_contentEncoder = new Swift_Mime_ContentEncoder_QpContentEncoder(
new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8'),
new Swift_StreamFilters_ByteArrayReplacementFilter(
array(array(0x0D, 0x0A), array(0x0D), array(0x0A)),
array(array(0x0A), array(0x0A), array(0x0D, 0x0A))
)
);
$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')
);
$this->_grammar = new Swift_Mime_Grammar();
$this->_headers = new Swift_Mime_SimpleHeaderSet(
new Swift_Mime_SimpleHeaderFactory($headerEncoder, $paramEncoder, $this->_grammar)
);
}
public function testCharsetIsSetInHeader()
{
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setCharset('utf-8');
$part->setBody('foobar');
$this->assertEquals(
'Content-Type: text/plain; charset=utf-8'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foobar',
$part->toString()
);
}
public function testFormatIsSetInHeaders()
{
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setFormat('flowed');
$part->setBody('> foobar');
$this->assertEquals(
'Content-Type: text/plain; format=flowed'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'> foobar',
$part->toString()
);
}
public function testDelSpIsSetInHeaders()
{
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setDelSp(true);
$part->setBody('foobar');
$this->assertEquals(
'Content-Type: text/plain; delsp=yes'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foobar',
$part->toString()
);
}
public function testAll3ParamsInHeaders()
{
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setCharset('utf-8');
$part->setFormat('fixed');
$part->setDelSp(true);
$part->setBody('foobar');
$this->assertEquals(
'Content-Type: text/plain; charset=utf-8; format=fixed; delsp=yes'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foobar',
$part->toString()
);
}
public function testBodyIsCanonicalized()
{
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setCharset('utf-8');
$part->setBody("foobar\r\rtest\ning\r");
$this->assertEquals(
'Content-Type: text/plain; charset=utf-8'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
"foobar\r\n".
"\r\n".
"test\r\n".
"ing\r\n",
$part->toString()
);
}
protected function _createMimePart()
{
$entity = new Swift_Mime_MimePart(
$this->_headers,
$this->_contentEncoder,
$this->_cache,
$this->_grammar
);
return $entity;
}
}

View File

@@ -0,0 +1,15 @@
<?php
require_once 'swift_required.php';
require_once __DIR__.'/Mime/MimePartAcceptanceTest.php';
class Swift_MimePartAcceptanceTest extends Swift_Mime_MimePartAcceptanceTest
{
protected function _createMimePart()
{
Swift_DependencyContainer::getInstance()
->register('properties.charset')->asValue(null);
return Swift_MimePart::newInstance();
}
}

View File

@@ -0,0 +1,131 @@
<?php
abstract class Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest extends \PHPUnit_Framework_TestCase
{
protected $_buffer;
abstract protected function _initializeBuffer();
protected function setUp()
{
if (true == getenv('TRAVIS')) {
$this->markTestSkipped(
'Will fail on travis-ci if not skipped due to travis blocking '.
'socket mailing tcp connections.'
);
}
$this->_buffer = new Swift_Transport_StreamBuffer(
$this->getMockBuilder('Swift_ReplacementFilterFactory')->getMock()
);
}
public function testReadLine()
{
$this->_initializeBuffer();
$line = $this->_buffer->readLine(0);
$this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
$seq = $this->_buffer->write("QUIT\r\n");
$this->assertTrue((bool) $seq);
$line = $this->_buffer->readLine($seq);
$this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
$this->_buffer->terminate();
}
public function testWrite()
{
$this->_initializeBuffer();
$line = $this->_buffer->readLine(0);
$this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
$seq = $this->_buffer->write("HELO foo\r\n");
$this->assertTrue((bool) $seq);
$line = $this->_buffer->readLine($seq);
$this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
$seq = $this->_buffer->write("QUIT\r\n");
$this->assertTrue((bool) $seq);
$line = $this->_buffer->readLine($seq);
$this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
$this->_buffer->terminate();
}
public function testBindingOtherStreamsMirrorsWriteOperations()
{
$this->_initializeBuffer();
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->at(0))
->method('write')
->with('x');
$is2->expects($this->at(1))
->method('write')
->with('y');
$this->_buffer->bind($is1);
$this->_buffer->bind($is2);
$this->_buffer->write('x');
$this->_buffer->write('y');
}
public function testBindingOtherStreamsMirrorsFlushOperations()
{
$this->_initializeBuffer();
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->once())
->method('flushBuffers');
$is2->expects($this->once())
->method('flushBuffers');
$this->_buffer->bind($is1);
$this->_buffer->bind($is2);
$this->_buffer->flushBuffers();
}
public function testUnbindingStreamPreventsFurtherWrites()
{
$this->_initializeBuffer();
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->once())
->method('write')
->with('x');
$this->_buffer->bind($is1);
$this->_buffer->bind($is2);
$this->_buffer->write('x');
$this->_buffer->unbind($is2);
$this->_buffer->write('y');
}
private function _createMockInputStream()
{
return $this->getMockBuilder('Swift_InputByteStream')->getMock();
}
}

View File

@@ -0,0 +1,33 @@
<?php
require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
class Swift_Transport_StreamBuffer_BasicSocketAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
{
protected function setUp()
{
if (!defined('SWIFT_SMTP_HOST')) {
$this->markTestSkipped(
'Cannot run test without an SMTP host to connect to (define '.
'SWIFT_SMTP_HOST in tests/acceptance.conf.php if you wish to run this test)'
);
}
parent::setUp();
}
protected function _initializeBuffer()
{
$parts = explode(':', SWIFT_SMTP_HOST);
$host = $parts[0];
$port = isset($parts[1]) ? $parts[1] : 25;
$this->_buffer->initialize(array(
'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
'host' => $host,
'port' => $port,
'protocol' => 'tcp',
'blocking' => 1,
'timeout' => 15,
));
}
}

View File

@@ -0,0 +1,26 @@
<?php
require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
class Swift_Transport_StreamBuffer_ProcessAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
{
protected function setUp()
{
if (!defined('SWIFT_SENDMAIL_PATH')) {
$this->markTestSkipped(
'Cannot run test without a path to sendmail (define '.
'SWIFT_SENDMAIL_PATH in tests/acceptance.conf.php if you wish to run this test)'
);
}
parent::setUp();
}
protected function _initializeBuffer()
{
$this->_buffer->initialize(array(
'type' => Swift_Transport_IoBuffer::TYPE_PROCESS,
'command' => SWIFT_SENDMAIL_PATH.' -bs',
));
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Swift_Transport_StreamBuffer_SocketTimeoutTest extends \PHPUnit_Framework_TestCase
{
protected $_buffer;
protected $_randomHighPort;
protected $_server;
protected function setUp()
{
if (!defined('SWIFT_SMTP_HOST')) {
$this->markTestSkipped(
'Cannot run test without an SMTP host to connect to (define '.
'SWIFT_SMTP_HOST in tests/acceptance.conf.php if you wish to run this test)'
);
}
$serverStarted = false;
for ($i = 0; $i < 5; ++$i) {
$this->_randomHighPort = rand(50000, 65000);
$this->_server = stream_socket_server('tcp://127.0.0.1:'.$this->_randomHighPort);
if ($this->_server) {
$serverStarted = true;
}
}
$this->_buffer = new Swift_Transport_StreamBuffer(
$this->getMockBuilder('Swift_ReplacementFilterFactory')->getMock()
);
}
protected function _initializeBuffer()
{
$host = '127.0.0.1';
$port = $this->_randomHighPort;
$this->_buffer->initialize(array(
'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
'host' => $host,
'port' => $port,
'protocol' => 'tcp',
'blocking' => 1,
'timeout' => 1,
));
}
public function testTimeoutException()
{
$this->_initializeBuffer();
$e = null;
try {
$line = $this->_buffer->readLine(0);
} catch (Exception $e) {
}
$this->assertInstanceOf('Swift_IoException', $e, 'IO Exception Not Thrown On Connection Timeout');
$this->assertRegExp('/Connection to .* Timed Out/', $e->getMessage());
}
protected function tearDown()
{
if ($this->_server) {
stream_socket_shutdown($this->_server, STREAM_SHUT_RDWR);
}
}
}

View File

@@ -0,0 +1,40 @@
<?php
require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
class Swift_Transport_StreamBuffer_SslSocketAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
{
protected function setUp()
{
$streams = stream_get_transports();
if (!in_array('ssl', $streams)) {
$this->markTestSkipped(
'SSL is not configured for your system. It is not possible to run this test'
);
}
if (!defined('SWIFT_SSL_HOST')) {
$this->markTestSkipped(
'Cannot run test without an SSL enabled SMTP host to connect to (define '.
'SWIFT_SSL_HOST in tests/acceptance.conf.php if you wish to run this test)'
);
}
parent::setUp();
}
protected function _initializeBuffer()
{
$parts = explode(':', SWIFT_SSL_HOST);
$host = $parts[0];
$port = isset($parts[1]) ? $parts[1] : 25;
$this->_buffer->initialize(array(
'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
'host' => $host,
'port' => $port,
'protocol' => 'ssl',
'blocking' => 1,
'timeout' => 15,
));
}
}

View File

@@ -0,0 +1,39 @@
<?php
require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
class Swift_Transport_StreamBuffer_TlsSocketAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
{
protected function setUp()
{
$streams = stream_get_transports();
if (!in_array('tls', $streams)) {
$this->markTestSkipped(
'TLS is not configured for your system. It is not possible to run this test'
);
}
if (!defined('SWIFT_TLS_HOST')) {
$this->markTestSkipped(
'Cannot run test without a TLS enabled SMTP host to connect to (define '.
'SWIFT_TLS_HOST in tests/acceptance.conf.php if you wish to run this test)'
);
}
parent::setUp();
}
protected function _initializeBuffer()
{
$parts = explode(':', SWIFT_TLS_HOST);
$host = $parts[0];
$port = isset($parts[1]) ? $parts[1] : 25;
$this->_buffer->initialize(array(
'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
'host' => $host,
'port' => $port,
'protocol' => 'tls',
'blocking' => 1,
'timeout' => 15,
));
}
}

View File

@@ -0,0 +1,21 @@
<?php
require_once dirname(__DIR__).'/vendor/autoload.php';
// Disable garbage collector to prevent segfaults
gc_disable();
set_include_path(get_include_path().PATH_SEPARATOR.dirname(__DIR__).'/lib');
Mockery::getConfiguration()->allowMockingNonExistentMethods(true);
if (is_file(__DIR__.'/acceptance.conf.php')) {
require_once __DIR__.'/acceptance.conf.php';
}
if (is_file(__DIR__.'/smoke.conf.php')) {
require_once __DIR__.'/smoke.conf.php';
}
require_once __DIR__.'/StreamCollector.php';
require_once __DIR__.'/IdenticalBinaryConstraint.php';
require_once __DIR__.'/SwiftMailerTestCase.php';
require_once __DIR__.'/SwiftMailerSmokeTestCase.php';

View 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());
}
}

View File

@@ -0,0 +1,20 @@
<?php
class Swift_Bug118Test extends \PHPUnit_Framework_TestCase
{
private $_message;
protected 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);
}
}

View File

@@ -0,0 +1,38 @@
<?php
class Swift_Bug206Test extends \PHPUnit_Framework_TestCase
{
private $_factory;
protected 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);
}
}

View File

@@ -0,0 +1,21 @@
<?php
class Swift_Bug274Test extends \PHPUnit_Framework_TestCase
{
public function testEmptyFileNameAsAttachment()
{
$message = new Swift_Message();
$this->setExpectedException('Swift_IoException', 'The path cannot be empty');
$message->attach(Swift_Attachment::fromPath(''));
}
public function testNonEmptyFileNameAsAttachment()
{
$message = new Swift_Message();
try {
$message->attach(Swift_Attachment::fromPath(__FILE__));
} catch (Exception $e) {
$this->fail('Path should not be empty');
}
}
}

View File

@@ -0,0 +1,75 @@
<?php
class Swift_Bug34Test extends \PHPUnit_Framework_TestCase
{
protected 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-ID: <'.$cidVal.'>'."\r\n".
'Content-Disposition: inline; filename=image.gif'."\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()
);
}
}

View File

@@ -0,0 +1,73 @@
<?php
class Swift_Bug35Test extends \PHPUnit_Framework_TestCase
{
protected 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()
);
}
}

View File

@@ -0,0 +1,192 @@
<?php
class Swift_Bug38Test extends \PHPUnit_Framework_TestCase
{
private $_attFile;
private $_attFileName;
private $_attFileType;
protected 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-ID: <'.preg_quote($imgId, '~').'>'."\r\n".
'Content-Disposition: inline; filename=image.gif'."\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-ID: <'.preg_quote($imgId, '~').'>'."\r\n".
'Content-Disposition: inline; filename=image.gif'."\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);
}
public function assertPatternInStream($pattern, $stream, $message = '%s')
{
$string = '';
while (false !== $bytes = $stream->read(8192)) {
$string .= $bytes;
}
$this->assertRegExp($pattern, $string, $message);
}
}

View 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);
}
}

View File

@@ -0,0 +1,110 @@
<?php
class Swift_Bug51Test extends \SwiftMailerTestCase
{
private $_attachmentFile;
private $_outputFile;
protected function setUp()
{
$this->_attachmentFile = sys_get_temp_dir().'/attach.rand.bin';
file_put_contents($this->_attachmentFile, '');
$this->_outputFile = sys_get_temp_dir().'/attach.out.bin';
file_put_contents($this->_outputFile, '');
}
protected 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
);
}
}
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));
}
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;
}
}

View 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);
}
}

View File

@@ -0,0 +1,36 @@
<?php
class Swift_Bug650Test extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider encodingDataProvider
*
* @param string $name
* @param string $expectedEncodedName
*/
public function testMailboxHeaderEncoding($name, $expectedEncodedName)
{
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$charStream = new Swift_CharacterStream_NgCharacterStream($factory, 'utf-8');
$encoder = new Swift_Mime_HeaderEncoder_QpHeaderEncoder($charStream);
$header = new Swift_Mime_Headers_MailboxHeader('To', $encoder, new Swift_Mime_Grammar());
$header->setCharset('utf-8');
$header->setNameAddresses(array(
'test@example.com' => $name,
));
$this->assertSame('To: '.$expectedEncodedName." <test@example.com>\r\n", $header->toString());
}
public function encodingDataProvider()
{
return array(
array('this is " a test ö', 'this is =?utf-8?Q?=22?= a test =?utf-8?Q?=C3=B6?='),
array(': this is a test ö', '=?utf-8?Q?=3A?= this is a test =?utf-8?Q?=C3=B6?='),
array('( test ö', '=?utf-8?Q?=28?= test =?utf-8?Q?=C3=B6?='),
array('[ test ö', '=?utf-8?Q?=5B?= test =?utf-8?Q?=C3=B6?='),
array('@ test ö)', '=?utf-8?Q?=40?= test =?utf-8?Q?=C3=B6=29?='),
);
}
}

View File

@@ -0,0 +1,20 @@
<?php
class Swift_Bug71Test extends \PHPUnit_Framework_TestCase
{
private $_message;
protected 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());
}
}

View File

@@ -0,0 +1,71 @@
<?php
class Swift_Bug76Test extends \PHPUnit_Framework_TestCase
{
private $_inputFile;
private $_outputFile;
private $_encoder;
protected function setUp()
{
$this->_inputFile = sys_get_temp_dir().'/in.bin';
file_put_contents($this->_inputFile, '');
$this->_outputFile = sys_get_temp_dir().'/out.bin';
file_put_contents($this->_outputFile, '');
$this->_encoder = $this->_createEncoder();
}
protected 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'
);
}
public function assertMaxLineLength($length, $filePath, $message = '%s')
{
$lines = file($filePath);
foreach ($lines as $line) {
$this->assertTrue((strlen(trim($line)) <= 76), $message);
}
}
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);
}
}

View File

@@ -0,0 +1,19 @@
<?php
class Swift_FileByteStreamConsecutiveReadCalls extends \PHPUnit_Framework_TestCase
{
/**
* @test
* @expectedException \Swift_IoException
*/
public function shouldThrowExceptionOnConsecutiveRead()
{
$fbs = new \Swift_ByteStream_FileByteStream('does not exist');
try {
$fbs->read(100);
} catch (\Swift_IoException $exc) {
$fbs->read(100);
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class MimeEntityFixture implements Swift_Mime_MimeEntity
{
private $level;
private $string;
private $contentType;
public function __construct($level = null, $string = '', $contentType = null)
{
$this->level = $level;
$this->string = $string;
$this->contentType = $contentType;
}
public function getNestingLevel()
{
return $this->level;
}
public function toString()
{
return $this->string;
}
public function getContentType()
{
return $this->contentType;
}
// These methods are here to account for the implemented interfaces
public function getId()
{
}
public function getHeaders()
{
}
public function getBody()
{
}
public function setBody($body, $contentType = null)
{
}
public function toByteStream(Swift_InputByteStream $is)
{
}
public function charsetChanged($charset)
{
}
public function encoderChanged(Swift_Mime_ContentEncoder $encoder)
{
}
public function getChildren()
{
}
public function setChildren(array $children)
{
}
}

View File

@@ -0,0 +1,63 @@
<?php
/*
Swift Mailer V4 smoke test configuration.
YOU ONLY NEED TO EDIT THIS FILE IF YOU WISH TO RUN THE SMOKE TESTS.
The smoke tests are run by default when "All Tests" are run with the
testing suite, however, without configuration options here only the unit tests
will be run and the smoke tests will be skipped.
*/
/*
Defines: The an address which Swift can send to (it will also send "from" this address).
Recommended: (your own email address?)
*/
define('SWIFT_SMOKE_EMAIL_ADDRESS', 'test@swiftmailer.org');
/*
Defines: The specific transport you want to mail with.
Recommended: Any of 'smtp', 'sendmail' or 'mail'
*/
define('SWIFT_SMOKE_TRANSPORT_TYPE', 'smtp');
// SMTP-specific settings
/*
Defines: An SMTP server to connect to
Recommended: smtp.your-isp.com (varies wildly!)
*/
define('SWIFT_SMOKE_SMTP_HOST', 'localhost');
/*
Defines: The SMTP port to connect to
Recommended: 25
*/
define('SWIFT_SMOKE_SMTP_PORT', '4456');
/*
Defines: A username to authenticate with SMTP (if needed).
Recommended: (none)
*/
define('SWIFT_SMOKE_SMTP_USER', '');
/*
Defines: A password to authenticate with SMTP (if needed).
Recommended: (none)
*/
define('SWIFT_SMOKE_SMTP_PASS', '');
/*
Defines: The encryption needed on your SMTP server.
Recommended: (none), or 'tls' or 'ssl'
*/
define('SWIFT_SMOKE_SMTP_ENCRYPTION', '');
// Sendmail specific settings
/*
Defines: The command to use when sending via sendmail
Recommended: /usr/sbin/sendmail -bs (or "-oi -t")
*/
define('SWIFT_SMOKE_SENDMAIL_COMMAND', '/usr/sbin/sendmail -bs');

View File

@@ -0,0 +1,33 @@
<?php
/**
* @group smoke
*/
class Swift_Smoke_AttachmentSmokeTest extends SwiftMailerSmokeTestCase
{
private $_attFile;
protected function setUp()
{
parent::setup(); // For skip
$this->_attFile = __DIR__.'/../../../_samples/files/textfile.zip';
}
public function testAttachmentSending()
{
$mailer = $this->_getMailer();
$message = Swift_Message::newInstance()
->setSubject('[Swift Mailer] AttachmentSmokeTest')
->setFrom(array(SWIFT_SMOKE_EMAIL_ADDRESS => 'Swift Mailer'))
->setTo(SWIFT_SMOKE_EMAIL_ADDRESS)
->setBody('This message should contain an attached ZIP file (named "textfile.zip").'.PHP_EOL.
'When unzipped, the archive should produce a text file which reads:'.PHP_EOL.
'"This is part of a Swift Mailer v4 smoke test."'
)
->attach(Swift_Attachment::fromPath($this->_attFile))
;
$this->assertEquals(1, $mailer->send($message),
'%s: The smoke test should send a single message'
);
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* @group smoke
*/
class Swift_Smoke_BasicSmokeTest extends SwiftMailerSmokeTestCase
{
public function testBasicSending()
{
$mailer = $this->_getMailer();
$message = Swift_Message::newInstance()
->setSubject('[Swift Mailer] BasicSmokeTest')
->setFrom(array(SWIFT_SMOKE_EMAIL_ADDRESS => 'Swift Mailer'))
->setTo(SWIFT_SMOKE_EMAIL_ADDRESS)
->setBody('One, two, three, four, five...'.PHP_EOL.
'six, seven, eight...'
)
;
$this->assertEquals(1, $mailer->send($message),
'%s: The smoke test should send a single message'
);
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* @group smoke
*/
class Swift_Smoke_HtmlWithAttachmentSmokeTest extends SwiftMailerSmokeTestCase
{
private $_attFile;
protected function setUp()
{
$this->_attFile = __DIR__.'/../../../_samples/files/textfile.zip';
}
public function testAttachmentSending()
{
$mailer = $this->_getMailer();
$message = Swift_Message::newInstance('[Swift Mailer] HtmlWithAttachmentSmokeTest')
->setFrom(array(SWIFT_SMOKE_EMAIL_ADDRESS => 'Swift Mailer'))
->setTo(SWIFT_SMOKE_EMAIL_ADDRESS)
->attach(Swift_Attachment::fromPath($this->_attFile))
->setBody('<p>This HTML-formatted message should contain an attached ZIP file (named "textfile.zip").'.PHP_EOL.
'When unzipped, the archive should produce a text file which reads:</p>'.PHP_EOL.
'<p><q>This is part of a Swift Mailer v4 smoke test.</q></p>', 'text/html'
)
;
$this->assertEquals(1, $mailer->send($message),
'%s: The smoke test should send a single message'
);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* @group smoke
*/
class Swift_Smoke_InternationalSmokeTest extends SwiftMailerSmokeTestCase
{
private $_attFile;
protected function setUp()
{
parent::setup(); // For skip
$this->_attFile = __DIR__.'/../../../_samples/files/textfile.zip';
}
public function testAttachmentSending()
{
$mailer = $this->_getMailer();
$message = Swift_Message::newInstance()
->setCharset('utf-8')
->setSubject('[Swift Mailer] InternationalSmokeTest (διεθνής)')
->setFrom(array(SWIFT_SMOKE_EMAIL_ADDRESS => 'Χριστοφορου (Swift Mailer)'))
->setTo(SWIFT_SMOKE_EMAIL_ADDRESS)
->setBody('This message should contain an attached ZIP file (named "κείμενο, εδάφιο, θέμα.zip").'.PHP_EOL.
'When unzipped, the archive should produce a text file which reads:'.PHP_EOL.
'"This is part of a Swift Mailer v4 smoke test."'.PHP_EOL.
PHP_EOL.
'Following is some arbitrary Greek text:'.PHP_EOL.
'Δεν βρέθηκαν λέξεις.'
)
->attach(Swift_Attachment::fromPath($this->_attFile)
->setContentType('application/zip')
->setFilename('κείμενο, εδάφιο, θέμα.zip')
)
;
$this->assertEquals(1, $mailer->send($message),
'%s: The smoke test should send a single message'
);
}
}

View File

@@ -0,0 +1,201 @@
<?php
class Swift_ByteStream_ArrayByteStreamTest extends \PHPUnit_Framework_TestCase
{
public function testReadingSingleBytesFromBaseInput()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$output = array();
while (false !== $bytes = $bs->read(1)) {
$output[] = $bytes;
}
$this->assertEquals($input, $output,
'%s: Bytes read from stream should be the same as bytes in constructor'
);
}
public function testReadingMultipleBytesFromBaseInput()
{
$input = array('a', 'b', 'c', 'd');
$bs = $this->_createArrayStream($input);
$output = array();
while (false !== $bytes = $bs->read(2)) {
$output[] = $bytes;
}
$this->assertEquals(array('ab', 'cd'), $output,
'%s: Bytes read from stream should be in pairs'
);
}
public function testReadingOddOffsetOnLastByte()
{
$input = array('a', 'b', 'c', 'd', 'e');
$bs = $this->_createArrayStream($input);
$output = array();
while (false !== $bytes = $bs->read(2)) {
$output[] = $bytes;
}
$this->assertEquals(array('ab', 'cd', 'e'), $output,
'%s: Bytes read from stream should be in pairs except final read'
);
}
public function testSettingPointerPartway()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$bs->setReadPointer(1);
$this->assertEquals('b', $bs->read(1),
'%s: Byte should be second byte since pointer as at offset 1'
);
}
public function testResettingPointerAfterExhaustion()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
while (false !== $bs->read(1));
$bs->setReadPointer(0);
$this->assertEquals('a', $bs->read(1),
'%s: Byte should be first byte since pointer as at offset 0'
);
}
public function testPointerNeverSetsBelowZero()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$bs->setReadPointer(-1);
$this->assertEquals('a', $bs->read(1),
'%s: Byte should be first byte since pointer should be at offset 0'
);
}
public function testPointerNeverSetsAboveStackSize()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$bs->setReadPointer(3);
$this->assertFalse($bs->read(1),
'%s: Stream should be at end and thus return false'
);
}
public function testBytesCanBeWrittenToStream()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$bs->write('de');
$output = array();
while (false !== $bytes = $bs->read(1)) {
$output[] = $bytes;
}
$this->assertEquals(array('a', 'b', 'c', 'd', 'e'), $output,
'%s: Bytes read from stream should be from initial stack + written'
);
}
public function testContentsCanBeFlushed()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$bs->flushBuffers();
$this->assertFalse($bs->read(1),
'%s: Contents have been flushed so read() should return false'
);
}
public function testConstructorCanTakeStringArgument()
{
$bs = $this->_createArrayStream('abc');
$output = array();
while (false !== $bytes = $bs->read(1)) {
$output[] = $bytes;
}
$this->assertEquals(array('a', 'b', 'c'), $output,
'%s: Bytes read from stream should be the same as bytes in constructor'
);
}
public function testBindingOtherStreamsMirrorsWriteOperations()
{
$bs = $this->_createArrayStream('');
$is1 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is2 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->at(0))
->method('write')
->with('x');
$is2->expects($this->at(1))
->method('write')
->with('y');
$bs->bind($is1);
$bs->bind($is2);
$bs->write('x');
$bs->write('y');
}
public function testBindingOtherStreamsMirrorsFlushOperations()
{
$bs = $this->_createArrayStream('');
$is1 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is2 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is1->expects($this->once())
->method('flushBuffers');
$is2->expects($this->once())
->method('flushBuffers');
$bs->bind($is1);
$bs->bind($is2);
$bs->flushBuffers();
}
public function testUnbindingStreamPreventsFurtherWrites()
{
$bs = $this->_createArrayStream('');
$is1 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is2 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->once())
->method('write')
->with('x');
$bs->bind($is1);
$bs->bind($is2);
$bs->write('x');
$bs->unbind($is2);
$bs->write('y');
}
private function _createArrayStream($input)
{
return new Swift_ByteStream_ArrayByteStream($input);
}
}

View File

@@ -0,0 +1,43 @@
<?php
class Swift_CharacterReader_GenericFixedWidthReaderTest extends \PHPUnit_Framework_TestCase
{
public function testInitialByteSizeMatchesWidth()
{
$reader = new Swift_CharacterReader_GenericFixedWidthReader(1);
$this->assertSame(1, $reader->getInitialByteSize());
$reader = new Swift_CharacterReader_GenericFixedWidthReader(4);
$this->assertSame(4, $reader->getInitialByteSize());
}
public function testValidationValueIsBasedOnOctetCount()
{
$reader = new Swift_CharacterReader_GenericFixedWidthReader(4);
$this->assertSame(
1, $reader->validateByteSequence(array(0x01, 0x02, 0x03), 3)
); //3 octets
$this->assertSame(
2, $reader->validateByteSequence(array(0x01, 0x0A), 2)
); //2 octets
$this->assertSame(
3, $reader->validateByteSequence(array(0xFE), 1)
); //1 octet
$this->assertSame(
0, $reader->validateByteSequence(array(0xFE, 0x03, 0x67, 0x9A), 4)
); //All 4 octets
}
public function testValidationFailsIfTooManyOctets()
{
$reader = new Swift_CharacterReader_GenericFixedWidthReader(6);
$this->assertSame(-1, $reader->validateByteSequence(
array(0xFE, 0x03, 0x67, 0x9A, 0x10, 0x09, 0x85), 7
)); //7 octets
}
}

View File

@@ -0,0 +1,52 @@
<?php
class Swift_CharacterReader_UsAsciiReaderTest extends \PHPUnit_Framework_TestCase
{
/*
for ($c = '', $size = 1; false !== $bytes = $os->read($size); ) {
$c .= $bytes;
$size = $v->validateCharacter($c);
if (-1 == $size) {
throw new Exception( ... invalid char .. );
} elseif (0 == $size) {
return $c; //next character in $os
}
}
*/
private $_reader;
protected function setUp()
{
$this->_reader = new Swift_CharacterReader_UsAsciiReader();
}
public function testAllValidAsciiCharactersReturnZero()
{
for ($ordinal = 0x00; $ordinal <= 0x7F; ++$ordinal) {
$this->assertSame(
0, $this->_reader->validateByteSequence(array($ordinal), 1)
);
}
}
public function testMultipleBytesAreInvalid()
{
for ($ordinal = 0x00; $ordinal <= 0x7F; $ordinal += 2) {
$this->assertSame(
-1, $this->_reader->validateByteSequence(array($ordinal, $ordinal + 1), 2)
);
}
}
public function testBytesAboveAsciiRangeAreInvalid()
{
for ($ordinal = 0x80; $ordinal <= 0xFF; ++$ordinal) {
$this->assertSame(
-1, $this->_reader->validateByteSequence(array($ordinal), 1)
);
}
}
}

View File

@@ -0,0 +1,65 @@
<?php
class Swift_CharacterReader_Utf8ReaderTest extends \PHPUnit_Framework_TestCase
{
private $_reader;
protected function setUp()
{
$this->_reader = new Swift_CharacterReader_Utf8Reader();
}
public function testLeading7BitOctetCausesReturnZero()
{
for ($ordinal = 0x00; $ordinal <= 0x7F; ++$ordinal) {
$this->assertSame(
0, $this->_reader->validateByteSequence(array($ordinal), 1)
);
}
}
public function testLeadingByteOf2OctetCharCausesReturn1()
{
for ($octet = 0xC0; $octet <= 0xDF; ++$octet) {
$this->assertSame(
1, $this->_reader->validateByteSequence(array($octet), 1)
);
}
}
public function testLeadingByteOf3OctetCharCausesReturn2()
{
for ($octet = 0xE0; $octet <= 0xEF; ++$octet) {
$this->assertSame(
2, $this->_reader->validateByteSequence(array($octet), 1)
);
}
}
public function testLeadingByteOf4OctetCharCausesReturn3()
{
for ($octet = 0xF0; $octet <= 0xF7; ++$octet) {
$this->assertSame(
3, $this->_reader->validateByteSequence(array($octet), 1)
);
}
}
public function testLeadingByteOf5OctetCharCausesReturn4()
{
for ($octet = 0xF8; $octet <= 0xFB; ++$octet) {
$this->assertSame(
4, $this->_reader->validateByteSequence(array($octet), 1)
);
}
}
public function testLeadingByteOf6OctetCharCausesReturn5()
{
for ($octet = 0xFC; $octet <= 0xFD; ++$octet) {
$this->assertSame(
5, $this->_reader->validateByteSequence(array($octet), 1)
);
}
}
}

View File

@@ -0,0 +1,358 @@
<?php
class Swift_CharacterStream_ArrayCharacterStreamTest extends \SwiftMailerTestCase
{
public function testValidatorAlgorithmOnImportString()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importString(pack('C*',
0xD0, 0x94,
0xD0, 0xB6,
0xD0, 0xBE,
0xD1, 0x8D,
0xD0, 0xBB,
0xD0, 0xB0
)
);
}
public function testCharactersWrittenUseValidator()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$stream->write(pack('C*',
0xD0, 0xBB,
0xD1, 0x8E,
0xD0, 0xB1,
0xD1, 0x8B,
0xD1, 0x85
)
);
}
public function testReadCharactersAreInTact()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
//String
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
//Stream
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$stream->write(pack('C*',
0xD0, 0xBB,
0xD1, 0x8E,
0xD0, 0xB1,
0xD1, 0x8B,
0xD1, 0x85
)
);
$this->assertIdenticalBinary(pack('C*', 0xD0, 0x94), $stream->read(1));
$this->assertIdenticalBinary(
pack('C*', 0xD0, 0xB6, 0xD0, 0xBE), $stream->read(2)
);
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xBB), $stream->read(1));
$this->assertIdenticalBinary(
pack('C*', 0xD1, 0x8E, 0xD0, 0xB1, 0xD1, 0x8B), $stream->read(3)
);
$this->assertIdenticalBinary(pack('C*', 0xD1, 0x85), $stream->read(1));
$this->assertFalse($stream->read(1));
}
public function testCharactersCanBeReadAsByteArrays()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
//String
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
//Stream
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$stream->write(pack('C*',
0xD0, 0xBB,
0xD1, 0x8E,
0xD0, 0xB1,
0xD1, 0x8B,
0xD1, 0x85
)
);
$this->assertEquals(array(0xD0, 0x94), $stream->readBytes(1));
$this->assertEquals(array(0xD0, 0xB6, 0xD0, 0xBE), $stream->readBytes(2));
$this->assertEquals(array(0xD0, 0xBB), $stream->readBytes(1));
$this->assertEquals(
array(0xD1, 0x8E, 0xD0, 0xB1, 0xD1, 0x8B), $stream->readBytes(3)
);
$this->assertEquals(array(0xD1, 0x85), $stream->readBytes(1));
$this->assertFalse($stream->readBytes(1));
}
public function testRequestingLargeCharCountPastEndOfStream()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE),
$stream->read(100)
);
$this->assertFalse($stream->read(1));
}
public function testRequestingByteArrayCountPastEndOfStream()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$this->assertEquals(array(0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE),
$stream->readBytes(100)
);
$this->assertFalse($stream->readBytes(1));
}
public function testPointerOffsetCanBeSet()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0x94), $stream->read(1));
$stream->setPointer(0);
$this->assertIdenticalBinary(pack('C*', 0xD0, 0x94), $stream->read(1));
$stream->setPointer(2);
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xBE), $stream->read(1));
}
public function testContentsCanBeFlushed()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$stream->flushContents();
$this->assertFalse($stream->read(1));
}
public function testByteStreamCanBeImportingUsesValidator()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$os = $this->_getByteStream();
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$os->shouldReceive('setReadPointer')
->between(0, 1)
->with(0);
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0x94));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xB6));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xBE));
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importByteStream($os);
}
public function testImportingStreamProducesCorrectCharArray()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$os = $this->_getByteStream();
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$os->shouldReceive('setReadPointer')
->between(0, 1)
->with(0);
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0x94));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xB6));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xBE));
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importByteStream($os);
$this->assertIdenticalBinary(pack('C*', 0xD0, 0x94), $stream->read(1));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xB6), $stream->read(1));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xBE), $stream->read(1));
$this->assertFalse($stream->read(1));
}
public function testAlgorithmWithFixedWidthCharsets()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(2);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1, 0x8D), 2);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0, 0xBB), 2);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0, 0xB0), 2);
$stream = new Swift_CharacterStream_ArrayCharacterStream(
$factory, 'utf-8'
);
$stream->importString(pack('C*', 0xD1, 0x8D, 0xD0, 0xBB, 0xD0, 0xB0));
$this->assertIdenticalBinary(pack('C*', 0xD1, 0x8D), $stream->read(1));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xBB), $stream->read(1));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xB0), $stream->read(1));
$this->assertFalse($stream->read(1));
}
private function _getReader()
{
return $this->getMockery('Swift_CharacterReader');
}
private function _getFactory($reader)
{
$factory = $this->getMockery('Swift_CharacterReaderFactory');
$factory->shouldReceive('getReaderFor')
->zeroOrMoreTimes()
->with('utf-8')
->andReturn($reader);
return $factory;
}
private function _getByteStream()
{
return $this->getMockery('Swift_OutputByteStream');
}
}

View File

@@ -0,0 +1,176 @@
<?php
class One
{
public $arg1;
public $arg2;
public function __construct($arg1 = null, $arg2 = null)
{
$this->arg1 = $arg1;
$this->arg2 = $arg2;
}
}
class Swift_DependencyContainerTest extends \PHPUnit_Framework_TestCase
{
private $_container;
protected function setUp()
{
$this->_container = new Swift_DependencyContainer();
}
public function testRegisterAndLookupValue()
{
$this->_container->register('foo')->asValue('bar');
$this->assertEquals('bar', $this->_container->lookup('foo'));
}
public function testHasReturnsTrueForRegisteredValue()
{
$this->_container->register('foo')->asValue('bar');
$this->assertTrue($this->_container->has('foo'));
}
public function testHasReturnsFalseForUnregisteredValue()
{
$this->assertFalse($this->_container->has('foo'));
}
public function testRegisterAndLookupNewInstance()
{
$this->_container->register('one')->asNewInstanceOf('One');
$this->assertInstanceOf('One', $this->_container->lookup('one'));
}
public function testHasReturnsTrueForRegisteredInstance()
{
$this->_container->register('one')->asNewInstanceOf('One');
$this->assertTrue($this->_container->has('one'));
}
public function testNewInstanceIsAlwaysNew()
{
$this->_container->register('one')->asNewInstanceOf('One');
$a = $this->_container->lookup('one');
$b = $this->_container->lookup('one');
$this->assertEquals($a, $b);
}
public function testRegisterAndLookupSharedInstance()
{
$this->_container->register('one')->asSharedInstanceOf('One');
$this->assertInstanceOf('One', $this->_container->lookup('one'));
}
public function testHasReturnsTrueForSharedInstance()
{
$this->_container->register('one')->asSharedInstanceOf('One');
$this->assertTrue($this->_container->has('one'));
}
public function testMultipleSharedInstancesAreSameInstance()
{
$this->_container->register('one')->asSharedInstanceOf('One');
$a = $this->_container->lookup('one');
$b = $this->_container->lookup('one');
$this->assertEquals($a, $b);
}
public function testNewInstanceWithDependencies()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('one')->asNewInstanceOf('One')
->withDependencies(array('foo'));
$obj = $this->_container->lookup('one');
$this->assertSame('FOO', $obj->arg1);
}
public function testNewInstanceWithMultipleDependencies()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('bar')->asValue(42);
$this->_container->register('one')->asNewInstanceOf('One')
->withDependencies(array('foo', 'bar'));
$obj = $this->_container->lookup('one');
$this->assertSame('FOO', $obj->arg1);
$this->assertSame(42, $obj->arg2);
}
public function testNewInstanceWithInjectedObjects()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('one')->asNewInstanceOf('One');
$this->_container->register('two')->asNewInstanceOf('One')
->withDependencies(array('one', 'foo'));
$obj = $this->_container->lookup('two');
$this->assertEquals($this->_container->lookup('one'), $obj->arg1);
$this->assertSame('FOO', $obj->arg2);
}
public function testNewInstanceWithAddConstructorValue()
{
$this->_container->register('one')->asNewInstanceOf('One')
->addConstructorValue('x')
->addConstructorValue(99);
$obj = $this->_container->lookup('one');
$this->assertSame('x', $obj->arg1);
$this->assertSame(99, $obj->arg2);
}
public function testNewInstanceWithAddConstructorLookup()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('bar')->asValue(42);
$this->_container->register('one')->asNewInstanceOf('One')
->addConstructorLookup('foo')
->addConstructorLookup('bar');
$obj = $this->_container->lookup('one');
$this->assertSame('FOO', $obj->arg1);
$this->assertSame(42, $obj->arg2);
}
public function testResolvedDependenciesCanBeLookedUp()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('one')->asNewInstanceOf('One');
$this->_container->register('two')->asNewInstanceOf('One')
->withDependencies(array('one', 'foo'));
$deps = $this->_container->createDependenciesFor('two');
$this->assertEquals(
array($this->_container->lookup('one'), 'FOO'), $deps
);
}
public function testArrayOfDependenciesCanBeSpecified()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('one')->asNewInstanceOf('One');
$this->_container->register('two')->asNewInstanceOf('One')
->withDependencies(array(array('one', 'foo'), 'foo'));
$obj = $this->_container->lookup('two');
$this->assertEquals(array($this->_container->lookup('one'), 'FOO'), $obj->arg1);
$this->assertSame('FOO', $obj->arg2);
}
public function testAliasCanBeSet()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('bar')->asAliasOf('foo');
$this->assertSame('FOO', $this->_container->lookup('bar'));
}
public function testAliasOfAliasCanBeSet()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('bar')->asAliasOf('foo');
$this->_container->register('zip')->asAliasOf('bar');
$this->_container->register('button')->asAliasOf('zip');
$this->assertSame('FOO', $this->_container->lookup('button'));
}
}

View File

@@ -0,0 +1,173 @@
<?php
class Swift_Encoder_Base64EncoderTest extends \PHPUnit_Framework_TestCase
{
private $_encoder;
protected function setUp()
{
$this->_encoder = new Swift_Encoder_Base64Encoder();
}
/*
There's really no point in testing the entire base64 encoding to the
level QP encoding has been tested. base64_encode() has been in PHP for
years.
*/
public function testInputOutputRatioIs3to4Bytes()
{
/*
RFC 2045, 6.8
The encoding process represents 24-bit groups of input bits as output
strings of 4 encoded characters. Proceeding from left to right, a
24-bit input group is formed by concatenating 3 8bit input groups.
These 24 bits are then treated as 4 concatenated 6-bit groups, each
of which is translated into a single digit in the base64 alphabet.
*/
$this->assertEquals(
'MTIz', $this->_encoder->encodeString('123'),
'%s: 3 bytes of input should yield 4 bytes of output'
);
$this->assertEquals(
'MTIzNDU2', $this->_encoder->encodeString('123456'),
'%s: 6 bytes in input should yield 8 bytes of output'
);
$this->assertEquals(
'MTIzNDU2Nzg5', $this->_encoder->encodeString('123456789'),
'%s: 9 bytes in input should yield 12 bytes of output'
);
}
public function testPadLength()
{
/*
RFC 2045, 6.8
Special processing is performed if fewer than 24 bits are available
at the end of the data being encoded. A full encoding quantum is
always completed at the end of a body. When fewer than 24 input bits
are available in an input group, zero bits are added (on the right)
to form an integral number of 6-bit groups. Padding at the end of
the data is performed using the "=" character. Since all base64
input is an integral number of octets, only the following cases can
arise: (1) the final quantum of encoding input is an integral
multiple of 24 bits; here, the final unit of encoded output will be
an integral multiple of 4 characters with no "=" padding, (2) the
final quantum of encoding input is exactly 8 bits; here, the final
unit of encoded output will be two characters followed by two "="
padding characters, or (3) the final quantum of encoding input is
exactly 16 bits; here, the final unit of encoded output will be three
characters followed by one "=" padding character.
*/
for ($i = 0; $i < 30; ++$i) {
$input = pack('C', rand(0, 255));
$this->assertRegExp(
'~^[a-zA-Z0-9/\+]{2}==$~', $this->_encoder->encodeString($input),
'%s: A single byte should have 2 bytes of padding'
);
}
for ($i = 0; $i < 30; ++$i) {
$input = pack('C*', rand(0, 255), rand(0, 255));
$this->assertRegExp(
'~^[a-zA-Z0-9/\+]{3}=$~', $this->_encoder->encodeString($input),
'%s: Two bytes should have 1 byte of padding'
);
}
for ($i = 0; $i < 30; ++$i) {
$input = pack('C*', rand(0, 255), rand(0, 255), rand(0, 255));
$this->assertRegExp(
'~^[a-zA-Z0-9/\+]{4}$~', $this->_encoder->encodeString($input),
'%s: Three bytes should have no padding'
);
}
}
public function testMaximumLineLengthIs76Characters()
{
/*
The encoded output stream must be represented in lines of no more
than 76 characters each. All line breaks or other characters not
found in Table 1 must be ignored by decoding software.
*/
$input =
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$output =
'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQk'.//38
'NERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1'."\r\n".//76 *
'Njc4OTBhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3'.//38
'h5ekFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFla'."\r\n".//76 *
'MTIzNDU2Nzg5MEFCQ0RFRkdISUpLTE1OT1BRUl'.//38
'NUVVZXWFla'; //48
$this->assertEquals(
$output, $this->_encoder->encodeString($input),
'%s: Lines should be no more than 76 characters'
);
}
public function testMaximumLineLengthCanBeSpecified()
{
$input =
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$output =
'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQk'.//38
'NERUZHSElKS0'."\r\n".//50 *
'xNTk9QUVJTVFVWV1hZWjEyMzQ1Njc4OTBhYmNk'.//38
'ZWZnaGlqa2xt'."\r\n".//50 *
'bm9wcXJzdHV2d3h5ekFCQ0RFRkdISUpLTE1OT1'.//38
'BRUlNUVVZXWF'."\r\n".//50 *
'laMTIzNDU2Nzg5MEFCQ0RFRkdISUpLTE1OT1BR'.//38
'UlNUVVZXWFla'; //50 *
$this->assertEquals(
$output, $this->_encoder->encodeString($input, 0, 50),
'%s: Lines should be no more than 100 characters'
);
}
public function testFirstLineLengthCanBeDifferent()
{
$input =
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$output =
'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQk'.//38
'NERUZHSElKS0xNTk9QU'."\r\n".//57 *
'VJTVFVWV1hZWjEyMzQ1Njc4OTBhYmNkZWZnaGl'.//38
'qa2xtbm9wcXJzdHV2d3h5ekFCQ0RFRkdISUpLT'."\r\n".//76 *
'E1OT1BRUlNUVVZXWFlaMTIzNDU2Nzg5MEFCQ0R'.//38
'FRkdISUpLTE1OT1BRUlNUVVZXWFla'; //67
$this->assertEquals(
$output, $this->_encoder->encodeString($input, 19),
'%s: First line offset is 19 so first line should be 57 chars long'
);
}
}

View File

@@ -0,0 +1,400 @@
<?php
class Swift_Encoder_QpEncoderTest extends \SwiftMailerTestCase
{
/* -- RFC 2045, 6.7 --
(1) (General 8bit representation) Any octet, except a CR or
LF that is part of a CRLF line break of the canonical
(standard) form of the data being encoded, may be
represented by an "=" followed by a two digit
hexadecimal representation of the octet's value. The
digits of the hexadecimal alphabet, for this purpose,
are "0123456789ABCDEF". Uppercase letters must be
used; lowercase letters are not allowed. Thus, for
example, the decimal value 12 (US-ASCII form feed) can
be represented by "=0C", and the decimal value 61 (US-
ASCII EQUAL SIGN) can be represented by "=3D". This
rule must be followed except when the following rules
allow an alternative encoding.
*/
public function testPermittedCharactersAreNotEncoded()
{
/* -- RFC 2045, 6.7 --
(2) (Literal representation) Octets with decimal values of
33 through 60 inclusive, and 62 through 126, inclusive,
MAY be represented as the US-ASCII characters which
correspond to those octets (EXCLAMATION POINT through
LESS THAN, and GREATER THAN through TILDE,
respectively).
*/
foreach (array_merge(range(33, 60), range(62, 126)) as $ordinal) {
$char = chr($ordinal);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($char);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array($ordinal));
$charStream->shouldReceive('readBytes')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertIdenticalBinary($char, $encoder->encodeString($char));
}
}
public function testWhiteSpaceAtLineEndingIsEncoded()
{
/* -- RFC 2045, 6.7 --
(3) (White Space) Octets with values of 9 and 32 MAY be
represented as US-ASCII TAB (HT) and SPACE characters,
respectively, but MUST NOT be so represented at the end
of an encoded line. Any TAB (HT) or SPACE characters
on an encoded line MUST thus be followed on that line
by a printable character. In particular, an "=" at the
end of an encoded line, indicating a soft line break
(see rule #5) may follow one or more TAB (HT) or SPACE
characters. It follows that an octet with decimal
value 9 or 32 appearing at the end of an encoded line
must be represented according to Rule #1. This rule is
necessary because some MTAs (Message Transport Agents,
programs which transport messages from one user to
another, or perform a portion of such transfers) are
known to pad lines of text with SPACEs, and others are
known to remove "white space" characters from the end
of a line. Therefore, when decoding a Quoted-Printable
body, any trailing white space on a line must be
deleted, as it will necessarily have been added by
intermediate transport agents.
*/
$HT = chr(0x09); //9
$SPACE = chr(0x20); //32
//HT
$string = 'a'.$HT.$HT."\r\n".'b';
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('a')));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x09));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x09));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('b')));
$charStream->shouldReceive('readBytes')->once()->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals(
'a'.$HT.'=09'."\r\n".'b',
$encoder->encodeString($string)
);
//SPACE
$string = 'a'.$SPACE.$SPACE."\r\n".'b';
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('a')));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x20));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x20));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('b')));
$charStream->shouldReceive('readBytes')->once()->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals(
'a'.$SPACE.'=20'."\r\n".'b',
$encoder->encodeString($string)
);
}
public function testCRLFIsLeftAlone()
{
/*
(4) (Line Breaks) A line break in a text body, represented
as a CRLF sequence in the text canonical form, must be
represented by a (RFC 822) line break, which is also a
CRLF sequence, in the Quoted-Printable encoding. Since
the canonical representation of media types other than
text do not generally include the representation of
line breaks as CRLF sequences, no hard line breaks
(i.e. line breaks that are intended to be meaningful
and to be displayed to the user) can occur in the
quoted-printable encoding of such types. Sequences
like "=0D", "=0A", "=0A=0D" and "=0D=0A" will routinely
appear in non-text data represented in quoted-
printable, of course.
Note that many implementations may elect to encode the
local representation of various content types directly
rather than converting to canonical form first,
encoding, and then converting back to local
representation. In particular, this may apply to plain
text material on systems that use newline conventions
other than a CRLF terminator sequence. Such an
implementation optimization is permissible, but only
when the combined canonicalization-encoding step is
equivalent to performing the three steps separately.
*/
$string = 'a'."\r\n".'b'."\r\n".'c'."\r\n";
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('a')));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('b')));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('c')));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')->once()->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals($string, $encoder->encodeString($string));
}
public function testLinesLongerThan76CharactersAreSoftBroken()
{
/*
(5) (Soft Line Breaks) The Quoted-Printable encoding
REQUIRES that encoded lines be no more than 76
characters long. If longer lines are to be encoded
with the Quoted-Printable encoding, "soft" line breaks
must be used. An equal sign as the last character on a
encoded line indicates such a non-significant ("soft")
line break in the encoded text.
*/
$input = str_repeat('a', 140);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($input);
$output = '';
for ($i = 0; $i < 140; ++$i) {
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
if (75 == $i) {
$output .= "=\r\n";
}
$output .= 'a';
}
$charStream->shouldReceive('readBytes')
->once()
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals($output, $encoder->encodeString($input));
}
public function testMaxLineLengthCanBeSpecified()
{
$input = str_repeat('a', 100);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($input);
$output = '';
for ($i = 0; $i < 100; ++$i) {
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
if (53 == $i) {
$output .= "=\r\n";
}
$output .= 'a';
}
$charStream->shouldReceive('readBytes')
->once()
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals($output, $encoder->encodeString($input, 0, 54));
}
public function testBytesBelowPermittedRangeAreEncoded()
{
/*
According to Rule (1 & 2)
*/
foreach (range(0, 32) as $ordinal) {
$char = chr($ordinal);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($char);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array($ordinal));
$charStream->shouldReceive('readBytes')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals(
sprintf('=%02X', $ordinal), $encoder->encodeString($char)
);
}
}
public function testDecimalByte61IsEncoded()
{
/*
According to Rule (1 & 2)
*/
$char = '=';
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($char);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(61));
$charStream->shouldReceive('readBytes')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals('=3D', $encoder->encodeString('='));
}
public function testBytesAbovePermittedRangeAreEncoded()
{
/*
According to Rule (1 & 2)
*/
foreach (range(127, 255) as $ordinal) {
$char = chr($ordinal);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($char);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array($ordinal));
$charStream->shouldReceive('readBytes')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals(
sprintf('=%02X', $ordinal), $encoder->encodeString($char)
);
}
}
public function testFirstLineLengthCanBeDifferent()
{
$input = str_repeat('a', 140);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($input);
$output = '';
for ($i = 0; $i < 140; ++$i) {
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
if (53 == $i || 53 + 75 == $i) {
$output .= "=\r\n";
}
$output .= 'a';
}
$charStream->shouldReceive('readBytes')
->once()
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals(
$output, $encoder->encodeString($input, 22),
'%s: First line should start at offset 22 so can only have max length 54'
);
}
public function testTextIsPreWrapped()
{
$encoder = $this->createEncoder();
$input = str_repeat('a', 70)."\r\n".
str_repeat('a', 70)."\r\n".
str_repeat('a', 70);
$this->assertEquals(
$input, $encoder->encodeString($input)
);
}
private function _createCharStream()
{
return $this->getMockery('Swift_CharacterStream')->shouldIgnoreMissing();
}
private function createEncoder()
{
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$charStream = new Swift_CharacterStream_NgCharacterStream($factory, 'utf-8');
return new Swift_Encoder_QpEncoder($charStream);
}
}

View File

@@ -0,0 +1,141 @@
<?php
class Swift_Encoder_Rfc2231EncoderTest extends \SwiftMailerTestCase
{
private $_rfc2045Token = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7E]+$/D';
/* --
This algorithm is described in RFC 2231, but is barely touched upon except
for mentioning bytes can be represented as their octet values (e.g. %20 for
the SPACE character).
The tests here focus on how to use that representation to always generate text
which matches RFC 2045's definition of "token".
*/
public function testEncodingAsciiCharactersProducesValidToken()
{
$charStream = $this->getMockery('Swift_CharacterStream');
$string = '';
foreach (range(0x00, 0x7F) as $octet) {
$char = pack('C', $octet);
$string .= $char;
$charStream->shouldReceive('read')
->once()
->andReturn($char);
}
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('read')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
$encoded = $encoder->encodeString($string);
foreach (explode("\r\n", $encoded) as $line) {
$this->assertRegExp($this->_rfc2045Token, $line,
'%s: Encoder should always return a valid RFC 2045 token.');
}
}
public function testEncodingNonAsciiCharactersProducesValidToken()
{
$charStream = $this->getMockery('Swift_CharacterStream');
$string = '';
foreach (range(0x80, 0xFF) as $octet) {
$char = pack('C', $octet);
$string .= $char;
$charStream->shouldReceive('read')
->once()
->andReturn($char);
}
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('read')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
$encoded = $encoder->encodeString($string);
foreach (explode("\r\n", $encoded) as $line) {
$this->assertRegExp($this->_rfc2045Token, $line,
'%s: Encoder should always return a valid RFC 2045 token.');
}
}
public function testMaximumLineLengthCanBeSet()
{
$charStream = $this->getMockery('Swift_CharacterStream');
$string = '';
for ($x = 0; $x < 200; ++$x) {
$char = 'a';
$string .= $char;
$charStream->shouldReceive('read')
->once()
->andReturn($char);
}
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('read')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
$encoded = $encoder->encodeString($string, 0, 75);
$this->assertEquals(
str_repeat('a', 75)."\r\n".
str_repeat('a', 75)."\r\n".
str_repeat('a', 50),
$encoded,
'%s: Lines should be wrapped at each 75 characters'
);
}
public function testFirstLineCanHaveShorterLength()
{
$charStream = $this->getMockery('Swift_CharacterStream');
$string = '';
for ($x = 0; $x < 200; ++$x) {
$char = 'a';
$string .= $char;
$charStream->shouldReceive('read')
->once()
->andReturn($char);
}
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('read')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
$encoded = $encoder->encodeString($string, 25, 75);
$this->assertEquals(
str_repeat('a', 50)."\r\n".
str_repeat('a', 75)."\r\n".
str_repeat('a', 75),
$encoded,
'%s: First line should be 25 bytes shorter than the others.'
);
}
}

View File

@@ -0,0 +1,34 @@
<?php
class Swift_Events_CommandEventTest extends \PHPUnit_Framework_TestCase
{
public function testCommandCanBeFetchedByGetter()
{
$evt = $this->_createEvent($this->_createTransport(), "FOO\r\n");
$this->assertEquals("FOO\r\n", $evt->getCommand());
}
public function testSuccessCodesCanBeFetchedViaGetter()
{
$evt = $this->_createEvent($this->_createTransport(), "FOO\r\n", array(250));
$this->assertEquals(array(250), $evt->getSuccessCodes());
}
public function testSourceIsBuffer()
{
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, "FOO\r\n");
$ref = $evt->getSource();
$this->assertEquals($transport, $ref);
}
private function _createEvent(Swift_Transport $source, $command, $successCodes = array())
{
return new Swift_Events_CommandEvent($source, $command, $successCodes);
}
private function _createTransport()
{
return $this->getMockBuilder('Swift_Transport')->getMock();
}
}

View File

@@ -0,0 +1,32 @@
<?php
class Swift_Events_EventObjectTest extends \PHPUnit_Framework_TestCase
{
public function testEventSourceCanBeReturnedViaGetter()
{
$source = new stdClass();
$evt = $this->_createEvent($source);
$ref = $evt->getSource();
$this->assertEquals($source, $ref);
}
public function testEventDoesNotHaveCancelledBubbleWhenNew()
{
$source = new stdClass();
$evt = $this->_createEvent($source);
$this->assertFalse($evt->bubbleCancelled());
}
public function testBubbleCanBeCancelledInEvent()
{
$source = new stdClass();
$evt = $this->_createEvent($source);
$evt->cancelBubble();
$this->assertTrue($evt->bubbleCancelled());
}
private function _createEvent($source)
{
return new Swift_Events_EventObject($source);
}
}

View File

@@ -0,0 +1,38 @@
<?php
class Swift_Events_ResponseEventTest extends \PHPUnit_Framework_TestCase
{
public function testResponseCanBeFetchViaGetter()
{
$evt = $this->_createEvent($this->_createTransport(), "250 Ok\r\n", true);
$this->assertEquals("250 Ok\r\n", $evt->getResponse(),
'%s: Response should be available via getResponse()'
);
}
public function testResultCanBeFetchedViaGetter()
{
$evt = $this->_createEvent($this->_createTransport(), "250 Ok\r\n", false);
$this->assertFalse($evt->isValid(),
'%s: Result should be checkable via isValid()'
);
}
public function testSourceIsBuffer()
{
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, "250 Ok\r\n", true);
$ref = $evt->getSource();
$this->assertEquals($transport, $ref);
}
private function _createEvent(Swift_Transport $source, $response, $result)
{
return new Swift_Events_ResponseEvent($source, $response, $result);
}
private function _createTransport()
{
return $this->getMockBuilder('Swift_Transport')->getMock();
}
}

View File

@@ -0,0 +1,97 @@
<?php
class Swift_Events_SendEventTest extends \PHPUnit_Framework_TestCase
{
public function testMessageCanBeFetchedViaGetter()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$ref = $evt->getMessage();
$this->assertEquals($message, $ref,
'%s: Message should be returned from getMessage()'
);
}
public function testTransportCanBeFetchViaGetter()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$ref = $evt->getTransport();
$this->assertEquals($transport, $ref,
'%s: Transport should be returned from getTransport()'
);
}
public function testTransportCanBeFetchViaGetSource()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$ref = $evt->getSource();
$this->assertEquals($transport, $ref,
'%s: Transport should be returned from getSource()'
);
}
public function testResultCanBeSetAndGet()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$evt->setResult(
Swift_Events_SendEvent::RESULT_SUCCESS | Swift_Events_SendEvent::RESULT_TENTATIVE
);
$this->assertTrue((bool) ($evt->getResult() & Swift_Events_SendEvent::RESULT_SUCCESS));
$this->assertTrue((bool) ($evt->getResult() & Swift_Events_SendEvent::RESULT_TENTATIVE));
}
public function testFailedRecipientsCanBeSetAndGet()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$evt->setFailedRecipients(array('foo@bar', 'zip@button'));
$this->assertEquals(array('foo@bar', 'zip@button'), $evt->getFailedRecipients(),
'%s: FailedRecipients should be returned from getter'
);
}
public function testFailedRecipientsGetsPickedUpCorrectly()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$this->assertEquals(array(), $evt->getFailedRecipients());
}
private function _createEvent(Swift_Transport $source,
Swift_Mime_Message $message)
{
return new Swift_Events_SendEvent($source, $message);
}
private function _createTransport()
{
return $this->getMockBuilder('Swift_Transport')->getMock();
}
private function _createMessage()
{
return $this->getMockBuilder('Swift_Mime_Message')->getMock();
}
}

View File

@@ -0,0 +1,142 @@
<?php
class Swift_Events_SimpleEventDispatcherTest extends \PHPUnit_Framework_TestCase
{
private $_dispatcher;
protected function setUp()
{
$this->_dispatcher = new Swift_Events_SimpleEventDispatcher();
}
public function testSendEventCanBeCreated()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$message = $this->getMockBuilder('Swift_Mime_Message')->getMock();
$evt = $this->_dispatcher->createSendEvent($transport, $message);
$this->assertInstanceOf('Swift_Events_SendEvent', $evt);
$this->assertSame($message, $evt->getMessage());
$this->assertSame($transport, $evt->getTransport());
}
public function testCommandEventCanBeCreated()
{
$buf = $this->getMockBuilder('Swift_Transport')->getMock();
$evt = $this->_dispatcher->createCommandEvent($buf, "FOO\r\n", array(250));
$this->assertInstanceOf('Swift_Events_CommandEvent', $evt);
$this->assertSame($buf, $evt->getSource());
$this->assertEquals("FOO\r\n", $evt->getCommand());
$this->assertEquals(array(250), $evt->getSuccessCodes());
}
public function testResponseEventCanBeCreated()
{
$buf = $this->getMockBuilder('Swift_Transport')->getMock();
$evt = $this->_dispatcher->createResponseEvent($buf, "250 Ok\r\n", true);
$this->assertInstanceOf('Swift_Events_ResponseEvent', $evt);
$this->assertSame($buf, $evt->getSource());
$this->assertEquals("250 Ok\r\n", $evt->getResponse());
$this->assertTrue($evt->isValid());
}
public function testTransportChangeEventCanBeCreated()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$evt = $this->_dispatcher->createTransportChangeEvent($transport);
$this->assertInstanceOf('Swift_Events_TransportChangeEvent', $evt);
$this->assertSame($transport, $evt->getSource());
}
public function testTransportExceptionEventCanBeCreated()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$ex = new Swift_TransportException('');
$evt = $this->_dispatcher->createTransportExceptionEvent($transport, $ex);
$this->assertInstanceOf('Swift_Events_TransportExceptionEvent', $evt);
$this->assertSame($transport, $evt->getSource());
$this->assertSame($ex, $evt->getException());
}
public function testListenersAreNotifiedOfDispatchedEvent()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$evt = $this->_dispatcher->createTransportChangeEvent($transport);
$listenerA = $this->getMockBuilder('Swift_Events_TransportChangeListener')->getMock();
$listenerB = $this->getMockBuilder('Swift_Events_TransportChangeListener')->getMock();
$this->_dispatcher->bindEventListener($listenerA);
$this->_dispatcher->bindEventListener($listenerB);
$listenerA->expects($this->once())
->method('transportStarted')
->with($evt);
$listenerB->expects($this->once())
->method('transportStarted')
->with($evt);
$this->_dispatcher->dispatchEvent($evt, 'transportStarted');
}
public function testListenersAreOnlyCalledIfImplementingCorrectInterface()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$message = $this->getMockBuilder('Swift_Mime_Message')->getMock();
$evt = $this->_dispatcher->createSendEvent($transport, $message);
$targetListener = $this->getMockBuilder('Swift_Events_SendListener')->getMock();
$otherListener = $this->getMockBuilder('DummyListener')->getMock();
$this->_dispatcher->bindEventListener($targetListener);
$this->_dispatcher->bindEventListener($otherListener);
$targetListener->expects($this->once())
->method('sendPerformed')
->with($evt);
$otherListener->expects($this->never())
->method('sendPerformed');
$this->_dispatcher->dispatchEvent($evt, 'sendPerformed');
}
public function testListenersCanCancelBubblingOfEvent()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$message = $this->getMockBuilder('Swift_Mime_Message')->getMock();
$evt = $this->_dispatcher->createSendEvent($transport, $message);
$listenerA = $this->getMockBuilder('Swift_Events_SendListener')->getMock();
$listenerB = $this->getMockBuilder('Swift_Events_SendListener')->getMock();
$this->_dispatcher->bindEventListener($listenerA);
$this->_dispatcher->bindEventListener($listenerB);
$listenerA->expects($this->once())
->method('sendPerformed')
->with($evt)
->will($this->returnCallback(function ($object) {
$object->cancelBubble(true);
}));
$listenerB->expects($this->never())
->method('sendPerformed');
$this->_dispatcher->dispatchEvent($evt, 'sendPerformed');
$this->assertTrue($evt->bubbleCancelled());
}
private function _createDispatcher(array $map)
{
return new Swift_Events_SimpleEventDispatcher($map);
}
}
class DummyListener implements Swift_Events_EventListener
{
public function sendPerformed(Swift_Events_SendEvent $evt)
{
}
}

View File

@@ -0,0 +1,30 @@
<?php
class Swift_Events_TransportChangeEventTest extends \PHPUnit_Framework_TestCase
{
public function testGetTransportReturnsTransport()
{
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport);
$ref = $evt->getTransport();
$this->assertEquals($transport, $ref);
}
public function testSourceIsTransport()
{
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport);
$ref = $evt->getSource();
$this->assertEquals($transport, $ref);
}
private function _createEvent(Swift_Transport $source)
{
return new Swift_Events_TransportChangeEvent($source);
}
private function _createTransport()
{
return $this->getMockBuilder('Swift_Transport')->getMock();
}
}

View File

@@ -0,0 +1,41 @@
<?php
class Swift_Events_TransportExceptionEventTest extends \PHPUnit_Framework_TestCase
{
public function testExceptionCanBeFetchViaGetter()
{
$ex = $this->_createException();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $ex);
$ref = $evt->getException();
$this->assertEquals($ex, $ref,
'%s: Exception should be available via getException()'
);
}
public function testSourceIsTransport()
{
$ex = $this->_createException();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $ex);
$ref = $evt->getSource();
$this->assertEquals($transport, $ref,
'%s: Transport should be available via getSource()'
);
}
private function _createEvent(Swift_Transport $transport, Swift_TransportException $ex)
{
return new Swift_Events_TransportExceptionEvent($transport, $ex);
}
private function _createTransport()
{
return $this->getMockBuilder('Swift_Transport')->getMock();
}
private function _createException()
{
return new Swift_TransportException('');
}
}

View File

@@ -0,0 +1,240 @@
<?php
class Swift_KeyCache_ArrayKeyCacheTest extends \PHPUnit_Framework_TestCase
{
private $_key1 = 'key1';
private $_key2 = 'key2';
public function testStringDataCanBeSetAndFetched()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeOverwritten()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->setString(
$this->_key1, 'foo', 'whatever', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('whatever', $cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeAppended()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->setString(
$this->_key1, 'foo', 'ing', Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testing', $cache->getString($this->_key1, 'foo'));
}
public function testHasKeyReturnValue()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyIsWellPartitioned()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->setString(
$this->_key2, 'foo', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $cache->getString($this->_key2, 'foo'));
}
public function testItemKeyIsWellPartitioned()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->setString(
$this->_key1, 'bar', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $cache->getString($this->_key1, 'bar'));
}
public function testByteStreamCanBeImported()
{
$os = $this->_createOutputStream();
$os->expects($this->at(0))
->method('read')
->will($this->returnValue('abc'));
$os->expects($this->at(1))
->method('read')
->will($this->returnValue('def'));
$os->expects($this->at(2))
->method('read')
->will($this->returnValue(false));
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('abcdef', $cache->getString($this->_key1, 'foo'));
}
public function testByteStreamCanBeAppended()
{
$os1 = $this->_createOutputStream();
$os1->expects($this->at(0))
->method('read')
->will($this->returnValue('abc'));
$os1->expects($this->at(1))
->method('read')
->will($this->returnValue('def'));
$os1->expects($this->at(2))
->method('read')
->will($this->returnValue(false));
$os2 = $this->_createOutputStream();
$os2->expects($this->at(0))
->method('read')
->will($this->returnValue('xyz'));
$os2->expects($this->at(1))
->method('read')
->will($this->returnValue('uvw'));
$os2->expects($this->at(2))
->method('read')
->will($this->returnValue(false));
$is = $this->_createKeyCacheInputStream(true);
$cache = $this->_createCache($is);
$cache->importFromByteStream(
$this->_key1, 'foo', $os1, Swift_KeyCache::MODE_APPEND
);
$cache->importFromByteStream(
$this->_key1, 'foo', $os2, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('abcdefxyzuvw', $cache->getString($this->_key1, 'foo'));
}
public function testByteStreamAndStringCanBeAppended()
{
$os = $this->_createOutputStream();
$os->expects($this->at(0))
->method('read')
->will($this->returnValue('abc'));
$os->expects($this->at(1))
->method('read')
->will($this->returnValue('def'));
$os->expects($this->at(2))
->method('read')
->will($this->returnValue(false));
$is = $this->_createKeyCacheInputStream(true);
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_APPEND
);
$cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testabcdef', $cache->getString($this->_key1, 'foo'));
}
public function testDataCanBeExportedToByteStream()
{
//See acceptance test for more detail
$is = $this->_createInputStream();
$is->expects($this->atLeastOnce())
->method('write');
$kcis = $this->_createKeyCacheInputStream(true);
$cache = $this->_createCache($kcis);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->exportToByteStream($this->_key1, 'foo', $is);
}
public function testKeyCanBeCleared()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($cache->hasKey($this->_key1, 'foo'));
$cache->clearKey($this->_key1, 'foo');
$this->assertFalse($cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyCanBeCleared()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->setString(
$this->_key1, 'bar', 'xyz', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($cache->hasKey($this->_key1, 'foo'));
$this->assertTrue($cache->hasKey($this->_key1, 'bar'));
$cache->clearAll($this->_key1);
$this->assertFalse($cache->hasKey($this->_key1, 'foo'));
$this->assertFalse($cache->hasKey($this->_key1, 'bar'));
}
private function _createCache($is)
{
return new Swift_KeyCache_ArrayKeyCache($is);
}
private function _createKeyCacheInputStream()
{
return $this->getMockBuilder('Swift_KeyCache_KeyCacheInputStream')->getMock();
}
private function _createOutputStream()
{
return $this->getMockBuilder('Swift_OutputByteStream')->getMock();
}
private function _createInputStream()
{
return $this->getMockBuilder('Swift_InputByteStream')->getMock();
}
}

View File

@@ -0,0 +1,73 @@
<?php
class Swift_KeyCache_SimpleKeyCacheInputStreamTest extends \PHPUnit_Framework_TestCase
{
private $_nsKey = 'ns1';
public function testStreamWritesToCacheInAppendMode()
{
$cache = $this->getMockBuilder('Swift_KeyCache')->getMock();
$cache->expects($this->at(0))
->method('setString')
->with($this->_nsKey, 'foo', 'a', Swift_KeyCache::MODE_APPEND);
$cache->expects($this->at(1))
->method('setString')
->with($this->_nsKey, 'foo', 'b', Swift_KeyCache::MODE_APPEND);
$cache->expects($this->at(2))
->method('setString')
->with($this->_nsKey, 'foo', 'c', Swift_KeyCache::MODE_APPEND);
$stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
$stream->setKeyCache($cache);
$stream->setNsKey($this->_nsKey);
$stream->setItemKey('foo');
$stream->write('a');
$stream->write('b');
$stream->write('c');
}
public function testFlushContentClearsKey()
{
$cache = $this->getMockBuilder('Swift_KeyCache')->getMock();
$cache->expects($this->once())
->method('clearKey')
->with($this->_nsKey, 'foo');
$stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
$stream->setKeyCache($cache);
$stream->setNsKey($this->_nsKey);
$stream->setItemKey('foo');
$stream->flushBuffers();
}
public function testClonedStreamStillReferencesSameCache()
{
$cache = $this->getMockBuilder('Swift_KeyCache')->getMock();
$cache->expects($this->at(0))
->method('setString')
->with($this->_nsKey, 'foo', 'a', Swift_KeyCache::MODE_APPEND);
$cache->expects($this->at(1))
->method('setString')
->with($this->_nsKey, 'foo', 'b', Swift_KeyCache::MODE_APPEND);
$cache->expects($this->at(2))
->method('setString')
->with('test', 'bar', 'x', Swift_KeyCache::MODE_APPEND);
$stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
$stream->setKeyCache($cache);
$stream->setNsKey($this->_nsKey);
$stream->setItemKey('foo');
$stream->write('a');
$stream->write('b');
$newStream = clone $stream;
$newStream->setKeyCache($cache);
$newStream->setNsKey('test');
$newStream->setItemKey('bar');
$newStream->write('x');
}
}

View File

@@ -0,0 +1,42 @@
<?php
class Swift_Mailer_ArrayRecipientIteratorTest extends \PHPUnit_Framework_TestCase
{
public function testHasNextReturnsFalseForEmptyArray()
{
$it = new Swift_Mailer_ArrayRecipientIterator(array());
$this->assertFalse($it->hasNext());
}
public function testHasNextReturnsTrueIfItemsLeft()
{
$it = new Swift_Mailer_ArrayRecipientIterator(array('foo@bar' => 'Foo'));
$this->assertTrue($it->hasNext());
}
public function testReadingToEndOfListCausesHasNextToReturnFalse()
{
$it = new Swift_Mailer_ArrayRecipientIterator(array('foo@bar' => 'Foo'));
$this->assertTrue($it->hasNext());
$it->nextRecipient();
$this->assertFalse($it->hasNext());
}
public function testReturnedValueHasPreservedKeyValuePair()
{
$it = new Swift_Mailer_ArrayRecipientIterator(array('foo@bar' => 'Foo'));
$this->assertEquals(array('foo@bar' => 'Foo'), $it->nextRecipient());
}
public function testIteratorMovesNextAfterEachIteration()
{
$it = new Swift_Mailer_ArrayRecipientIterator(array(
'foo@bar' => 'Foo',
'zip@button' => 'Zip thing',
'test@test' => null,
));
$this->assertEquals(array('foo@bar' => 'Foo'), $it->nextRecipient());
$this->assertEquals(array('zip@button' => 'Zip thing'), $it->nextRecipient());
$this->assertEquals(array('test@test' => null), $it->nextRecipient());
}
}

View File

@@ -0,0 +1,145 @@
<?php
class Swift_MailerTest extends \SwiftMailerTestCase
{
public function testTransportIsStartedWhenSending()
{
$transport = $this->_createTransport();
$message = $this->_createMessage();
$started = false;
$transport->shouldReceive('isStarted')
->zeroOrMoreTimes()
->andReturnUsing(function () use (&$started) {
return $started;
});
$transport->shouldReceive('start')
->once()
->andReturnUsing(function () use (&$started) {
$started = true;
return;
});
$mailer = $this->_createMailer($transport);
$mailer->send($message);
}
public function testTransportIsOnlyStartedOnce()
{
$transport = $this->_createTransport();
$message = $this->_createMessage();
$started = false;
$transport->shouldReceive('isStarted')
->zeroOrMoreTimes()
->andReturnUsing(function () use (&$started) {
return $started;
});
$transport->shouldReceive('start')
->once()
->andReturnUsing(function () use (&$started) {
$started = true;
return;
});
$mailer = $this->_createMailer($transport);
for ($i = 0; $i < 10; ++$i) {
$mailer->send($message);
}
}
public function testMessageIsPassedToTransport()
{
$transport = $this->_createTransport();
$message = $this->_createMessage();
$transport->shouldReceive('send')
->once()
->with($message, \Mockery::any());
$mailer = $this->_createMailer($transport);
$mailer->send($message);
}
public function testSendReturnsCountFromTransport()
{
$transport = $this->_createTransport();
$message = $this->_createMessage();
$transport->shouldReceive('send')
->once()
->with($message, \Mockery::any())
->andReturn(57);
$mailer = $this->_createMailer($transport);
$this->assertEquals(57, $mailer->send($message));
}
public function testFailedRecipientReferenceIsPassedToTransport()
{
$failures = array();
$transport = $this->_createTransport();
$message = $this->_createMessage();
$transport->shouldReceive('send')
->once()
->with($message, $failures)
->andReturn(57);
$mailer = $this->_createMailer($transport);
$mailer->send($message, $failures);
}
public function testSendRecordsRfcComplianceExceptionAsEntireSendFailure()
{
$failures = array();
$rfcException = new Swift_RfcComplianceException('test');
$transport = $this->_createTransport();
$message = $this->_createMessage();
$message->shouldReceive('getTo')
->once()
->andReturn(array('foo&invalid' => 'Foo', 'bar@valid.tld' => 'Bar'));
$transport->shouldReceive('send')
->once()
->with($message, $failures)
->andThrow($rfcException);
$mailer = $this->_createMailer($transport);
$this->assertEquals(0, $mailer->send($message, $failures), '%s: Should return 0');
$this->assertEquals(array('foo&invalid', 'bar@valid.tld'), $failures, '%s: Failures should contain all addresses since the entire message failed to compile');
}
public function testRegisterPluginDelegatesToTransport()
{
$plugin = $this->_createPlugin();
$transport = $this->_createTransport();
$mailer = $this->_createMailer($transport);
$transport->shouldReceive('registerPlugin')
->once()
->with($plugin);
$mailer->registerPlugin($plugin);
}
private function _createPlugin()
{
return $this->getMockery('Swift_Events_EventListener')->shouldIgnoreMissing();
}
private function _createTransport()
{
return $this->getMockery('Swift_Transport')->shouldIgnoreMissing();
}
private function _createMessage()
{
return $this->getMockery('Swift_Mime_Message')->shouldIgnoreMissing();
}
private function _createMailer(Swift_Transport $transport)
{
return new Swift_Mailer($transport);
}
}

View File

@@ -0,0 +1,129 @@
<?php
class Swift_MessageTest extends \PHPUnit_Framework_TestCase
{
public function testCloning()
{
$message1 = new Swift_Message('subj', 'body', 'ctype');
$message2 = new Swift_Message('subj', 'body', 'ctype');
$message1_clone = clone $message1;
$this->_recursiveObjectCloningCheck($message1, $message2, $message1_clone);
}
public function testCloningWithSigners()
{
$message1 = new Swift_Message('subj', 'body', 'ctype');
$signer = new Swift_Signers_DKIMSigner(dirname(dirname(__DIR__)).'/_samples/dkim/dkim.test.priv', 'test.example', 'example');
$message1->attachSigner($signer);
$message2 = new Swift_Message('subj', 'body', 'ctype');
$signer = new Swift_Signers_DKIMSigner(dirname(dirname(__DIR__)).'/_samples/dkim/dkim.test.priv', 'test.example', 'example');
$message2->attachSigner($signer);
$message1_clone = clone $message1;
$this->_recursiveObjectCloningCheck($message1, $message2, $message1_clone);
}
public function testBodySwap()
{
$message1 = new Swift_Message('Test');
$html = Swift_MimePart::newInstance('<html></html>', 'text/html');
$html->getHeaders()->addTextHeader('X-Test-Remove', 'Test-Value');
$html->getHeaders()->addTextHeader('X-Test-Alter', 'Test-Value');
$message1->attach($html);
$source = $message1->toString();
$message2 = clone $message1;
$message2->setSubject('Message2');
foreach ($message2->getChildren() as $child) {
$child->setBody('Test');
$child->getHeaders()->removeAll('X-Test-Remove');
$child->getHeaders()->get('X-Test-Alter')->setValue('Altered');
}
$final = $message1->toString();
if ($source != $final) {
$this->fail("Difference although object cloned \n [".$source."]\n[".$final."]\n");
}
$final = $message2->toString();
if ($final == $source) {
$this->fail('Two body matches although they should differ'."\n [".$source."]\n[".$final."]\n");
}
$id_1 = $message1->getId();
$id_2 = $message2->getId();
$this->assertEquals($id_1, $id_2, 'Message Ids differ');
$id_2 = $message2->generateId();
$this->assertNotEquals($id_1, $id_2, 'Message Ids are the same');
}
protected function _recursiveObjectCloningCheck($obj1, $obj2, $obj1_clone)
{
$obj1_properties = (array) $obj1;
$obj2_properties = (array) $obj2;
$obj1_clone_properties = (array) $obj1_clone;
foreach ($obj1_properties as $property => $value) {
if (is_object($value)) {
$obj1_value = $obj1_properties[$property];
$obj2_value = $obj2_properties[$property];
$obj1_clone_value = $obj1_clone_properties[$property];
if ($obj1_value !== $obj2_value) {
// two separetely instanciated objects property not referencing same object
$this->assertFalse(
// but object's clone does - not everything copied
$obj1_value === $obj1_clone_value,
"Property `$property` cloning error: source and cloned objects property is referencing same object"
);
} else {
// two separetely instanciated objects have same reference
$this->assertFalse(
// but object's clone doesn't - overdone making copies
$obj1_value !== $obj1_clone_value,
"Property `$property` not properly cloned: it should reference same object as cloning source (overdone copping)"
);
}
// recurse
$this->_recursiveObjectCloningCheck($obj1_value, $obj2_value, $obj1_clone_value);
} elseif (is_array($value)) {
$obj1_value = $obj1_properties[$property];
$obj2_value = $obj2_properties[$property];
$obj1_clone_value = $obj1_clone_properties[$property];
return $this->_recursiveArrayCloningCheck($obj1_value, $obj2_value, $obj1_clone_value);
}
}
}
protected function _recursiveArrayCloningCheck($array1, $array2, $array1_clone)
{
foreach ($array1 as $key => $value) {
if (is_object($value)) {
$arr1_value = $array1[$key];
$arr2_value = $array2[$key];
$arr1_clone_value = $array1_clone[$key];
if ($arr1_value !== $arr2_value) {
// two separetely instanciated objects property not referencing same object
$this->assertFalse(
// but object's clone does - not everything copied
$arr1_value === $arr1_clone_value,
"Key `$key` cloning error: source and cloned objects property is referencing same object"
);
} else {
// two separetely instanciated objects have same reference
$this->assertFalse(
// but object's clone doesn't - overdone making copies
$arr1_value !== $arr1_clone_value,
"Key `$key` not properly cloned: it should reference same object as cloning source (overdone copping)"
);
}
// recurse
$this->_recursiveObjectCloningCheck($arr1_value, $arr2_value, $arr1_clone_value);
} elseif (is_array($value)) {
$arr1_value = $array1[$key];
$arr2_value = $array2[$key];
$arr1_clone_value = $array1_clone[$key];
return $this->_recursiveArrayCloningCheck($arr1_value, $arr2_value, $arr1_clone_value);
}
}
}
}

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More