2021-11-12 20:35:21 +00:00
< ? php
2021-11-12 20:50:02 +00:00
/**
* @ copyright Copyright ( C ) 2010 - 2021 , the Friendica project
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*
*/
2021-11-12 20:35:21 +00:00
namespace Friendica\Test\src\Module\Api\Friendica ;
use Friendica\DI ;
use Friendica\Module\Api\Friendica\Notification ;
use Friendica\Test\src\Module\Api\ApiTest ;
use Friendica\Util\DateTimeFormat ;
use Friendica\Util\Temporal ;
class NotificationTest extends ApiTest
{
public function testEmpty ()
{
self :: markTestIncomplete ( 'Needs BasicAuth as dynamic method for overriding first' );
2021-11-12 21:44:59 +00:00
/*
2021-11-12 20:35:21 +00:00
$this -> expectException ( BadRequestException :: class );
DI :: session () -> set ( 'uid' , '' );
Notification :: rawContent ();
2021-11-12 21:44:59 +00:00
*/
2021-11-12 20:35:21 +00:00
}
public function testWithoutAuthenticatedUser ()
{
self :: markTestIncomplete ( 'Needs BasicAuth as dynamic method for overriding first' );
2021-11-12 21:44:59 +00:00
/*
2021-11-12 20:35:21 +00:00
$this -> expectException ( BadRequestException :: class );
DI :: session () -> set ( 'uid' , 41 );
Notification :: rawContent ();
2021-11-12 21:44:59 +00:00
*/
2021-11-12 20:35:21 +00:00
}
public function testWithXmlResult ()
{
$date = DateTimeFormat :: local ( '2020-01-01 12:12:02' );
$dateRel = Temporal :: getRelativeDate ( '2020-01-01 07:12:02' );
$assertXml = <<< XML
< ? xml version = " 1.0 " ?>
< notes >
< note date = " $date " date_rel = " $dateRel " id = " 1 " iid = " 4 " link = " http://localhost/notification/1 " msg = " A test reply from an item " msg_cache = " A test reply from an item " msg_html = " A test reply from an item " msg_plain = " A test reply from an item " name = " Reply to " name_cache = " Reply to " otype = " item " parent = " " photo = " http://localhost/ " seen = " false " timestamp = " 1577880722 " type = " 8 " uid = " 42 " url = " http://localhost/display/1 " verb = " http://activitystrea.ms/schema/1.0/post " />
</ notes >
XML ;
2021-11-21 20:52:36 +00:00
$notification = new Notification ( DI :: app (), DI :: l10n (), DI :: baseUrl (), DI :: args (), DI :: logger (), DI :: profiler (), DI :: apiResponse (), [], [ 'extension' => 'xml' ]);
$response = $notification -> run ();
2021-11-12 20:35:21 +00:00
2021-11-21 22:37:17 +00:00
self :: assertXmlStringEqualsXmlString ( $assertXml , ( string ) $response -> getBody ());
2021-11-12 20:35:21 +00:00
}
public function testWithJsonResult ()
{
2021-11-21 20:52:36 +00:00
$notification = new Notification ( DI :: app (), DI :: l10n (), DI :: baseUrl (), DI :: args (), DI :: logger (), DI :: profiler (), DI :: apiResponse (), [], [ 'extension' => 'json' ]);
$response = $notification -> run ();
2021-11-12 20:35:21 +00:00
2021-11-21 22:37:17 +00:00
self :: assertJson ( $response -> getBody ());
2021-11-12 20:35:21 +00:00
}
}