mediawiki-extensions-Echo/tests/phpunit/integration/Push/SubscriptionManagerTest.php
James D. Forrester 291ea47dd3 tests: Namespace the PHP classes
This might make dependencies easier to find.

Change-Id: I158fd9f63f18a2b8da0368ac95d5fb5aa9bca3ff
2024-10-03 20:30:06 +00:00

47 lines
1.6 KiB
PHP

<?php
namespace MediaWiki\Extension\Notifications\Test\Integration\Push;
use MediaWiki\Extension\Notifications\Push\Utils;
use MediaWiki\Extension\Notifications\Services;
use MediaWikiIntegrationTestCase;
use Wikimedia\TestingAccessWrapper;
/**
* @group Database
* @covers \MediaWiki\Extension\Notifications\Push\SubscriptionManager
*/
class SubscriptionManagerTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
parent::setUp();
$this->overrideConfigValue( 'EchoPushMaxSubscriptionsPerUser', 1 );
}
public function testManagePushSubscriptions(): void {
$subscriptionManagerBase = Services::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() );
}
}