forked from redjanym/php-firebase-cloud-messaging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageTest.php
More file actions
86 lines (71 loc) · 2.79 KB
/
Copy pathMessageTest.php
File metadata and controls
86 lines (71 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace sngrl\PhpFirebaseCloudMessaging\Tests;
use sngrl\PhpFirebaseCloudMessaging\Recipient\Recipient;
use sngrl\PhpFirebaseCloudMessaging\Message;
use sngrl\PhpFirebaseCloudMessaging\Recipient\Topic;
use sngrl\PhpFirebaseCloudMessaging\Notification;
use sngrl\PhpFirebaseCloudMessaging\Recipient\Device;
class MessageTest extends PhpFirebaseCloudMessagingTestCase
{
private $fixture;
protected function setUp()
{
parent::setUp();
$this->fixture = new Message();
}
public function testThrowsExceptionWhenDifferentRecepientTypesAreRegistered()
{
$this->setExpectedException(\InvalidArgumentException::class);
$this->fixture->addRecipient(new Topic('breaking-news'))
->addRecipient(new Recipient());
}
public function testThrowsExceptionWhenNoRecepientWasAdded()
{
$this->setExpectedException(\UnexpectedValueException::class);
$this->fixture->jsonSerialize();
}
public function testThrowsExceptionWhenMultipleTopicsWereGiven()
{
$this->setExpectedException(\UnexpectedValueException::class);
$this->fixture->addRecipient(new Topic('breaking-news'))
->addRecipient(new Topic('another topic'));
$this->fixture->jsonSerialize();
}
public function testJsonEncodeWorksOnTopicRecipients()
{
$body = '{"to":"\/topics\/breaking-news","notification":{"title":"test","body":"a nice testing notification"}}';
$notification = new Notification('test', 'a nice testing notification');
$message = new Message();
$message->setNotification($notification);
$message->addRecipient(new Topic('breaking-news'));
$this->assertSame(
$body,
json_encode($message)
);
}
public function testJsonEncodeWorksOnDeviceRecipients()
{
$body = '{"to":"deviceId","notification":{"title":"test","body":"a nice testing notification"}}';
$notification = new Notification('test', 'a nice testing notification');
$message = new Message();
$message->setNotification($notification);
$message->addRecipient(new Device('deviceId'));
$this->assertSame(
$body,
json_encode($message)
);
}
public function testJsonSerializeWithContentAvailable()
{
$body = '{"to":"deviceId","content_available":true,"notification":{"title":"test","body":"a nice testing notification"}}';
$notification = new Notification('test', 'a nice testing notification');
$message = new Message();
$message->setNotification($notification);
$message->setContentAvailable(true);
$message->addRecipient(new Device('deviceId'));
$this->assertSame(
$body,
json_encode($message)
);
}
}