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