2020-05-15 17:19:03 +00:00
|
|
|
<?php
|
|
|
|
|
2020-08-11 20:34:21 +00:00
|
|
|
use EchoPush\Utils;
|
2020-08-12 21:33:06 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
2020-05-15 17:19:03 +00:00
|
|
|
/**
|
|
|
|
* @group Database
|
|
|
|
* @covers \EchoPush\SubscriptionManager
|
|
|
|
*/
|
2020-05-22 22:02:34 +00:00
|
|
|
class SubscriptionManagerTest extends MediaWikiIntegrationTestCase {
|
2020-05-15 17:19:03 +00:00
|
|
|
|
|
|
|
public function setUp(): void {
|
|
|
|
parent::setUp();
|
|
|
|
$this->tablesUsed[] = 'echo_push_subscription';
|
|
|
|
$this->tablesUsed[] = 'echo_push_provider';
|
2020-08-12 21:33:06 +00:00
|
|
|
$this->setMwGlobals( 'wgEchoPushMaxSubscriptionsPerUser', 1 );
|
2020-05-15 17:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testManagePushSubscriptions(): void {
|
2020-08-12 21:33:06 +00:00
|
|
|
$subscriptionManagerBase = EchoServices::getInstance()->getPushSubscriptionManager();
|
|
|
|
$subscriptionManager = TestingAccessWrapper::newFromObject( $subscriptionManagerBase );
|
|
|
|
|
2020-05-15 17:19:03 +00:00
|
|
|
$user = $this->getTestUser()->getUser();
|
2020-08-11 20:34:21 +00:00
|
|
|
$centralId = Utils::getPushUserId( $user );
|
2020-08-12 21:33:06 +00:00
|
|
|
|
2020-08-11 20:34:21 +00:00
|
|
|
$subscriptionManager->create( 'test', 'ABC123', $centralId );
|
2020-05-22 22:02:34 +00:00
|
|
|
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
|
2020-05-15 17:19:03 +00:00
|
|
|
$this->assertCount( 1, $subscriptions );
|
2020-08-12 21:33:06 +00:00
|
|
|
$this->assertTrue( $subscriptionManager->userHasMaxAllowedSubscriptions( $centralId ) );
|
|
|
|
|
2020-08-11 20:34:21 +00:00
|
|
|
$subscriptionManager->delete( [ 'ABC123' ], $centralId );
|
|
|
|
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
|
|
|
|
$this->assertCount( 0, $subscriptions );
|
|
|
|
$this->assertFalse( $subscriptionManager->userHasMaxAllowedSubscriptions( $centralId ) );
|
|
|
|
|
|
|
|
$subscriptionManager->create( 'test', 'ABC123', $centralId );
|
|
|
|
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
|
|
|
|
$this->assertCount( 1, $subscriptions );
|
|
|
|
$this->assertTrue( $subscriptionManager->userHasMaxAllowedSubscriptions( $centralId ) );
|
|
|
|
|
|
|
|
$subscriptionManager->delete( [ 'ABC123' ] );
|
2020-05-22 22:02:34 +00:00
|
|
|
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
|
2020-05-15 17:19:03 +00:00
|
|
|
$this->assertCount( 0, $subscriptions );
|
2020-08-12 21:33:06 +00:00
|
|
|
$this->assertFalse( $subscriptionManager->userHasMaxAllowedSubscriptions( $centralId ) );
|
2020-05-15 17:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|