2021-11-12 20:35:21 +00:00
< ? php
2021-11-12 20:50:02 +00:00
/**
2024-01-02 20:57:26 +00:00
* @ copyright Copyright ( C ) 2010 - 2024 , the Friendica project
2021-11-12 20:50:02 +00:00
*
* @ 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 ;
2021-11-21 23:07:09 +00:00
use Friendica\Capabilities\ICanCreateResponses ;
2021-11-12 20:35:21 +00:00
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 >
2024-02-25 04:46:54 +00:00
< note date = " $date " date_rel = " $dateRel " id = " 1 " iid = " 4 " link = " https://friendica.local/display/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 = " Friend contact " name_cache = " Friend contact " otype = " item " parent = " " photo = " https://friendica.local/ " seen = " false " timestamp = " 1577880722 " type = " 8 " uid = " 42 " url = " https://friendica.local/profile/friendcontact " verb = " http://activitystrea.ms/schema/1.0/post " />
2021-11-12 20:35:21 +00:00
</ notes >
XML ;
2023-10-11 14:01:32 +00:00
$response = ( new Notification ( DI :: mstdnError (), DI :: app (), DI :: l10n (), DI :: baseUrl (), DI :: args (), DI :: logger (), DI :: profiler (), DI :: apiResponse (), [], [ 'extension' => 'xml' ]))
2022-12-26 20:17:32 +00:00
-> run ( $this -> httpExceptionMock );
2021-11-12 20:35:21 +00:00
2021-11-21 22:37:17 +00:00
self :: assertXmlStringEqualsXmlString ( $assertXml , ( string ) $response -> getBody ());
2022-01-02 00:04:04 +00:00
self :: assertEquals ([
'Content-type' => [ 'text/xml' ],
ICanCreateResponses :: X_HEADER => [ 'xml' ]
], $response -> getHeaders ());
2021-11-12 20:35:21 +00:00
}
public function testWithJsonResult ()
{
2023-10-11 14:01:32 +00:00
$response = ( new Notification ( DI :: mstdnError (), DI :: app (), DI :: l10n (), DI :: baseUrl (), DI :: args (), DI :: logger (), DI :: profiler (), DI :: apiResponse (), [], [ 'extension' => 'json' ]))
2022-12-26 20:17:32 +00:00
-> run ( $this -> httpExceptionMock );
2021-11-12 20:35:21 +00:00
2021-12-10 16:32:41 +00:00
$json = $this -> toJson ( $response );
self :: assertIsArray ( $json );
foreach ( $json as $note ) {
self :: assertIsInt ( $note -> id );
self :: assertIsInt ( $note -> uid );
self :: assertIsString ( $note -> msg );
}
2021-12-09 19:53:29 +00:00
2022-01-02 00:04:04 +00:00
self :: assertEquals ([
'Content-type' => [ 'application/json' ],
ICanCreateResponses :: X_HEADER => [ 'json' ]
], $response -> getHeaders ());
2021-11-12 20:35:21 +00:00
}
}