summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Echo/tests/phpunit/api')
-rw-r--r--Echo/tests/phpunit/api/ApiEchoMarkReadTest.php10
-rw-r--r--Echo/tests/phpunit/api/ApiEchoNotificationsTest.php4
-rw-r--r--Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsCreateTest.php50
-rw-r--r--Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsDeleteTest.php48
-rw-r--r--Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsTest.php22
5 files changed, 123 insertions, 11 deletions
diff --git a/Echo/tests/phpunit/api/ApiEchoMarkReadTest.php b/Echo/tests/phpunit/api/ApiEchoMarkReadTest.php
index 9c41ec37..b5a4b6e1 100644
--- a/Echo/tests/phpunit/api/ApiEchoMarkReadTest.php
+++ b/Echo/tests/phpunit/api/ApiEchoMarkReadTest.php
@@ -4,11 +4,11 @@
* @group medium
* @group API
* @group Database
- * @covers ApiEchoMarkRead
+ * @covers \ApiEchoMarkRead
*/
class ApiEchoMarkReadTest extends ApiTestCase {
- function getTokens() {
+ public function getTokens() {
return $this->getTokenList( self::$users['sysop'] );
}
@@ -29,13 +29,11 @@ class ApiEchoMarkReadTest extends ApiTestCase {
$this->assertArrayHasKey( 'count', $result );
$this->assertArrayHasKey( 'rawcount', $result );
- // Alert
$this->assertArrayHasKey( 'alert', $result );
$alert = $result['alert'];
$this->assertArrayHasKey( 'rawcount', $alert );
$this->assertArrayHasKey( 'count', $alert );
- // Message
$this->assertArrayHasKey( 'message', $result );
$message = $result['message'];
$this->assertArrayHasKey( 'rawcount', $message );
@@ -59,13 +57,11 @@ class ApiEchoMarkReadTest extends ApiTestCase {
$this->assertArrayHasKey( 'count', $result );
$this->assertArrayHasKey( 'rawcount', $result );
- // Alert
$this->assertArrayHasKey( 'alert', $result );
$alert = $result['alert'];
$this->assertArrayHasKey( 'rawcount', $alert );
$this->assertArrayHasKey( 'count', $alert );
- // Message
$this->assertArrayHasKey( 'message', $result );
$message = $result['message'];
$this->assertArrayHasKey( 'rawcount', $message );
@@ -89,13 +85,11 @@ class ApiEchoMarkReadTest extends ApiTestCase {
$this->assertArrayHasKey( 'count', $result );
$this->assertArrayHasKey( 'rawcount', $result );
- // Alert
$this->assertArrayHasKey( 'alert', $result );
$alert = $result['alert'];
$this->assertArrayHasKey( 'rawcount', $alert );
$this->assertArrayHasKey( 'count', $alert );
- // Message
$this->assertArrayHasKey( 'message', $result );
$message = $result['message'];
$this->assertArrayHasKey( 'rawcount', $message );
diff --git a/Echo/tests/phpunit/api/ApiEchoNotificationsTest.php b/Echo/tests/phpunit/api/ApiEchoNotificationsTest.php
index cfcf5c90..d430fa12 100644
--- a/Echo/tests/phpunit/api/ApiEchoNotificationsTest.php
+++ b/Echo/tests/phpunit/api/ApiEchoNotificationsTest.php
@@ -3,7 +3,7 @@
/**
* @group medium
* @group API
- * @covers ApiEchoNotifications
+ * @covers \ApiEchoNotifications
*/
class ApiEchoNotificationsTest extends ApiTestCase {
@@ -26,7 +26,6 @@ class ApiEchoNotificationsTest extends ApiTestCase {
$this->assertArrayHasKey( 'count', $result );
$this->assertArrayHasKey( 'rawcount', $result );
- // Alert
$this->assertArrayHasKey( 'alert', $result );
$alert = $result['alert'];
$this->assertArrayHasKey( 'list', $alert );
@@ -34,7 +33,6 @@ class ApiEchoNotificationsTest extends ApiTestCase {
$this->assertArrayHasKey( 'rawcount', $alert );
$this->assertArrayHasKey( 'count', $alert );
- // Message
$this->assertArrayHasKey( 'message', $result );
$message = $result['message'];
$this->assertArrayHasKey( 'list', $message );
diff --git a/Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsCreateTest.php b/Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsCreateTest.php
new file mode 100644
index 00000000..5361309d
--- /dev/null
+++ b/Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsCreateTest.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * @group medium
+ * @group API
+ * @group Database
+ * @covers \EchoPush\Api\ApiEchoPushSubscriptionsCreate
+ */
+class ApiEchoPushSubscriptionsCreateTest extends ApiTestCase {
+
+ /** @var User */
+ private $user;
+
+ public function setUp(): void {
+ parent::setUp();
+ $this->setMwGlobals( 'wgEchoEnablePush', true );
+ $this->tablesUsed[] = 'echo_push_subscription';
+ $this->tablesUsed[] = 'echo_push_provider';
+ $this->user = $this->getTestUser()->getUser();
+ $this->createTestData();
+ }
+
+ public function testApiCreateSubscription(): void {
+ $params = [
+ 'action' => 'echopushsubscriptions',
+ 'command' => 'create',
+ 'provider' => 'fcm',
+ 'providertoken' => 'ABC123',
+ ];
+ $result = $this->doApiRequestWithToken( $params, null, $this->user );
+ $this->assertEquals( 'Success', $result[0]['create']['result'] );
+ }
+
+ public function testApiCreateSubscriptionTokenExists(): void {
+ $params = [
+ 'action' => 'echopushsubscriptions',
+ 'command' => 'create',
+ 'provider' => 'fcm',
+ 'providertoken' => 'XYZ789',
+ ];
+ $this->expectException( ApiUsageException::class );
+ $this->doApiRequestWithToken( $params, null, $this->user );
+ }
+
+ private function createTestData(): void {
+ $subscriptionManager = EchoServices::getInstance()->getPushSubscriptionManager();
+ $subscriptionManager->create( $this->user, 'fcm', 'XYZ789' );
+ }
+
+}
diff --git a/Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsDeleteTest.php b/Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsDeleteTest.php
new file mode 100644
index 00000000..f2ec0d66
--- /dev/null
+++ b/Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsDeleteTest.php
@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * @group medium
+ * @group API
+ * @group Database
+ * @covers \EchoPush\Api\ApiEchoPushSubscriptionsDelete
+ */
+class ApiEchoPushSubscriptionsDeleteTest extends ApiTestCase {
+
+ /** @var User */
+ private $user;
+
+ public function setUp(): void {
+ parent::setUp();
+ $this->setMwGlobals( 'wgEchoEnablePush', true );
+ $this->tablesUsed[] = 'echo_push_subscription';
+ $this->tablesUsed[] = 'echo_push_provider';
+ $this->user = $this->getTestUser()->getUser();
+ $this->createTestData();
+ }
+
+ public function testApiDeleteSubscription(): void {
+ $params = [
+ 'action' => 'echopushsubscriptions',
+ 'command' => 'delete',
+ 'providertoken' => 'XYZ789',
+ ];
+ $result = $this->doApiRequestWithToken( $params, null, $this->user );
+ $this->assertEquals( 'Success', $result[0]['delete']['result'] );
+ }
+
+ public function testApiDeleteSubscriptionNotFound(): void {
+ $params = [
+ 'action' => 'echopushsubscriptions',
+ 'command' => 'delete',
+ 'providertoken' => 'ABC123',
+ ];
+ $this->expectException( ApiUsageException::class );
+ $this->doApiRequestWithToken( $params, null, $this->user );
+ }
+
+ private function createTestData(): void {
+ $subscriptionManager = EchoServices::getInstance()->getPushSubscriptionManager();
+ $subscriptionManager->create( $this->user, 'fcm', 'XYZ789' );
+ }
+
+}
diff --git a/Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsTest.php b/Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsTest.php
new file mode 100644
index 00000000..857464a8
--- /dev/null
+++ b/Echo/tests/phpunit/api/Push/ApiEchoPushSubscriptionsTest.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * @group medium
+ * @group API
+ * @covers \EchoPush\Api\ApiEchoPushSubscriptions
+ */
+class ApiEchoPushSubscriptionsTest extends ApiTestCase {
+
+ public function testRequiresToken(): void {
+ $this->setMwGlobals( 'wgEchoEnablePush', true );
+ $params = [
+ 'action' => 'echopushsubscriptions',
+ 'command' => 'create',
+ 'platform' => 'apns',
+ 'platformtoken' => 'ABC123',
+ ];
+ $this->expectException( ApiUsageException::class );
+ $this->doApiRequest( $params );
+ }
+
+}