mediawiki-extensions-Echo/tests/phpunit/integration/Push/SubscriptionManagerTest.php
Michael Holloway 15d48278be Create and enforce a config setting for max subscriptions per user
Creates a EchoPushMaxSubscriptionsPerUser config setting (default: 0)
that controls the maximum number of subscriptions a user may associate
with the user's central user ID.

The setting is enforced in EchoPush\SubscriptionManager::create().

To allow creating push subscriptions for development, set
$wgEchoPushMaxSubscriptionsPerUser to a positive integer value in
LocalSettings.php:

 $wgEchoPushMaxSubscriptionsPerUser = 10;

Bug: T259150
Change-Id: Ib97b6b6cbb8161dd75dad92c54b4fe4fff80c421
2020-08-12 17:58:11 -04:00

37 lines
1.3 KiB
PHP

<?php
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 = CentralIdLookup::factory()->centralIdFromLocalUser( $user );
$subscriptionManager->create( $user, 'test', 'ABC123' );
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
$this->assertCount( 1, $subscriptions );
$this->assertTrue( $subscriptionManager->userHasMaxAllowedSubscriptions( $centralId ) );
$subscriptionManager->delete( $user, 'ABC123' );
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
$this->assertCount( 0, $subscriptions );
$this->assertFalse( $subscriptionManager->userHasMaxAllowedSubscriptions( $centralId ) );
}
}