-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathMessageTest.php
More file actions
177 lines (141 loc) · 5.54 KB
/
MessageTest.php
File metadata and controls
177 lines (141 loc) · 5.54 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
namespace paragraph1\phpFCM\Tests;
use paragraph1\phpFCM\Recipient\Recipient;
use paragraph1\phpFCM\Message;
use paragraph1\phpFCM\Recipient\Topic;
use paragraph1\phpFCM\Notification;
use paragraph1\phpFCM\Recipient\Device;
class MessageTest extends PhpFcmTestCase
{
private $fixture;
protected function setUp()
{
parent::setUp();
$this->fixture = new Message();
}
public function testThrowsExceptionWhenDifferentRecepientTypesAreRegistered()
{
$this->setExpectedException(\InvalidArgumentException::class, 'mixed recepient types are not supported by FCM');
$this->fixture->addRecipient(new Topic('breaking-news'))
->addRecipient(new Device('token'));
}
public function testThrowsExceptionWhenNoRecepientWasAdded()
{
$this->setExpectedException(\UnexpectedValueException::class, 'message must have at least one recipient');
$this->fixture->jsonSerialize();
}
public function testWorksCorrectlyWithMultipleTopics()
{
$body = '{"condition":"\'topic1\' in topics || \'topic2\' in topics","data":{"foo":"bar"},"priority":"high"}';
$this->fixture->addRecipient(new Topic('topic1'))
->addRecipient(new Topic('topic2'))
->setData(['foo' => 'bar']);
$this->assertSame(
$body,
json_encode($this->fixture)
);
}
public function testJsonEncodeWorksOnTopicRecipients()
{
$body = '{"to":"\/topics\/breaking-news","priority":"high","notification":{"title":"test","body":"a nice testing notification"}}';
$notification = new Notification('test', 'a nice testing notification');
$this->fixture->setNotification($notification);
$this->fixture->addRecipient(new Topic('breaking-news'));
$this->assertSame(
$body,
json_encode($this->fixture)
);
}
public function testJsonEncodeWorksOnDeviceRecipients()
{
$body = '{"to":"deviceId","priority":"high","notification":{"title":"test","body":"a nice testing notification"}}';
$notification = new Notification('test', 'a nice testing notification');
$this->fixture->setNotification($notification);
$this->fixture->addRecipient(new Device('deviceId'));
$this->assertSame(
$body,
json_encode($this->fixture)
);
}
public function testAddingMultipleDeviceRecipientsAddsRegistrationIds()
{
$body = '{"registration_ids":["deviceId","anotherDeviceId"],"priority":"high","notification":{"title":"test","body":"a nice testing notification"}}';
$notification = new Notification('test', 'a nice testing notification');
$this->fixture->setNotification($notification);
$this->fixture->addRecipient(new Device('deviceId'))
->addRecipient(new Device('anotherDeviceId'));
$this->assertSame(
$body,
json_encode($this->fixture)
);
}
public function testJsonEncodeCorrectlyHandlesCollapseKeyAndData()
{
$body = '{"to":"\/topics\/testing","collapse_key":"collapseMe","data":{"foo":"bar"},"priority":"normal"}';
$this->fixture->setData(['foo' => 'bar'])
->setCollapseKey('collapseMe')
->setPriority(Message::PRIORITY_NORMAL);
$this->fixture->addRecipient(new Topic('testing'));
$this->assertSame(
$body,
json_encode($this->fixture)
);
}
public function testJsonEncodeHandlesTTL()
{
$body = '{"to":"\/topics\/testing","data":{"foo":"bar"},"priority":"high","time_to_live":3}';
$this->fixture->setData(['foo' => 'bar'])
->setTimeToLive(3);
$this->fixture->addRecipient(new Topic('testing'));
$this->assertSame(
$body,
json_encode($this->fixture)
);
}
public function testJsonEncodeHandlesDelayIdle()
{
$body = '{"to":"\/topics\/testing","data":{"foo":"bar"},"priority":"high","delay_while_idle":true}';
$this->fixture->setData(['foo' => 'bar'])
->setDelayWhileIdle(true);
$this->fixture->addRecipient(new Topic('testing'));
$this->assertSame(
$body,
json_encode($this->fixture)
);
}
public function testJsonEncodeHandlesMutableContent()
{
$body = '{"to":"\/topics\/testing","data":{"foo":"bar"},"priority":"high","mutable_content":true}';
$this->fixture->setData(['foo' => 'bar'])
->setMutableContent();
$this->fixture->addRecipient(new Topic('testing'));
$this->assertSame(
$body,
json_encode($this->fixture)
);
}
public function testAddingNewAndUnknownRecipientTypesYieldsException()
{
$this->setExpectedException(\UnexpectedValueException::class);
$this->fixture->addRecipient(\Mockery::mock(Recipient::class));
}
public function testJsonEncodeWorksWithContentAvailableFlag()
{
$body = '{"to":"deviceId","priority":"high","content_available":true}';
$this->fixture->setContentAvailable();
$this->fixture->addRecipient(new Device('deviceId'));
$this->assertSame(
$body,
json_encode($this->fixture)
);
}
public function testJsonEncodeWorksWithoutContentAvailableFlag()
{
$body = '{"to":"deviceId","priority":"high"}';
$this->fixture->addRecipient(new Device('deviceId'));
$this->assertSame(
$body,
json_encode($this->fixture)
);
}
}