2020-05-15 17:19:03 +00:00
|
|
|
<?php
|
|
|
|
|
2022-04-08 00:38:27 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Push\Utils;
|
2020-08-12 21:33:06 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
2020-05-15 17:19:03 +00:00
|
|
|
/**
|
|
|
|
* @group Database
|
2022-04-08 00:38:27 +00:00
|
|
|
* @covers \MediaWiki\Extension\Notifications\Push\SubscriptionManager
|
2020-05-15 17:19:03 +00:00
|
|
|
*/
|
2020-05-22 22:02:34 +00:00
|
|
|
class SubscriptionManagerTest extends MediaWikiIntegrationTestCase {
|
2020-05-15 17:19:03 +00:00
|
|
|
|
2022-09-29 13:41:35 +00:00
|
|
|
protected function setUp(): void {
|
2020-05-15 17:19:03 +00:00
|
|
|
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
|
|
|
|
2020-08-11 20:34:21 +00:00
|
|
|
$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 );
|
|
|
|
|
2021-07-23 13:23:31 +00:00
|
|
|
$subscriptionManager->create( 'test', 'DEF456', $centralId );
|
2020-05-22 22:02:34 +00:00
|
|
|
$subscriptions = $subscriptionManager->getSubscriptionsForUser( $centralId );
|
2021-07-23 13:23:31 +00:00
|
|
|
$this->assertCount( 1, $subscriptions );
|
|
|
|
$this->assertEquals( 'DEF456', $subscriptions[0]->getToken() );
|
2020-05-15 17:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|