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' )
|
2023-11-21 22:55:06 +00:00
|
|
|
->willReturnCallback( function ( $provider, $payload ) use ( &$expected ): void {
|
|
|
|
$expectedIdx = array_search( [ $provider, $payload ], $expected, true );
|
|
|
|
$this->assertNotFalse( $expectedIdx, "Unexpected arguments (provider: $provider)" );
|
|
|
|
unset( $expected[$expectedIdx] );
|
|
|
|
} );
|
2020-08-03 18:27:47 +00:00
|
|
|
|
|
|
|
$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 [
|
2024-03-10 18:22:36 +00:00
|
|
|
[
|
|
|
|
1,
|
|
|
|
[ $subscriptions[0], $subscriptions[1] ],
|
2020-08-03 18:27:47 +00:00
|
|
|
[
|
|
|
|
[
|
2024-03-10 18:22:36 +00:00
|
|
|
'fcm',
|
2020-08-03 18:27:47 +00:00
|
|
|
[
|
2024-03-10 18:22:36 +00:00
|
|
|
'deviceTokens' => [ "JKL123", 'DEF456' ],
|
|
|
|
'messageType' => 'checkEchoV1'
|
2020-08-03 18:27:47 +00:00
|
|
|
]
|
|
|
|
]
|
2024-03-10 18:22:36 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
2,
|
|
|
|
$subscriptions,
|
2020-08-03 18:27:47 +00:00
|
|
|
[
|
|
|
|
[
|
2024-03-10 18:22:36 +00:00
|
|
|
'fcm',
|
2020-08-03 18:27:47 +00:00
|
|
|
[
|
2024-03-10 18:22:36 +00:00
|
|
|
'deviceTokens' => [ "JKL123", 'DEF456' ],
|
|
|
|
'messageType' => 'checkEchoV1'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'apns',
|
2020-08-03 18:27:47 +00:00
|
|
|
[
|
2024-03-10 18:22:36 +00:00
|
|
|
'deviceTokens' => [ 'GHI789' ],
|
|
|
|
'messageType' => 'checkEchoV1',
|
|
|
|
'topic' => 'test'
|
2020-08-03 18:27:47 +00:00
|
|
|
]
|
2024-03-10 18:22:36 +00:00
|
|
|
]
|
2020-08-03 18:27:47 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|