mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 16:04:35 +00:00
6c5a88107c
At the moment we support a maximum of 10 tokens per user for subscribing to push notifications, stored as a basic list that runs out when the limit is reached. There may, however, be some edge cases where an app registers a token and then forgets to unregister it (and repeats this 10 times), after which time it will be unable to register any new token. This changes the token list to behave more like a circular buffer, by simply deleting the oldest token before inserting the new one. This way an app could register a new token even in the rare case of forgetting the previous ten. Change-Id: I387de63460882e4e56d1aa6db1f78d73a0495208
45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
use EchoPush\Utils;
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
/**
|
|
* @group Database
|
|
* @covers \EchoPush\SubscriptionManager
|
|
*/
|
|
class SubscriptionManagerTest extends MediaWikiIntegrationTestCase {
|
|
|
|
public function setUp(): void {
|
|
parent::setUp();
|
|
$this->tablesUsed[] = 'echo_push_subscription';
|
|
$this->tablesUsed[] = 'echo_push_provider';
|
|
$this->setMwGlobals( 'wgEchoPushMaxSubscriptionsPerUser', 1 );
|
|
}
|
|
|
|
public function testManagePushSubscriptions(): void {
|
|
$subscriptionManagerBase = EchoServices::getInstance()->getPushSubscriptionManager();
|
|
$subscriptionManager = TestingAccessWrapper::newFromObject( $subscriptionManagerBase );
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
$centralId = Utils::getPushUserId( $user );
|
|
|
|
$subscriptionManager->create( 'test', 'ABC123', $centralId );
|
|
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
|
|
$this->assertCount( 1, $subscriptions );
|
|
|
|
$subscriptionManager->delete( [ 'ABC123' ], $centralId );
|
|
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
|
|
$this->assertCount( 0, $subscriptions );
|
|
|
|
$subscriptionManager->create( 'test', 'ABC123', $centralId );
|
|
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
|
|
$this->assertCount( 1, $subscriptions );
|
|
|
|
$subscriptionManager->create( 'test', 'DEF456', $centralId );
|
|
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
|
|
$this->assertCount( 1, $subscriptions );
|
|
$this->assertEquals( 'DEF456', $subscriptions[0]->getToken() );
|
|
}
|
|
|
|
}
|