Skip to content

Commit a8c3c13

Browse files
committed
add tests
1 parent e8532f0 commit a8c3c13

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/WebPushTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ public function testSendNotification()
4242
$this->assertEquals(true, $res['success']);
4343
}
4444

45+
public function testSendNotificationWithPayload()
46+
{
47+
$res = $this->webPush->sendNotification(
48+
$this->endpoints['standard'],
49+
'test',
50+
$this->keys['standard']
51+
);
52+
53+
$this->assertArrayHasKey('success', $res);
54+
$this->assertEquals(true, $res['success']);
55+
}
56+
4557
public function testSendGCMNotification()
4658
{
4759
$res = $this->webPush->sendNotification($this->endpoints['GCM']);
@@ -71,4 +83,25 @@ public function testSendGCMNotificationWithWrongGCMApiKey()
7183

7284
$this->assertArrayHasKey('headers', $res);
7385
}
86+
87+
public function testEncrypt()
88+
{
89+
// encrypt is a private method
90+
$class = new ReflectionClass(get_class($this->webPush));
91+
$encrypt = $class->getMethod('encrypt');
92+
$encrypt->setAccessible(true);
93+
94+
$expected = array(
95+
'localPublicKey' => 'BH_1HZcs53fCIMW7Q6ePJqCqc4JIzSeCTjcNBmoet2eMObvQTpiBHH0EnDYZ0kTqk5f2b6wruq7US1vewtngt6o',
96+
'salt' => '0HK6QfkQmcQKFVAgG2iOTw',
97+
'cipherText' => 'ivmuewrVd-7qkRgxRcu972JyrSvXJzbLeWhTXx1FRZndeP5PVS3fnLQhmK077PgW7C5MLAA_wzDpIN_oB9vo',
98+
);
99+
100+
$actualUserPublicKey = 'BDFsuXPNuJ4SxoYcVVvRagonMcSKHXjsif4qmzpXTDyy29ZKqbwtVAgHCLJGP0HgQ0hpkg6H5-fPBvDjBQxjYfc';
101+
$actualPayload = '{"action":"chatMsg","name":"Bob","msg":"test"}';
102+
103+
$actual = $encrypt->invokeArgs($this->webPush, array($actualUserPublicKey, $actualPayload));
104+
105+
$this->assertEquals($expected, $actual);
106+
}
74107
}

0 commit comments

Comments
 (0)