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\GcmMessage; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Custom Gcm message tests. |
16
|
|
|
*/ |
17
|
|
|
class GcmMessageTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var \Jgut\Tify\Adapter\Gcm\GcmMessage |
21
|
|
|
*/ |
22
|
|
|
protected $message; |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->message = new GcmMessage(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testMutatorsAccessors() |
30
|
|
|
{ |
31
|
|
|
self::assertCount(0, $this->message->getNotificationPayload()); |
32
|
|
|
|
33
|
|
|
$this->message->addNotificationPayload('first', 'first'); |
34
|
|
|
self::assertCount(1, $this->message->getNotificationPayload()); |
35
|
|
|
|
36
|
|
|
$this->message->setNotificationPayload(['first' => 'first', 'second' => 'second']); |
37
|
|
|
self::assertCount(2, $this->message->getNotificationPayload()); |
38
|
|
|
|
39
|
|
|
$this->message->clearNotificationPayload(); |
40
|
|
|
self::assertCount(0, $this->message->getNotificationPayload()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @expectedException \InvalidArgumentException |
45
|
|
|
*/ |
46
|
|
|
public function testInvalidKey() |
47
|
|
|
{ |
48
|
|
|
$this->message->addNotificationPayload(' ', 'first'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @expectedException \RuntimeException |
53
|
|
|
*/ |
54
|
|
|
public function testDuplicatedKey() |
55
|
|
|
{ |
56
|
|
|
$this->message->addNotificationPayload('first', 'first'); |
57
|
|
|
$this->message->addNotificationPayload('first', 'first'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testJsonResult() |
61
|
|
|
{ |
62
|
|
|
$this->message->setRegistrationIds(['sdfshj']); |
63
|
|
|
$this->message->setCollapseKey('key'); |
64
|
|
|
$this->message->setDelayWhileIdle(true); |
65
|
|
|
$this->message->setTimeToLive(600); |
66
|
|
|
$this->message->setRestrictedPackageName('package.name'); |
67
|
|
|
$this->message->setDryRun(true); |
68
|
|
|
$this->message->setData(['key' => 'value']); |
69
|
|
|
$this->message->addNotificationPayload('first', 'first'); |
70
|
|
|
|
71
|
|
|
$result = json_decode($this->message->toJson()); |
72
|
|
|
self::assertTrue(isset($result->notification->first)); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|