|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Push notification services abstraction (http://github.com/juliangut/tify) |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/juliangut/tify for the canonical source repository |
|
6
|
|
|
* |
|
7
|
|
|
* @license https://github.com/juliangut/tify/blob/master/LICENSE |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Jgut\Tify\Tests\Adapter\Gcm; |
|
11
|
|
|
|
|
12
|
|
|
use Jgut\Tify\Adapter\Gcm\GcmBuilder; |
|
13
|
|
|
use Jgut\Tify\Adapter\Gcm\GcmMessage; |
|
14
|
|
|
use Jgut\Tify\Message; |
|
15
|
|
|
use Jgut\Tify\Notification; |
|
16
|
|
|
use ZendService\Google\Gcm\Client; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Gcm service builder |
|
20
|
|
|
*/ |
|
21
|
|
|
class GcmBuilderTest extends \PHPUnit_Framework_TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var \Jgut\Tify\Adapter\Gcm\GcmBuilder |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $builder; |
|
27
|
|
|
|
|
28
|
|
|
public function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->builder = new GcmBuilder; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testPushClient() |
|
34
|
|
|
{ |
|
35
|
|
|
$client = $this->builder->buildPushClient('my_api_key'); |
|
36
|
|
|
|
|
37
|
|
|
self::assertInstanceOf(Client::class, $client); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testPushMessage() |
|
41
|
|
|
{ |
|
42
|
|
|
$message = new Message(); |
|
43
|
|
|
|
|
44
|
|
|
$notification = new Notification($message, [], ['collapse_key' => 'my_key']); |
|
45
|
|
|
|
|
46
|
|
|
$pushMessage = $this->builder->buildPushMessage(['my_token'], $notification); |
|
47
|
|
|
|
|
48
|
|
|
self::assertInstanceOf(GcmMessage::class, $pushMessage); |
|
49
|
|
|
self::assertEquals('my_key', $pushMessage->getCollapseKey()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testNotificationPushMessage() |
|
53
|
|
|
{ |
|
54
|
|
|
$message = new Message(['title_loc_key' => 'MESSAGE_TITLE']); |
|
55
|
|
|
|
|
56
|
|
|
$notification = new Notification($message, []); |
|
57
|
|
|
|
|
58
|
|
|
$pushMessage = $this->builder->buildPushMessage(['my_token'], $notification); |
|
59
|
|
|
|
|
60
|
|
|
self::assertInstanceOf(GcmMessage::class, $pushMessage); |
|
61
|
|
|
self::assertEquals('MESSAGE_TITLE', $pushMessage->getNotificationPayload()['title_loc_key']); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|