mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-04 12:18:30 +00:00
c76761eff3
Bug: T305667 Change-Id: I5a7846a0fc383bddbf6511d6ba73c8be7d7760c7
87 lines
2 KiB
PHP
87 lines
2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\Notifications\Push\NotificationServiceClient;
|
|
use MediaWiki\Extension\Notifications\Push\Subscription;
|
|
|
|
/** @covers \MediaWiki\Extension\Notifications\Push\NotificationServiceClient */
|
|
class NotificationServiceClientUnitTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @dataProvider sendCheckEchoRequestsProvider
|
|
*/
|
|
public function testSendCheckEchoRequests( $numOfCalls, $subscriptions, $expected ): void {
|
|
$mock = $this->getMockBuilder( NotificationServiceClient::class )
|
|
->disableOriginalConstructor()
|
|
->onlyMethods( [ 'sendRequest' ] )
|
|
->getMock();
|
|
|
|
$mock->expects( $this->exactly( $numOfCalls ) )
|
|
->method( 'sendRequest' )
|
|
->withConsecutive( ...$expected );
|
|
|
|
$mock->sendCheckEchoRequests( $subscriptions );
|
|
}
|
|
|
|
public function sendCheckEchoRequestsProvider(): array {
|
|
$row = new stdClass();
|
|
$row->eps_token = 'JKL123';
|
|
$row->epp_name = 'fcm';
|
|
$row->eps_data = null;
|
|
$row->ept_text = null;
|
|
$row->eps_updated = '2020-01-01 10:10:10';
|
|
$subscriptions[] = Subscription::newFromRow( $row );
|
|
|
|
$row->eps_token = 'DEF456';
|
|
$row->epp_name = 'fcm';
|
|
$row->eps_data = null;
|
|
$row->ept_text = null;
|
|
$row->eps_updated = '2020-01-01 10:10:10';
|
|
$subscriptions[] = Subscription::newFromRow( $row );
|
|
|
|
$row->eps_token = 'GHI789';
|
|
$row->epp_name = 'apns';
|
|
$row->eps_data = null;
|
|
$row->ept_text = 'test';
|
|
$row->eps_updated = '2020-01-01 10:10:10';
|
|
$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'
|
|
]
|
|
]
|
|
]
|
|
]
|
|
];
|
|
}
|
|
|
|
}
|