forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mautic#4158 from escopecz/bug-email-address-apostr…
…ophe Bug email address apostrophe
- Loading branch information
Showing
2 changed files
with
97 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
use Mautic\CoreBundle\Factory\MauticFactory; | ||
use Mautic\EmailBundle\Entity\Email; | ||
use Mautic\EmailBundle\Helper\MailHelper; | ||
use Mautic\EmailBundle\MonitoredEmail\Mailbox; | ||
use Mautic\EmailBundle\Swiftmailer\Exception\BatchQueueMaxException; | ||
use Mautic\EmailBundle\Tests\Helper\Transport\BatchTransport; | ||
|
@@ -79,7 +80,7 @@ public function testQueueModeThrowsExceptionWhenBatchLimitHit() | |
|
||
$swiftMailer = new \Swift_Mailer(new BatchTransport()); | ||
|
||
$mailer = new \Mautic\EmailBundle\Helper\MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
$mailer = new MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
|
||
// Enable queue mode | ||
$mailer->enableQueue(); | ||
|
@@ -107,7 +108,7 @@ public function testQueueModeDisabledDoesNotThrowsExceptionWhenBatchLimitHit() | |
|
||
$swiftMailer = new \Swift_Mailer(new BatchTransport()); | ||
|
||
$mailer = new \Mautic\EmailBundle\Helper\MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
$mailer = new MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
|
||
// Enable queue mode | ||
try { | ||
|
@@ -128,7 +129,7 @@ public function testQueuedEmailFromOverride() | |
$transport = new BatchTransport(); | ||
$swiftMailer = new \Swift_Mailer($transport); | ||
|
||
$mailer = new \Mautic\EmailBundle\Helper\MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
$mailer = new MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
$mailer->enableQueue(); | ||
|
||
$email = new Email(); | ||
|
@@ -169,7 +170,7 @@ public function testBatchMode() | |
$transport = new BatchTransport(true); | ||
$swiftMailer = new \Swift_Mailer($transport); | ||
|
||
$mailer = new \Mautic\EmailBundle\Helper\MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
$mailer = new MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
$mailer->enableQueue(); | ||
|
||
$email = new Email(); | ||
|
@@ -200,7 +201,7 @@ public function testQueuedOwnerAsMailer() | |
$transport = new BatchTransport(); | ||
$swiftMailer = new \Swift_Mailer($transport); | ||
|
||
$mailer = new \Mautic\EmailBundle\Helper\MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
$mailer = new MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
$mailer->enableQueue(); | ||
|
||
$mailer->setSubject('Hello'); | ||
|
@@ -255,7 +256,7 @@ public function testStandardOwnerAsMailer() | |
$transport = new SmtpTransport(); | ||
$swiftMailer = new \Swift_Mailer($transport); | ||
|
||
$mailer = new \Mautic\EmailBundle\Helper\MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
$mailer = new MailHelper($mockFactory, $swiftMailer, ['[email protected]' => 'No Body']); | ||
$mailer->setBody('{signature}'); | ||
|
||
foreach ($this->contacts as $key => $contact) { | ||
|
@@ -276,6 +277,88 @@ public function testStandardOwnerAsMailer() | |
} | ||
} | ||
|
||
public function testValidateValidEmails() | ||
{ | ||
$helper = $this->mockEmptyMailHelper(); | ||
$addresses = [ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
]; | ||
|
||
foreach ($addresses as $address) { | ||
// will throw Swift_RfcComplianceException if it will find the address invalid | ||
$helper::validateEmail($address); | ||
} | ||
} | ||
|
||
public function testValidateEmailWithoutTld() | ||
{ | ||
$heper = $this->mockEmptyMailHelper(); | ||
$this->setExpectedException(\Swift_RfcComplianceException::class); | ||
$heper::validateEmail('john@doe'); | ||
} | ||
|
||
public function testValidateEmailWithSpaceInIt() | ||
{ | ||
$heper = $this->mockEmptyMailHelper(); | ||
$this->setExpectedException(\Swift_RfcComplianceException::class); | ||
$heper::validateEmail('jo [email protected]'); | ||
} | ||
|
||
public function testValidateEmailWithCaretInIt() | ||
{ | ||
$heper = $this->mockEmptyMailHelper(); | ||
$this->setExpectedException(\Swift_RfcComplianceException::class); | ||
$heper::validateEmail('jo^[email protected]'); | ||
} | ||
|
||
public function testValidateEmailWithApostropheInIt() | ||
{ | ||
$heper = $this->mockEmptyMailHelper(); | ||
$this->setExpectedException(\Swift_RfcComplianceException::class); | ||
$heper::validateEmail('jo\'[email protected]'); | ||
} | ||
|
||
public function testValidateEmailWithSemicolonInIt() | ||
{ | ||
$heper = $this->mockEmptyMailHelper(); | ||
$this->setExpectedException(\Swift_RfcComplianceException::class); | ||
$heper::validateEmail('jo;[email protected]'); | ||
} | ||
|
||
public function testValidateEmailWithAmpersandInIt() | ||
{ | ||
$heper = $this->mockEmptyMailHelper(); | ||
$this->setExpectedException(\Swift_RfcComplianceException::class); | ||
$heper::validateEmail('jo&[email protected]'); | ||
} | ||
|
||
public function testValidateEmailWithStarInIt() | ||
{ | ||
$heper = $this->mockEmptyMailHelper(); | ||
$this->setExpectedException(\Swift_RfcComplianceException::class); | ||
$heper::validateEmail('jo*[email protected]'); | ||
} | ||
|
||
public function testValidateEmailWithPercentInIt() | ||
{ | ||
$heper = $this->mockEmptyMailHelper(); | ||
$this->setExpectedException(\Swift_RfcComplianceException::class); | ||
$heper::validateEmail('jo%[email protected]'); | ||
} | ||
|
||
protected function mockEmptyMailHelper() | ||
{ | ||
$mockFactory = $this->getMockFactory(); | ||
$transport = new SmtpTransport(); | ||
$swiftMailer = new \Swift_Mailer($transport); | ||
|
||
return new MailHelper($mockFactory, $swiftMailer); | ||
} | ||
|
||
protected function getMockFactory($mailIsOwner = true) | ||
{ | ||
$mockLeadRepository = $this->getMockBuilder(LeadRepository::class) | ||
|