Skip to content

Commit 5d5c828

Browse files
OskarStarknicolas-grekas
authored andcommitted
[Notifier] Add tests for option classes
1 parent 87a6790 commit 5d5c828

File tree

3 files changed

+267
-0
lines changed

3 files changed

+267
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests\Notification;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Firebase\Notification\AndroidNotification;
16+
17+
final class AndroidNotificationTest extends TestCase
18+
{
19+
public function testAndroidNotificationOptions()
20+
{
21+
$notification = new AndroidNotification('device_token', [
22+
'title' => 'Test Title',
23+
'body' => 'Test Body',
24+
], ['key' => 'value']);
25+
26+
$this->assertSame([
27+
'to' => 'device_token',
28+
'notification' => [
29+
'title' => 'Test Title',
30+
'body' => 'Test Body',
31+
],
32+
'data' => ['key' => 'value'],
33+
], $notification->toArray());
34+
35+
$this->assertSame('device_token', $notification->getRecipientId());
36+
}
37+
38+
public function testAndroidNotificationWithAllOptions()
39+
{
40+
$notification = (new AndroidNotification('device_token', []))
41+
->title('New Title')
42+
->body('New Body')
43+
->data(['custom' => 'data'])
44+
->channelId('channel_123')
45+
->icon('notification_icon')
46+
->sound('notification_sound')
47+
->tag('tag_123')
48+
->color('#FF0000')
49+
->clickAction('OPEN_ACTIVITY')
50+
->bodyLocKey('body_key')
51+
->bodyLocArgs(['arg1', 'arg2'])
52+
->titleLocKey('title_key')
53+
->titleLocArgs(['title_arg1', 'title_arg2']);
54+
55+
$expected = [
56+
'to' => 'device_token',
57+
'notification' => [
58+
'title' => 'New Title',
59+
'body' => 'New Body',
60+
'android_channel_id' => 'channel_123',
61+
'icon' => 'notification_icon',
62+
'sound' => 'notification_sound',
63+
'tag' => 'tag_123',
64+
'color' => '#FF0000',
65+
'click_action' => 'OPEN_ACTIVITY',
66+
'body_loc_key' => 'body_key',
67+
'body_loc_args' => ['arg1', 'arg2'],
68+
'title_loc_key' => 'title_key',
69+
'title_loc_args' => ['title_arg1', 'title_arg2'],
70+
],
71+
'data' => ['custom' => 'data'],
72+
];
73+
74+
$this->assertSame($expected, $notification->toArray());
75+
}
76+
77+
public function testAndroidNotificationChaining()
78+
{
79+
$notification = new AndroidNotification('device_token', []);
80+
81+
$result = $notification
82+
->channelId('test_channel')
83+
->icon('test_icon');
84+
85+
$this->assertSame($notification, $result);
86+
$this->assertSame([
87+
'to' => 'device_token',
88+
'notification' => [
89+
'android_channel_id' => 'test_channel',
90+
'icon' => 'test_icon',
91+
],
92+
'data' => [],
93+
], $notification->toArray());
94+
}
95+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests\Notification;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Firebase\Notification\IOSNotification;
16+
17+
final class IOSNotificationTest extends TestCase
18+
{
19+
public function testIOSNotificationOptions()
20+
{
21+
$notification = new IOSNotification('device_token', [
22+
'title' => 'Test Title',
23+
'body' => 'Test Body',
24+
], ['key' => 'value']);
25+
26+
$this->assertSame([
27+
'to' => 'device_token',
28+
'notification' => [
29+
'title' => 'Test Title',
30+
'body' => 'Test Body',
31+
],
32+
'data' => ['key' => 'value'],
33+
], $notification->toArray());
34+
35+
$this->assertSame('device_token', $notification->getRecipientId());
36+
}
37+
38+
public function testIOSNotificationWithAllOptions()
39+
{
40+
$notification = (new IOSNotification('device_token', []))
41+
->title('New Title')
42+
->body('New Body')
43+
->data(['custom' => 'data'])
44+
->sound('default')
45+
->badge('5')
46+
->clickAction('OPEN_ACTIVITY')
47+
->subtitle('Test Subtitle')
48+
->bodyLocKey('body_key')
49+
->bodyLocArgs(['arg1', 'arg2'])
50+
->titleLocKey('title_key')
51+
->titleLocArgs(['title_arg1', 'title_arg2']);
52+
53+
$expected = [
54+
'to' => 'device_token',
55+
'notification' => [
56+
'title' => 'New Title',
57+
'body' => 'New Body',
58+
'sound' => 'default',
59+
'badge' => '5',
60+
'click_action' => 'OPEN_ACTIVITY',
61+
'subtitle' => 'Test Subtitle',
62+
'body_loc_key' => 'body_key',
63+
'body_loc_args' => ['arg1', 'arg2'],
64+
'title_loc_key' => 'title_key',
65+
'title_loc_args' => ['title_arg1', 'title_arg2'],
66+
],
67+
'data' => ['custom' => 'data'],
68+
];
69+
70+
$this->assertSame($expected, $notification->toArray());
71+
}
72+
73+
public function testIOSNotificationChaining()
74+
{
75+
$notification = new IOSNotification('device_token', []);
76+
77+
$result = $notification
78+
->sound('ping.aiff')
79+
->badge('10')
80+
->subtitle('Important');
81+
82+
$this->assertSame($notification, $result);
83+
$this->assertSame([
84+
'to' => 'device_token',
85+
'notification' => [
86+
'sound' => 'ping.aiff',
87+
'badge' => '10',
88+
'subtitle' => 'Important',
89+
],
90+
'data' => [],
91+
], $notification->toArray());
92+
}
93+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests\Notification;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Firebase\Notification\WebNotification;
16+
17+
final class WebNotificationTest extends TestCase
18+
{
19+
public function testWebNotificationOptions()
20+
{
21+
$notification = new WebNotification('device_token', [
22+
'title' => 'Test Title',
23+
'body' => 'Test Body',
24+
], ['key' => 'value']);
25+
26+
$this->assertSame([
27+
'to' => 'device_token',
28+
'notification' => [
29+
'title' => 'Test Title',
30+
'body' => 'Test Body',
31+
],
32+
'data' => ['key' => 'value'],
33+
], $notification->toArray());
34+
35+
$this->assertSame('device_token', $notification->getRecipientId());
36+
}
37+
38+
public function testWebNotificationWithAllOptions()
39+
{
40+
$notification = (new WebNotification('device_token', []))
41+
->title('New Title')
42+
->body('New Body')
43+
->data(['custom' => 'data'])
44+
->icon('/images/icon.png')
45+
->clickAction('https://example.com');
46+
47+
$expected = [
48+
'to' => 'device_token',
49+
'notification' => [
50+
'title' => 'New Title',
51+
'body' => 'New Body',
52+
'icon' => '/images/icon.png',
53+
'click_action' => 'https://example.com',
54+
],
55+
'data' => ['custom' => 'data'],
56+
];
57+
58+
$this->assertSame($expected, $notification->toArray());
59+
}
60+
61+
public function testWebNotificationChaining()
62+
{
63+
$notification = new WebNotification('device_token', []);
64+
65+
$result = $notification
66+
->icon('/favicon.ico')
67+
->clickAction('https://myapp.com/action');
68+
69+
$this->assertSame($notification, $result);
70+
$this->assertSame([
71+
'to' => 'device_token',
72+
'notification' => [
73+
'icon' => '/favicon.ico',
74+
'click_action' => 'https://myapp.com/action',
75+
],
76+
'data' => [],
77+
], $notification->toArray());
78+
}
79+
}

0 commit comments

Comments
 (0)