2020-08-03 18:27:47 +00:00
|
|
|
<?php
|
|
|
|
|
2022-04-08 00:38:27 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Push\NotificationServiceClient;
|
|
|
|
use MediaWiki\Extension\Notifications\Push\Subscription;
|
2020-08-03 18:27:47 +00:00
|
|
|
|
2022-04-08 00:38:27 +00:00
|
|
|
/** @covers \MediaWiki\Extension\Notifications\Push\NotificationServiceClient */
|
2020-08-03 18:27:47 +00:00
|
|
|
class NotificationServiceClientUnitTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider sendCheckEchoRequestsProvider
|
|
|
|
*/
|
|
|
|
public function testSendCheckEchoRequests( $numOfCalls, $subscriptions, $expected ): void {
|
|
|
|
$mock = $this->getMockBuilder( NotificationServiceClient::class )
|
|
|
|
->disableOriginalConstructor()
|
2021-05-03 07:28:02 +00:00
|
|
|
->onlyMethods( [ 'sendRequest' ] )
|
2020-08-03 18:27:47 +00:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$mock->expects( $this->exactly( $numOfCalls ) )
|
|
|
|
->method( 'sendRequest' )
|
|
|
|
->withConsecutive( ...$expected );
|
|
|
|
|
|
|
|
$mock->sendCheckEchoRequests( $subscriptions );
|
|
|
|
}
|
|
|
|
|
2023-05-20 18:35:53 +00:00
|
|
|
public static function sendCheckEchoRequestsProvider(): array {
|
2022-09-29 13:41:35 +00:00
|
|
|
$row = (object)[
|
|
|
|
'eps_token' => 'JKL123',
|
|
|
|
'epp_name' => 'fcm',
|
|
|
|
'ept_text' => null,
|
|
|
|
'eps_updated' => '2020-01-01 10:10:10',
|
|
|
|
];
|
2020-08-03 18:27:47 +00:00
|
|
|
$subscriptions[] = Subscription::newFromRow( $row );
|
|
|
|
|
2022-09-29 13:41:35 +00:00
|
|
|
$row = (object)[
|
|
|
|
'eps_token' => 'DEF456',
|
|
|
|
'epp_name' => 'fcm',
|
|
|
|
'ept_text' => null,
|
|
|
|
'eps_updated' => '2020-01-01 10:10:10',
|
|
|
|
];
|
2020-08-03 18:27:47 +00:00
|
|
|
$subscriptions[] = Subscription::newFromRow( $row );
|
|
|
|
|
2022-09-29 13:41:35 +00:00
|
|
|
$row = (object)[
|
|
|
|
'eps_token' => 'GHI789',
|
|
|
|
'epp_name' => 'apns',
|
|
|
|
'ept_text' => 'test',
|
|
|
|
'eps_updated' => '2020-01-01 10:10:10',
|
|
|
|
];
|
2020-08-03 18:27:47 +00:00
|
|
|
$subscriptions[] = Subscription::newFromRow( $row );
|
|
|
|
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
1,
|
|
|
|
[ $subscriptions[0], $subscriptions[1] ],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'fcm',
|
|
|
|
[
|
|
|
|
'deviceTokens' => [ "JKL123", 'DEF456' ],
|
|
|
|
'messageType' => 'checkEchoV1'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
2,
|
|
|
|
$subscriptions,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'fcm',
|
|
|
|
[
|
|
|
|
'deviceTokens' => [ "JKL123", 'DEF456' ],
|
|
|
|
'messageType' => 'checkEchoV1'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'apns',
|
|
|
|
[
|
|
|
|
'deviceTokens' => [ 'GHI789' ],
|
|
|
|
'messageType' => 'checkEchoV1',
|
|
|
|
'topic' => 'test'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|