2020-05-15 17:19:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group medium
|
|
|
|
* @group API
|
|
|
|
* @group Database
|
|
|
|
* @covers \EchoPush\Api\ApiEchoPushSubscriptionsCreate
|
|
|
|
*/
|
|
|
|
class ApiEchoPushSubscriptionsCreateTest extends ApiTestCase {
|
|
|
|
|
|
|
|
/** @var User */
|
|
|
|
private $user;
|
|
|
|
|
|
|
|
public function setUp(): void {
|
|
|
|
parent::setUp();
|
2020-08-12 21:33:06 +00:00
|
|
|
$this->setMwGlobals( [
|
|
|
|
'wgEchoEnablePush' => true,
|
|
|
|
'wgEchoPushMaxSubscriptionsPerUser' => 2
|
|
|
|
] );
|
2020-05-15 17:19:03 +00:00
|
|
|
$this->tablesUsed[] = 'echo_push_subscription';
|
|
|
|
$this->tablesUsed[] = 'echo_push_provider';
|
|
|
|
$this->user = $this->getTestUser()->getUser();
|
|
|
|
$this->createTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testApiCreateSubscription(): void {
|
2020-08-12 21:33:06 +00:00
|
|
|
// Before max subscriptions reached
|
2020-05-15 17:19:03 +00:00
|
|
|
$params = [
|
|
|
|
'action' => 'echopushsubscriptions',
|
|
|
|
'command' => 'create',
|
|
|
|
'provider' => 'fcm',
|
|
|
|
'providertoken' => 'ABC123',
|
|
|
|
];
|
|
|
|
$result = $this->doApiRequestWithToken( $params, null, $this->user );
|
|
|
|
$this->assertEquals( 'Success', $result[0]['create']['result'] );
|
2020-08-12 21:33:06 +00:00
|
|
|
|
|
|
|
// After max subscriptions reached
|
|
|
|
$params['providertoken'] = 'DEF456';
|
|
|
|
$this->expectException( ApiUsageException::class );
|
|
|
|
$this->doApiRequestWithToken( $params, null, $this->user );
|
2020-05-15 17:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testApiCreateSubscriptionTokenExists(): void {
|
|
|
|
$params = [
|
|
|
|
'action' => 'echopushsubscriptions',
|
|
|
|
'command' => 'create',
|
|
|
|
'provider' => 'fcm',
|
|
|
|
'providertoken' => 'XYZ789',
|
|
|
|
];
|
|
|
|
$this->expectException( ApiUsageException::class );
|
|
|
|
$this->doApiRequestWithToken( $params, null, $this->user );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createTestData(): void {
|
|
|
|
$subscriptionManager = EchoServices::getInstance()->getPushSubscriptionManager();
|
|
|
|
$subscriptionManager->create( $this->user, 'fcm', 'XYZ789' );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|