From 5ccf41a56fd41de9024ca1443714b991001f447c Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 22:00:21 +0100 Subject: [PATCH] Add API test case for notification --- src/Repository/Notify.php | 2 -- tests/datasets/api.fixture.php | 19 +++++++++++++++++++ tests/include/ApiTest.php | 27 ++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/Repository/Notify.php b/src/Repository/Notify.php index ba00d26fa7..8c71fc289a 100644 --- a/src/Repository/Notify.php +++ b/src/Repository/Notify.php @@ -37,8 +37,6 @@ class Notify extends BaseRepository { $params['order'] = $params['order'] ?? ['date' => 'DESC']; - $condition = array_merge($condition, ['uid' => local_user()]); - return parent::select($condition, $params); } diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 475fa03854..44501d0493 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -189,6 +189,25 @@ return [ 'origin' => 1, ], ], + 'notify' => [ + [ + 'id' => 1, + 'type' => 8, + 'name' => 'Reply to', + 'url' => 'http://localhost/display/1', + 'photo' => 'http://localhost/', + 'date' => '2020-01-01 12:12:02', + 'msg' => 'A test reply from an item', + 'uid' => 42, + 'link' => 'http://localhost/notification/1', + 'iid' => 4, + 'seen' => 0, + 'verb' => '', + 'otype' => 'item', + 'name_cache' => 'Reply to', + 'msg_cache' => 'A test reply from an item', + ], + ], 'thread' => [ [ 'iid' => 1, diff --git a/tests/include/ApiTest.php b/tests/include/ApiTest.php index 466248f652..3ef64b3171 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -14,6 +14,7 @@ use Friendica\Core\Session; use Friendica\Core\Session\ISession; use Friendica\Core\System; use Friendica\Database\Database; +use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Network\HTTPException; @@ -3916,14 +3917,15 @@ class ApiTest extends DatabaseTest } /** - * Test the api_friendica_notification() function with an argument count. + * Test the api_friendica_notification() function with empty result * * @return void */ - public function testApiFriendicaNotificationWithArgumentCount() + public function testApiFriendicaNotificationWithEmptyResult() { $this->app->argv = ['api', 'friendica', 'notification']; $this->app->argc = count($this->app->argv); + $_SESSION['uid'] = 41; $result = api_friendica_notification('json'); $this->assertEquals(['note' => false], $result); } @@ -3938,7 +3940,26 @@ class ApiTest extends DatabaseTest $this->app->argv = ['api', 'friendica', 'notification']; $this->app->argc = count($this->app->argv); $result = api_friendica_notification('xml'); - $this->assertXml($result, 'notes'); + $assertXml=<< + + + +XML; + $this->assertXmlStringEqualsXmlString($assertXml, $result); + } + + /** + * Test the api_friendica_notification() function with an JSON result. + * + * @return void + */ + public function testApiFriendicaNotificationWithJsonResult() + { + $this->app->argv = ['api', 'friendica', 'notification']; + $this->app->argc = count($this->app->argv); + $result = json_encode(api_friendica_notification('json')); + $this->assertJson($result); } /**