Skip to content

Commit e9c7762

Browse files
committed
add VAPID tests
1 parent d926aeb commit e9c7762

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

tests/PushServiceTest.php

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class PushServiceTest extends PHPUnit_Framework_TestCase
1818
private static $testServiceUrl;
1919
private static $gcmSenderId = '759071690750';
2020
private static $gcmApiKey = 'AIzaSyBAU0VfXoskxUSg81K5VgLgwblHbZWe6tA';
21+
private static $vapidKeys = array(
22+
'subject' => 'http://test.com',
23+
'publicKey' => 'BA6jvk34k6YjElHQ6S0oZwmrsqHdCNajxcod6KJnI77Dagikfb--O_kYXcR2eflRz6l3PcI2r8fPCH3BElLQHDk',
24+
'privateKey' => '-3CdhFOqjzixgAbUSa0Zv9zi-dwDVmWO7672aBxSFPQ',
25+
);
2126

2227
/** @var WebPush WebPush with correct api keys */
2328
private $webPush;
@@ -46,11 +51,11 @@ protected function setUp()
4651
{
4752
$startApiCurl = curl_init(self::$testServiceUrl.'/api/start-test-suite/');
4853
curl_setopt_array($startApiCurl, array(
49-
CURLOPT_POST => true,
50-
CURLOPT_POSTFIELDS => array(),
51-
CURLOPT_RETURNTRANSFER => true,
52-
CURLOPT_TIMEOUT => 30,
53-
));
54+
CURLOPT_POST => true,
55+
CURLOPT_POSTFIELDS => array(),
56+
CURLOPT_RETURNTRANSFER => true,
57+
CURLOPT_TIMEOUT => 30,
58+
));
5459

5560
$resp = curl_exec($startApiCurl);
5661

@@ -86,7 +91,19 @@ public function browserProvider()
8691
array('firefox', 'beta', array('GCM' => self::$gcmApiKey)),
8792
array('firefox', 'unstable', array('GCM' => self::$gcmApiKey)),
8893
// Web Push + VAPID
94+
array('chrome', 'stable', array('VAPID' => self::$vapidKeys)),
95+
array('chrome', 'beta', array('VAPID' => self::$vapidKeys)),
96+
array('chrome', 'unstable', array('VAPID' => self::$vapidKeys)),
97+
array('firefox', 'stable', array('VAPID' => self::$vapidKeys)),
98+
array('firefox', 'beta', array('VAPID' => self::$vapidKeys)),
99+
array('firefox', 'unstable', array('VAPID' => self::$vapidKeys)),
89100
// Web Push + GCM + VAPID
101+
array('chrome', 'stable', array('GCM' => self::$gcmApiKey, 'VAPID' => self::$vapidKeys)),
102+
array('chrome', 'beta', array('GCM' => self::$gcmApiKey, 'VAPID' => self::$vapidKeys)),
103+
array('chrome', 'unstable', array('GCM' => self::$gcmApiKey, 'VAPID' => self::$vapidKeys)),
104+
array('firefox', 'stable', array('GCM' => self::$gcmApiKey, 'VAPID' => self::$vapidKeys)),
105+
array('firefox', 'beta', array('GCM' => self::$gcmApiKey, 'VAPID' => self::$vapidKeys)),
106+
array('firefox', 'unstable', array('GCM' => self::$gcmApiKey, 'VAPID' => self::$vapidKeys)),
90107
);
91108
}
92109

@@ -99,20 +116,30 @@ public function testBrowsers($browserId, $browserVersion, $options)
99116
$this->webPush = new WebPush($options);
100117
$this->webPush->setAutomaticPadding(false);
101118

102-
$dataString = json_encode(array(
119+
$subscriptionParameters = array(
103120
'testSuiteId' => self::$testSuiteId,
104121
'browserName' => $browserId,
105122
'browserVersion' => $browserVersion,
106-
'gcmSenderId' => self::$gcmSenderId,
107-
));
123+
);
124+
125+
if (array_key_exists('GCM', $options)) {
126+
$subscriptionParameters['gcmSenderId'] = self::$gcmSenderId;
127+
}
128+
129+
if (array_key_exists('VAPID', $options)) {
130+
$subscriptionParameters['vapidPublicKey'] = self::$vapidKeys['publicKey'];
131+
}
132+
133+
$subscriptionParameters = json_encode($subscriptionParameters);
134+
108135
$getSubscriptionCurl = curl_init(self::$testServiceUrl.'/api/get-subscription/');
109136
curl_setopt_array($getSubscriptionCurl, array(
110137
CURLOPT_POST => true,
111-
CURLOPT_POSTFIELDS => $dataString,
138+
CURLOPT_POSTFIELDS => $subscriptionParameters,
112139
CURLOPT_RETURNTRANSFER => true,
113140
CURLOPT_HTTPHEADER => array(
114141
'Content-Type: application/json',
115-
'Content-Length: '.strlen($dataString),
142+
'Content-Length: '.strlen($subscriptionParameters),
116143
),
117144
CURLOPT_TIMEOUT => 30,
118145
));
@@ -184,21 +211,21 @@ protected function tearDown()
184211
$dataString = '{ "testSuiteId": '.self::$testSuiteId.' }';
185212
$curl = curl_init(self::$testServiceUrl.'/api/end-test-suite/');
186213
curl_setopt_array($curl, array(
187-
CURLOPT_POST => true,
188-
CURLOPT_POSTFIELDS => $dataString,
189-
CURLOPT_RETURNTRANSFER => true,
190-
CURLOPT_HTTPHEADER => array(
214+
CURLOPT_POST => true,
215+
CURLOPT_POSTFIELDS => $dataString,
216+
CURLOPT_RETURNTRANSFER => true,
217+
CURLOPT_HTTPHEADER => array(
191218
'Content-Type: application/json',
192219
'Content-Length: '.strlen($dataString),
193-
),
194-
CURLOPT_TIMEOUT => 30,
195-
));
220+
),
221+
CURLOPT_TIMEOUT => 30,
222+
));
196223
$resp = curl_exec($curl);
197224
$parsedResp = json_decode($resp);
198225

199226
self::$testSuiteId = null;
200-
// Close request to clear up some resources
201-
curl_close($curl);
227+
// Close request to clear up some resources
228+
curl_close($curl);
202229
}
203230

204231
public static function tearDownAfterClass()

0 commit comments

Comments
 (0)