1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\Test\Adapter; |
4
|
|
|
|
5
|
|
|
use IrishDan\NotificationBundle\Adapter\MailMessageAdapter; |
6
|
|
|
use IrishDan\NotificationBundle\Message\MessageInterface; |
7
|
|
|
|
8
|
|
|
class MailMessageAdapterTest extends AdapterTestCase |
9
|
|
|
{ |
10
|
|
|
public function setUp() |
11
|
|
|
{ |
12
|
|
|
parent::setUp(); |
13
|
|
|
|
14
|
|
|
$parameters = $this->getParametersFromContainer('notification.channel.mail.configuration'); |
15
|
|
|
$mailer = $this->getMockBuilder(\Swift_mailer::class) |
16
|
|
|
->disableOriginalConstructor() |
17
|
|
|
->getMock(); |
18
|
|
|
|
19
|
|
|
$this->adapter = new MailMessageAdapter($mailer, $parameters); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testFormat() |
23
|
|
|
{ |
24
|
|
|
$message = $this->adapter->format($this->notification); |
25
|
|
|
|
26
|
|
|
$this->assertValidDispatchData($message); |
27
|
|
|
$this->assertMessageDataStructure($message); |
28
|
|
|
|
29
|
|
|
$this->assertBasicMessageData($message); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testFormatWithTwig() |
33
|
|
|
{ |
34
|
|
|
$this->setTwig(); |
35
|
|
|
$message = $this->adapter->format($this->notification); |
36
|
|
|
|
37
|
|
|
$this->assertValidDispatchData($message); |
38
|
|
|
$this->assertMessageDataStructure($message); |
39
|
|
|
|
40
|
|
|
$messageData = $message->getMessageData(); |
41
|
|
|
|
42
|
|
|
$this->assertEquals('New member', $messageData['title']); |
43
|
|
|
$message = 'Hello jimBob |
44
|
|
|
Notification message for jimBob |
45
|
|
|
Sincerely yours, |
46
|
|
|
NotificationBundle |
47
|
|
|
Sent via mail channel.'; |
48
|
|
|
|
49
|
|
|
$this->assertEquals($message, $messageData['body']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
private function assertValidDispatchData(MessageInterface $message) |
53
|
|
|
{ |
54
|
|
|
$this->assertEquals('mail', $message->getChannel()); |
55
|
|
|
|
56
|
|
|
$dispatchData = $message->getDispatchData(); |
57
|
|
|
$this->assertArrayHasKey('to', $dispatchData); |
58
|
|
|
$this->assertArrayHasKey('from', $dispatchData); |
59
|
|
|
|
60
|
|
|
$this->assertEquals('[email protected]', $dispatchData['to']); |
61
|
|
|
$this->assertEquals('[email protected]', $dispatchData['from']); |
62
|
|
|
} |
63
|
|
|
} |