-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced Swift Mailer with Symfony Mailer
- Loading branch information
1 parent
ca0a3cc
commit 7e942e8
Showing
3 changed files
with
91 additions
and
75 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 |
---|---|---|
|
@@ -22,10 +22,10 @@ | |
use Sulu\Bundle\TestBundle\Testing\SuluTestCase; | ||
use Sulu\Component\HttpKernel\SuluKernel; | ||
use Symfony\Bundle\FrameworkBundle\KernelBrowser; | ||
use Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpKernel\Profiler\Profile; | ||
use Symfony\Component\Mime\RawMessage; | ||
|
||
/** | ||
* This testcases covers the whole registration, confirmation and login process. | ||
|
@@ -181,7 +181,7 @@ public function testRegistrationBlacklistedBlocked(): void | |
$this->assertNull($this->findUser()); | ||
} | ||
|
||
public function testRegistrationBlacklistedRequested(): \Swift_Message | ||
public function testRegistrationBlacklistedRequested(): RawMessage | ||
{ | ||
$this->createBlacklistItem($this->getEntityManager(), '*@sulu.io', BlacklistItem::TYPE_REQUEST); | ||
|
||
|
@@ -209,11 +209,10 @@ public function testRegistrationBlacklistedRequested(): \Swift_Message | |
$profile = $this->client->getProfile(); | ||
$this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); | ||
|
||
/** @var MessageDataCollector $mailCollector */ | ||
$mailCollector = $profile->getCollector('swiftmailer'); | ||
$this->assertSame(1, $mailCollector->getMessageCount()); | ||
$message = $mailCollector->getMessages()[0]; | ||
$this->assertSame('admin@localhost', \key($message->getTo())); | ||
$this->assertEmailCount(1); | ||
|
||
$message = $this->getMailerMessage(); | ||
$this->assertSame('admin@localhost', $message->getTo()[0]->getAddress()); | ||
|
||
return $message; | ||
} | ||
|
@@ -223,7 +222,7 @@ public function testBlacklistConfirm(): void | |
$message = $this->testRegistrationBlacklistedRequested(); | ||
|
||
$emailCrawler = new Crawler(); | ||
$emailCrawler->addContent($message->getBody()); | ||
$emailCrawler->addContent($message->getHtmlBody()); | ||
|
||
$links = $emailCrawler->filter('a'); | ||
$firstLink = $links->first()->attr('href'); | ||
|
@@ -241,19 +240,18 @@ public function testBlacklistConfirm(): void | |
$profile = $this->client->getProfile(); | ||
$this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); | ||
|
||
/** @var MessageDataCollector $mailCollector */ | ||
$mailCollector = $profile->getCollector('swiftmailer'); | ||
$this->assertSame(1, $mailCollector->getMessageCount()); | ||
$message = $mailCollector->getMessages()[0]; | ||
$this->assertSame('[email protected]', \key($message->getTo())); | ||
$this->assertEmailCount(1); | ||
|
||
$message = $this->getMailerMessage(); | ||
$this->assertSame('[email protected]', $message->getTo()[0]->getAddress()); | ||
} | ||
|
||
public function testBlacklistBlocked(): void | ||
{ | ||
$message = $this->testRegistrationBlacklistedRequested(); | ||
|
||
$emailCrawler = new Crawler(); | ||
$emailCrawler->addContent($message->getBody()); | ||
$emailCrawler->addContent($message->getHtmlBody()); | ||
|
||
$links = $emailCrawler->filter('a'); | ||
$lastLink = $links->last()->attr('href'); | ||
|
@@ -271,9 +269,7 @@ public function testBlacklistBlocked(): void | |
$profile = $this->client->getProfile(); | ||
$this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); | ||
|
||
/** @var MessageDataCollector $mailCollector */ | ||
$mailCollector = $profile->getCollector('swiftmailer'); | ||
$this->assertSame(0, $mailCollector->getMessageCount()); | ||
$this->assertEmailCount(0); | ||
} | ||
|
||
public function testPasswordForget(): void | ||
|
@@ -298,14 +294,13 @@ public function testPasswordForget(): void | |
$profile = $this->client->getProfile(); | ||
$this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); | ||
|
||
/** @var MessageDataCollector $mailCollector */ | ||
$mailCollector = $profile->getCollector('swiftmailer'); | ||
$this->assertSame(1, $mailCollector->getMessageCount()); | ||
$message = $mailCollector->getMessages()[0]; | ||
$this->assertSame('[email protected]', \key($message->getTo())); | ||
$this->assertEmailCount(1); | ||
|
||
$message = $this->getMailerMessage(); | ||
$this->assertSame('[email protected]', $message->getTo()[0]->getAddress()); | ||
|
||
$emailCrawler = new Crawler(); | ||
$emailCrawler->addContent($message->getBody()); | ||
$emailCrawler->addContent($message->getHtmlBody()); | ||
$links = $emailCrawler->filter('a'); | ||
|
||
$firstLink = $links->first()->attr('href'); | ||
|
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 |
---|---|---|
|
@@ -17,13 +17,15 @@ | |
use Sulu\Bundle\CommunityBundle\Mail\Mail; | ||
use Sulu\Bundle\CommunityBundle\Mail\MailFactory; | ||
use Sulu\Bundle\SecurityBundle\Entity\User; | ||
use Symfony\Component\Mailer\MailerInterface; | ||
use Symfony\Component\Mime\Email; | ||
use Symfony\Component\Translation\Translator; | ||
use Twig\Environment; | ||
|
||
class MailFactoryTest extends TestCase | ||
{ | ||
/** | ||
* @var ObjectProphecy<\Swift_Mailer> | ||
* @var ObjectProphecy<MailerInterface> | ||
*/ | ||
private $mailer; | ||
|
||
|
@@ -49,10 +51,11 @@ class MailFactoryTest extends TestCase | |
|
||
protected function setUp(): void | ||
{ | ||
$this->mailer = $this->prophesize(\Swift_Mailer::class); | ||
$this->mailer = $this->prophesize(MailerInterface::class); | ||
$this->twig = $this->prophesize(Environment::class); | ||
$this->translator = $this->prophesize(Translator::class); | ||
$this->translator->getLocale()->willReturn('en'); | ||
$this->translator->trans('testcase')->willReturn('Test case'); | ||
$this->user = $this->prophesize(User::class); | ||
$this->user->getEmail()->willReturn('[email protected]'); | ||
$this->user->getLocale()->willReturn('de'); | ||
|
@@ -70,22 +73,18 @@ public function testSendEmails(): void | |
$this->twig->render('admin-template', Argument::any())->willReturn('Admin-Template'); | ||
|
||
$this->mailer->send( | ||
Argument::that( | ||
function (\Swift_Message $message) { | ||
return 'User-Template' === $message->getBody() | ||
&& $message->getFrom() === ['[email protected]' => null] | ||
&& $message->getTo() === ['[email protected]' => null]; | ||
} | ||
) | ||
(new Email()) | ||
->subject('Test case') | ||
->from('[email protected]') | ||
->to('[email protected]') | ||
->html('User-Template') | ||
)->shouldBeCalledTimes(1); | ||
$this->mailer->send( | ||
Argument::that( | ||
function (\Swift_Message $message) { | ||
return 'Admin-Template' === $message->getBody() | ||
&& $message->getFrom() === ['[email protected]' => null] | ||
&& $message->getTo() === ['[email protected]' => null]; | ||
} | ||
) | ||
(new Email()) | ||
->subject('Test case') | ||
->from('[email protected]') | ||
->to('[email protected]') | ||
->html('Admin-Template') | ||
)->shouldBeCalledTimes(1); | ||
|
||
$mail = new Mail('[email protected]', '[email protected]', 'testcase', 'user-template', 'admin-template'); | ||
|
@@ -100,22 +99,18 @@ public function testSendEmailsNoAdminTemplate(): void | |
$this->twig->render('admin-template', Argument::any())->willReturn('Admin-Template'); | ||
|
||
$this->mailer->send( | ||
Argument::that( | ||
function (\Swift_Message $message) { | ||
return 'User-Template' === $message->getBody() | ||
&& $message->getFrom() === ['[email protected]' => null] | ||
&& $message->getTo() === ['[email protected]' => null]; | ||
} | ||
) | ||
(new Email()) | ||
->subject('Test case') | ||
->from('[email protected]') | ||
->to('[email protected]') | ||
->html('User-Template') | ||
)->shouldBeCalledTimes(1); | ||
$this->mailer->send( | ||
Argument::that( | ||
function (\Swift_Message $message) { | ||
return 'Admin-Template' === $message->getBody() | ||
&& $message->getFrom() === ['[email protected]' => null] | ||
&& $message->getTo() === ['[email protected]' => null]; | ||
} | ||
) | ||
(new Email()) | ||
->subject('Test case') | ||
->from('[email protected]') | ||
->to('[email protected]') | ||
->html('Admin-Template') | ||
)->shouldNotBeCalled(); | ||
|
||
$mail = new Mail('[email protected]', '[email protected]', 'testcase', 'user-template', null); | ||
|
@@ -130,22 +125,18 @@ public function testSendEmailsNoUserTemplate(): void | |
$this->twig->render('admin-template', Argument::any())->willReturn('Admin-Template'); | ||
|
||
$this->mailer->send( | ||
Argument::that( | ||
function (\Swift_Message $message) { | ||
return 'User-Template' === $message->getBody() | ||
&& $message->getFrom() === ['[email protected]' => null] | ||
&& $message->getTo() === ['[email protected]' => null]; | ||
} | ||
) | ||
(new Email()) | ||
->subject('Test case') | ||
->from('[email protected]') | ||
->to('[email protected]') | ||
->html('User-Template') | ||
)->shouldNotBeCalled(); | ||
$this->mailer->send( | ||
Argument::that( | ||
function (\Swift_Message $message) { | ||
return 'Admin-Template' === $message->getBody() | ||
&& $message->getFrom() === ['[email protected]' => null] | ||
&& $message->getTo() === ['[email protected]' => null]; | ||
} | ||
) | ||
(new Email()) | ||
->subject('Test case') | ||
->from('[email protected]') | ||
->to('[email protected]') | ||
->html('Admin-Template') | ||
)->shouldBeCalledTimes(1); | ||
|
||
$mail = new Mail('[email protected]', '[email protected]', 'testcase', null, 'admin-template'); | ||
|